|
def query_deepseek(prompt): |
|
payload = { |
|
"inputs": f"<|system|>You are a helpful assistant.<|user|>{prompt}<|assistant|>", |
|
"parameters": {"max_new_tokens": 200} |
|
} |
|
response = requests.post( |
|
f"https://api-inference.huggingface.co/models/{DEEPSEEK_MODEL}", |
|
headers=headers, |
|
json=payload |
|
) |
|
|
|
try: |
|
result = response.json() |
|
|
|
if isinstance(result, dict) and "error" in result: |
|
return f"⚠️ DeepSeek API error: {result['error']}" |
|
return result[0]["generated_text"].split("<|assistant|>")[-1].strip() |
|
except Exception as e: |
|
return f"⚠️ Failed to parse DeepSeek response: {e}" |
|
|