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.

39 lines
1.4 KiB

5 months ago
import os
from openai import OpenAI
# https://help.aliyun.com/zh/model-studio/developer-reference/deepseek?spm=a2c4g.11186623.0.0.274b1d1c4GY0Zd
from pathlib import Path
API_KEY = "sk-01d13a39e09844038322108ecdbd1bbc"
client = OpenAI(
# 若没有配置环境变量请用百炼API Key将下行替换为api_key="sk-xxx",
api_key=API_KEY, # 如何获取API Keyhttps://help.aliyun.com/zh/model-studio/developer-reference/get-api-key
base_url="https://dashscope.aliyuncs.com/compatible-mode/v1"
)
# 读取文本文件内容
file_path = Path(r"D:\dsWork\QingLong\音频文本.txt")
if file_path.exists():
# 自动处理文件编码默认utf-8读取内容
content = file_path.read_text(encoding='utf-8')
else:
print(f"文件 {file_path} 不存在")
exit(0)
# Send request.
completion = client.chat.completions.create(
model="deepseek-v3", # 此处以 deepseek-r1 为例,可按需更换模型名称。
messages=[
{'role': 'user', 'content': "帮我梳理:这节课分了几个部分,每部分的名称和开始的时间是多少:"+content}
]
)
# 通过reasoning_content字段打印思考过程
#print("思考过程:")
#print(completion.choices[0].message.reasoning_content)
# 通过content字段打印最终答案
print("最终答案:")
print(completion.choices[0].message.content)