File size: 1,280 Bytes
dd3c4b9
 
c864562
dd3c4b9
 
 
 
c864562
 
dd3c4b9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from langdetect import detect

def choose_model(user_input: str) -> str:
    """
    Автоматически подбирает оптимальную модель Hugging Face
    в зависимости от языка, задачи и сложности запроса.
    """
    text = user_input.lower()

    # Определяем язык
    try:
        lang = detect(user_input)
    except:
        lang = "en"

    # === Категории задач ===
    if any(x in text for x in ["код", "python", "script", "программа", "function", "code"]):
        return "codellama/CodeLlama-7b-Instruct-hf"

    elif any(x in text for x in ["анализ", "объясни", "научи", "почему", "как работает"]):
        return "mistralai/Mistral-7B-Instruct-v0.3"

    elif any(x in text for x in ["текст", "переведи", "история", "расскажи", "объяснение"]):
        return "google/gemma-2b-it"

    elif any(x in text for x in ["чат", "ответь", "расскажи про", "что такое"]):
        return "microsoft/Phi-3-mini-4k-instruct"

    # === fallback ===
    if lang != "ru":
        return "mistralai/Mistral-7B-Instruct-v0.3"
    return "microsoft/Phi-3-mini-4k-instruct"