基础调用流程(通用模板)
import requests
import json
def call_deepseek_api(api_key, prompt):
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {api_key}"
}
payload = {
"model": "deepseek-chat", # 根据具体模型调整
"messages": [
{"role": "user", "content": prompt}
],
"temperature": 0.7
}
try:
response = requests.post(
"https://api.deepseek.com/v1/chat/completions", # 示例端点
headers=headers,
json=payload
)
response.raise_for_status() # 自动处理HTTP错误
result = response.json()
return result['choices'][0]['message']['content']
except requests.exceptions.RequestException as e:
print(f"API请求失败: {str(