Spaces:
Sleeping
Sleeping
| 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)}" | |