Files
dsProject/dsLightRag/GeoGeBra/T1_Qvq.py
2025-08-14 15:45:08 +08:00

71 lines
2.6 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_BASE_URL, ALY_LLM_API_KEY
# 初始化OpenAI客户端
client = OpenAI(
api_key=ALY_LLM_API_KEY,
base_url=ALY_LLM_BASE_URL
)
reasoning_content = "" # 定义完整思考过程
answer_content = "" # 定义完整回复
is_answering = False # 判断是否结束思考过程并开始回复
prompt = """
你是一个严谨的数学助手,请将以下初中几何题进行描述,需包含:
【1】有哪些主体元素比如 直角等腰三角形,等腰三角形,直角三角形,都有哪些,先列举大的,再列举小的。
【2】这些主体元素的位置关系是什么样的比如AB是斜边角C是90度角AB是水平的适合做坐标系的X轴。
【3】除主体元素外其它的辅助元素有哪些都应该如何描述清楚
"""
# 创建聊天完成请求
completion = client.chat.completions.create(
model="qvq-max", # 此处以 qvq-max 为例,可按需更换模型名称
messages=[
{
"role": "user",
"content": [
{
"type": "image_url",
"image_url": {
"url": "https://dsideal.obs.cn-north-1.myhuaweicloud.com/wb/math.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")
# 保存成QvqResult.txt
with open("QvqResult.txt", "w", encoding='utf-8') as f:
f.write(answer_content)
print("试题解析文本保存成功!")