Spaces:
Sleeping
Sleeping
File size: 766 Bytes
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 |
# inference.py
import requests
import os
# Get the API key from Hugging Face Secrets
API_KEY = os.getenv("DEEPSEEK_KEY")
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()
return result["choices"][0]["message"]["content"]
except Exception as e:
return f"[ERROR] {str(e)}"
|