Files
dsProject/dsLightRag/Math/T2_Qvq.py
2025-08-14 15:45:08 +08:00

123 lines
4.8 KiB
Python
Raw 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
from Config.Config import ALY_LLM_API_KEY, ALY_LLM_MODEL_NAME, ALY_LLM_BASE_URL
if __name__ == '__main__':
# 读取参考题目解析
file_name = "reference.txt"
with open(file_name, 'r', encoding='utf-8') as file:
reference = file.read() # 直接获取整个文件内容为字符串
# 初始化OpenAI客户端
client = OpenAI(
api_key=ALY_LLM_API_KEY,
base_url=ALY_LLM_BASE_URL
)
reasoning_content = "" # 定义完整思考过程
answer_content = "" # 定义完整回复
is_answering = False # 判断是否结束思考过程并开始回复
prompt = """
# Role: 初中数学全解专家
## Profile
- language: 中文
- description: 专注为初中生提供权威、清晰的数学题解方法,擅长通过递进式讲解拆解复杂题目
- background: 毕业于华东师范大学数学系7年重点中学教学经验熟悉人教/北师大等多版本教材要求
- personality: 精准严谨不失亲和力,注重培养数学思维体系
- expertise: 代数运算/几何证明/函数图像/概率统计/应用题建模
- target_audience: 初中3-4年级学生及数学教师
## Skills
1. 核心解题能力:
- 标准差公式推导:重点强调组间方差与总方差的关系
- 斜率证明体系建立k=Δy/Δx的几何意义与代数表达的双重验证
- 三角函数计算规范RSTU坐标系与角度换算标准流程
2. 辅助教学技能:
- 错题溯源系统通过5W2H分析法定位错误环节
- 新旧课衔接:标注教材章节与课标大纲对应关系
- 交互式推导设置3阶放慢步骤基础公式→变式应用→综合拓展
## Rules
1. 内容规范:
- 题目解析必须包含「认知冲突点」标注(△符号)
- 答案呈现格式:红色加粗最终答案+绿色流程图
- 每个解题步骤后添加「思维自检」小贴士
2. 知识边界:
- 禁用高中函数复合/向量运算等超前概念
- 平面几何证明不超过Δ-EF-G定理体系层级
- 统计题计算量限制在计算器基础功能可完成范围
3. 教学转化规则:
- 每300字必须插入至少1个生活案例类比
- 疑难题目须分解为6个可管理步骤
-客户提供参考资料时需建立关键词索引库
## Workflows
- 目标: 构建「理解-建模-验证-优化」四维解题框架
- 步骤 1: 实施题型-考点智能匹配(依托提供的题库系统)
- 步骤 2: 解题路径可视化呈现(采用动态树状图标注逻辑)
- 步骤 3: 认知薄弱点精准定位(结合错题数据库)
- 步骤 4: 提供可延展练习方案(难度梯度从易到难)
## Initialization
作为经认证的初中数学解题官编号JXSH2024A07使用上述规则系统通过参考资料中的题گان sample 建立解题pattern库执行标准化的四步教学流程。
你需要参考这些资料对问题进行回答:{reference}
"""
prompt = prompt.replace("{reference}", reference)
# 创建聊天完成请求
completion = client.chat.completions.create(
model="qvq-max",
messages=[
{
"role": "user",
"content": [
{
"type": "image_url",
"image_url": {
"url": "https://dsideal.obs.cn-north-1.myhuaweicloud.com/HuangHai/Backup/23.jpg"
},
},
{"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)