Spaces:
Sleeping
Sleeping
Download text2generation.py from sreepathi-ravikumar/sample: direct link, hf CLI and curl.
- Browser
- Download file 1.27 kB
-
https://huggingface.co/spaces/sreepathi-ravikumar/sample/resolve/main/text2generation.py
- Command line
-
hf download hf://spaces/sreepathi-ravikumar/sample/text2generation.py
-
curl -L -o text2generation.py https://huggingface.co/spaces/sreepathi-ravikumar/sample/resolve/main/text2generation.py
1.27 kB
| 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)}" | |