Spaces:
Runtime error
Runtime error
| import pyodide_http | |
| pyodide_http.patch_all() | |
| import requests | |
| import json | |
| def get_answer(text, api_key): | |
| # Прямая связь с OpenRouter | |
| url = "https://openrouter.ai/api/v1/chat/completions" | |
| headers = { | |
| "Authorization": f"Bearer {api_key}", | |
| "Content-Type": "application/json" | |
| } | |
| # Полностью убрали характер. Только твой вопрос. | |
| payload = { | |
| "model": "google/gemma-2-9b-it:free", | |
| "messages": [ | |
| {"role": "user", "content": text} | |
| ], | |
| "parameters": { | |
| "max_new_tokens": 150, | |
| "temperature": 0.7 | |
| } | |
| } | |
| try: | |
| response = requests.post(url, headers=headers, data=json.dumps(payload), timeout=15) | |
| data = response.json() | |
| if 'choices' in data: | |
| return data['choices']['message']['content'].strip() | |
| else: | |
| return "Ошибка! Проверь лимиты или ключ." | |
| except: | |
| return "Нет связи с сервером." | |
| # Ждем данные из твоего index.html с Гитхаба | |
| result = get_answer(user_input, openrouter_key) | |