import requests
import json
# DeepSeek 模型的 API 端点
API_URL = "https://api.deepseek.com/v1/chat/completions"
# 你的 API 密钥
API_KEY = ""
# 定义提示词
prompt = [
{"role": "system", "content": "你是一个翻译助手,帮助用户翻译。"},
{"role": "user", "content": '''Spreadsheets are used to calculate project cost estimates. Totals for each cost category are then keyed into the job-costing system. What is
the BEST control to ensure that data is accurately entered into the system?
A. Display back of project detail after entry
B. Reconciliation of total amounts by project
C. Reasonableness checks for each cost type
D. Validity checks, preventing entry of character data '''}
]
# 请求体
payload = {
"model": "deepseek-chat", # 模型名称
"messages": prompt, # 提示词
"max_tokens": 1000, # 最大生成 token 数
"temperature": 0.7 # 控制生成文本的随机性
}
# 请求头
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {API_KEY}"
}
# 发送请求
response = requests.post(API_URL, headers=headers, data=json.dumps(payload))
# 解析响应
if response.status_code == 200:
result = response.json()
assistant_reply = result["choices"][0]["message"]["content"]
print("助手回复:", assistant_reply)
else:
print("请求失败,状态码:", response.status_code)
print("错误信息:", response.text)