Spaces:
Sleeping
Sleeping
Create core/model_selector.py
Browse files- core/model_selector.py +29 -11
core/model_selector.py
CHANGED
|
@@ -1,14 +1,32 @@
|
|
|
|
|
|
|
|
| 1 |
def choose_model(user_input: str) -> str:
|
| 2 |
-
"""
|
|
|
|
|
|
|
|
|
|
| 3 |
text = user_input.lower()
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from langdetect import detect
|
| 2 |
+
|
| 3 |
def choose_model(user_input: str) -> str:
|
| 4 |
+
"""
|
| 5 |
+
Автоматически подбирает оптимальную модель Hugging Face
|
| 6 |
+
в зависимости от языка, задачи и сложности запроса.
|
| 7 |
+
"""
|
| 8 |
text = user_input.lower()
|
| 9 |
|
| 10 |
+
# Определяем язык
|
| 11 |
+
try:
|
| 12 |
+
lang = detect(user_input)
|
| 13 |
+
except:
|
| 14 |
+
lang = "en"
|
| 15 |
+
|
| 16 |
+
# === Категории задач ===
|
| 17 |
+
if any(x in text for x in ["код", "python", "script", "программа", "function", "code"]):
|
| 18 |
+
return "codellama/CodeLlama-7b-Instruct-hf"
|
| 19 |
+
|
| 20 |
+
elif any(x in text for x in ["анализ", "объясни", "научи", "почему", "как работает"]):
|
| 21 |
+
return "mistralai/Mistral-7B-Instruct-v0.3"
|
| 22 |
+
|
| 23 |
+
elif any(x in text for x in ["текст", "переведи", "история", "расскажи", "объяснение"]):
|
| 24 |
+
return "google/gemma-2b-it"
|
| 25 |
+
|
| 26 |
+
elif any(x in text for x in ["чат", "ответь", "расскажи про", "что такое"]):
|
| 27 |
+
return "microsoft/Phi-3-mini-4k-instruct"
|
| 28 |
+
|
| 29 |
+
# === fallback ===
|
| 30 |
+
if lang != "ru":
|
| 31 |
+
return "mistralai/Mistral-7B-Instruct-v0.3"
|
| 32 |
+
return "microsoft/Phi-3-mini-4k-instruct"
|