Spaces:
Sleeping
Sleeping
File size: 904 Bytes
3c816b5 d019361 e15f17f d019361 3c816b5 d019361 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# inference.py
import requests
import os
API_KEY = os.getenv("DEEPSEEK_KEY", "").strip()
def deepseek_query(prompt):
url = "https://api.deepseek.com/v1/chat/completions"
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
}
data = {
"model": "deepseek-chat",
"messages": [
{"role": "system", "content": "You are a helpful, creative AI agent."},
{"role": "user", "content": prompt}
]
}
try:
response = requests.post(url, json=data, headers=headers)
result = response.json()
# ✅ Debug: Print whole response if there's an issue
if "choices" not in result:
return f"[ERROR] choices not found in response: {result}"
return result["choices"][0]["message"]["content"]
except Exception as e:
return f"[ERROR] {str(e)}"
|