Files
ocr/test14_1.py
2025-08-14 16:04:59 +08:00

135 lines
5.3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from openai import OpenAI
if __name__ == '__main__':
# 读取 QvqResult.txt 内容
file_name="QvqResult.txt"
# file_name = "GlmResult.txt"
with open(file_name, 'r', encoding='utf-8') as file:
QvqResult = file.read() # 直接获取整个文件内容为字符串
# 初始化OpenAI客户端
client = OpenAI(
api_key="sk-f6da0c787eff4b0389e4ad03a35a911f",
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1"
)
reasoning_content = "" # 定义完整思考过程
answer_content = "" # 定义完整回复
is_answering = False # 判断是否结束思考过程并开始回复
prompt = """
# Role: GeoGebra 几何图形生成器
## Profile
- language: 中文
- description: 专门用于根据初中几何题的题干和几何图形的描述来生成Geogebra指令集的角色确保生成的指令集严格遵循几何约束和动态坐标系构建规则并具备错误熔断机制。
- background: 拥有深厚的几何学和计算机科学背景熟悉Geogebra软件的操作和指令集编写。
- personality: 严谨、细致、高效
- expertise: 几何学、计算机编程、Geogebra软件应用
**几何图形生成规则(通用强制约束版)**
请严格按以下优先级执行,不受题目具体内容影响:
1. **几何约束最高优先级**
- 描述中提到的水平线段,一定要保持水平,不可以进行变更
- 当文字描述与坐标/位置冲突时,以文字描述的几何关系为准
- 必须自动验证:{长度|角度|中点|平行|垂直}关系
- 验证失败时:重新计算坐标并报告修正
- 有动点的,要设置滑块。没有动点的,不要设置滑块。
- 检查描述中提到的最长的边做为X轴最长边的左端点做为原点
2. **动态坐标系构建**
```mermaid
graph TB
A[定位原点] --> B{原点坐标明确?}
B -->|是| C[直接采用]
B -->|否| D[根据相对关系推算]
E[建立坐标系] --> F{存在水平/垂直要求?}
F -->|是| G[调整坐标满足]
F -->|否| H[保持默认方向]
```
3、错误熔断机制
检测到矛盾 → 触发修正流程:
if not satisfy_constraint(description):
new_coords = recalculate_by_geometry()
log_adjustment(old_coords, new_coords, reason)
4、元素生成协议
顺序:固定点 → 固定线 → 动态点(初始位) → 动态元素
依赖检查:确保父元素先于子元素生成
5、输出结构强制
[修正报告] (若有调整)
[坐标摘要] (最终使用坐标)
[Geogebra指令] (完整可执行代码)
注意:
【1】GGB指令集中不要添加注释不要添加除指令集外的其它描述性文字需要可以直接批量执行的
【2】仔细检查原图中是线段还是直线要严格进行识别
【3】仔细检查原图中的每一条边是否都正确进行了线段标识
【4】不显示网格使用ShowGrid(false)不显示坐标轴使用ShowAxes(false)),但如果是坐标系就需要显示坐标轴。
【5】如果在使用Segment创建两个点的线段时需要指定一个标签名然后使用ShowLabel隐藏这个标签名注意使用的是ShowLabel而不是SetVisibleInView而且只是Segment创建两个点的线段时才隐藏标签名
【6】注意不要使用Perpendicular需要使用PerpendicularLine来替代
【7】注意不要使用SetLabel因为会提示“未知的指令”。
【8】注意不要使用Angle无需标注角度。
【9】如果有滑块使用Slider
【10】如果没有动点就无需添加滑块。
【11】注意不要使用TangentPoint因为会提示“未知的指令”。
6、题目的文字描述信息
```
{QvqResult}
```
"""
prompt = prompt.replace("{QvqResult}", QvqResult)
# 创建聊天完成请求
completion = client.chat.completions.create(
model="deepseek-r1-0528",
messages=[
{
"role": "user",
"content": [
{"type": "text",
"text": prompt},
],
},
],
stream=True,
)
print("\n" + "=" * 20 + "思考过程" + "=" * 20 + "\n")
for chunk in completion:
# 如果chunk.choices为空则打印usage
if not chunk.choices:
print("\nUsage:")
print(chunk.usage)
else:
delta = chunk.choices[0].delta
# 打印思考过程
if hasattr(delta, 'reasoning_content') and delta.reasoning_content != None:
print(delta.reasoning_content, end='', flush=True)
reasoning_content += delta.reasoning_content
else:
# 开始回复
if delta.content != "" and is_answering is False:
print("\n" + "=" * 20 + "完整回复" + "=" * 20 + "\n")
is_answering = True
# 打印回复过程
print(delta.content, end='', flush=True)
answer_content += delta.content
# print("=" * 20 + "完整思考过程" + "=" * 20 + "\n")
# print(reasoning_content)
# print("=" * 20 + "完整回复" + "=" * 20 + "\n")
print(answer_content)
# 保存成GGB.txt
with open("GGB.txt", "w", encoding='utf-8') as f:
f.write(answer_content)
print("GGB指令集保存成功")