Spaces:
Sleeping
Sleeping
File size: 1,266 Bytes
bd2d0eb 5c7d95e d1d8593 8dfd3bf da0cd92 3b4268a 8dfd3bf 3b4268a 3eb2902 3b4268a 250e906 3b4268a 209c7f2 3b4268a cdd4a8e 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 33 |
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_NEW')}",
"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",
"stream":True,
"messages": [{
"role": "user",
"content": f"condition every topics or heading only must startswith # and endswith : \n\n{question}"
}],
"temperature": 0.3,
"max_tokens": 599
}
)
response.raise_for_status()
return response.json()['choices'][0]['message']['content']
except Exception as e:
return f"Error generating answer: {str(e)}"
|