mcp2-backend / inference.py
aymnsk's picture
Create inference.py
d019361 verified
raw
history blame
766 Bytes
# 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)}"