|
|
|
@ -0,0 +1,46 @@
|
|
|
|
|
import os
|
|
|
|
|
from openai import OpenAI
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
client = OpenAI(
|
|
|
|
|
# 若没有配置环境变量,请用百炼API Key将下行替换为:api_key="sk-xxx",
|
|
|
|
|
api_key='sk-f6da0c787eff4b0389e4ad03a35a911f',
|
|
|
|
|
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
|
|
|
|
|
)
|
|
|
|
|
# 读取md文件内容
|
|
|
|
|
with open("2、识别出结果.md", "r", encoding="utf-8") as f:
|
|
|
|
|
text = f.read()
|
|
|
|
|
|
|
|
|
|
prompt = """
|
|
|
|
|
我将提供一份markdown格式的试卷,请帮我整理出每道题的以下内容:
|
|
|
|
|
1. 题目序号
|
|
|
|
|
2. 题目内容(自动识别并添加$或$$包裹数学公式)
|
|
|
|
|
3. 选项(如果有)
|
|
|
|
|
4. 答案
|
|
|
|
|
5. 解析
|
|
|
|
|
|
|
|
|
|
要求:
|
|
|
|
|
- 一道题一道题输出,不要使用表格
|
|
|
|
|
- 自动检测数学表达式并用$或$$正确包裹
|
|
|
|
|
- 确保公式中的特殊字符正确转义
|
|
|
|
|
- 除题目内容外,不要输出其它无关信息
|
|
|
|
|
|
|
|
|
|
内容如下:
|
|
|
|
|
"""
|
|
|
|
|
prompt += text
|
|
|
|
|
completion = client.chat.completions.create(
|
|
|
|
|
model="deepseek-v3",
|
|
|
|
|
messages=[
|
|
|
|
|
{"role": "system", "content": "You are a helpful assistant."},
|
|
|
|
|
{"role": "user",
|
|
|
|
|
"content": prompt},
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
print(completion.choices[0].message.content)
|
|
|
|
|
# 将上面的返回内容写入到文件 3、整理后的结果.md 中
|
|
|
|
|
with open("3、整理后的结果.md", "w", encoding="utf-8") as f:
|
|
|
|
|
f.write(completion.choices[0].message.content)
|
|
|
|
|
print("保存成功!")
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print(f"错误信息:{e}")
|
|
|
|
|
print("请参考文档:https://help.aliyun.com/zh/model-studio/developer-reference/error-code")
|