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