Spaces:
Sleeping
Sleeping
File size: 1,282 Bytes
bd2d0eb 5c7d95e d1d8593 8dfd3bf 3b4268a 8dfd3bf 3b4268a 1af330b 3b4268a 8dfd3bf 3b4268a 8dfd3bf df516c3 | 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 | import os
import httpx
def generate_long_answer(question):
"""Generate detailed answers using OpenRouter's DeepSeek API"""
try:
with httpx.Client(timeout=10.0) as client:
response = client.post(
url="https://openrouter.ai/api/v1/chat/completions",
headers={
"Authorization": f"Bearer {os.getenv('OPENROUTER_API_KEY')}",
"Content-Type": "application/json",
"HTTP-Referer": "https://sreepathi-ravikumar-sample.hf.space",
"X-Title": "Educational AI Assistant"
},
json={
"model": "deepseek/deepseek-chat-v3-0324:free",
"messages": [{
"role": "user",
"content": f"Provide a comprehensive educational answer with examples in very simple english words that can easily understand by anyone:\n\n{question}"
}],
"temperature": 0.3,
"max_tokens": 2000
}
)
response.raise_for_status()
return response.json()['choices'][0]['message']['content']
except Exception as e:
return f"Error generating answer: {str(e)}"
|