File size: 1,187 Bytes
2d73dda
 
 
 
 
 
 
18fa2ce
2d73dda
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
34
35
36
37
38
39
40
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)