You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.8 KiB

1 week ago
from openai import OpenAI
import os
# 初始化OpenAI客户端
client = OpenAI(
# 如果没有配置环境变量请用百炼API Key替换api_key="sk-xxx"
1 week ago
api_key="sk-01d13a39e09844038322108ecdbd1bbc",
1 week ago
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1"
)
reasoning_content = "" # 定义完整思考过程
1 week ago
answer_content = "" # 定义完整回复
is_answering = False # 判断是否结束思考过程并开始回复
1 week ago
1 week ago
prompt = "1、现在需要解答第1张图片的第4问。第2张图片的内容是此题的答案。\n"
prompt=prompt+"2、限定在初中数学知识范围内解决问题即不用使用建系向量等高级数学方法只限使用三角形相似勾股定理全等三角形平面几何知识等。\n"
1 week ago
prompt = prompt + "3、根据我提供的答案梳理题目的解题步骤分析一下我们做这道题时题目中的关键点是什么此时该如何思考步骤才能快速正确回答问题。"
1 week ago
# 创建聊天完成请求
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"
},
},
1 week ago
{
"type": "image_url",
"image_url": {
"url": "https://dsideal.obs.cn-north-1.myhuaweicloud.com/HuangHai/Backup/answer.jpg"
},
},
1 week ago
{"type": "text",
"text": prompt},
1 week ago
],
},
],
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")
1 week ago
# print(answer_content)