Spaces:
Paused
Paused
Update backend_models.py
Browse files- backend_models.py +22 -9
backend_models.py
CHANGED
|
@@ -1,15 +1,28 @@
|
|
| 1 |
import os
|
| 2 |
-
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
#
|
| 8 |
-
|
| 9 |
-
model = genai.GenerativeModel('gemini-1.5-flash')
|
| 10 |
|
| 11 |
def get_inference_client(model_id: str, provider: str = "auto"):
|
| 12 |
-
return
|
| 13 |
|
| 14 |
def get_real_model_id(model_id: str) -> str:
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
+
from openai import OpenAI
|
| 3 |
|
| 4 |
+
# Kết nối tới OpenRouter
|
| 5 |
+
client = OpenAI(
|
| 6 |
+
base_url="https://openrouter.ai/api/v1",
|
| 7 |
+
api_key=os.getenv("OPENROUTER_API_KEY") # Hãy chắc chắn bạn đã đổi key này trong Secrets
|
| 8 |
+
)
|
|
|
|
| 9 |
|
| 10 |
def get_inference_client(model_id: str, provider: str = "auto"):
|
| 11 |
+
return client
|
| 12 |
|
| 13 |
def get_real_model_id(model_id: str) -> str:
|
| 14 |
+
# Ánh xạ tên giao diện -> tên chuẩn của OpenRouter
|
| 15 |
+
mapping = {
|
| 16 |
+
"DeepSeek V4 Flash": "deepseek/deepseek-chat", # Hoặc model tương đương
|
| 17 |
+
"Qwen3 Coder 480B A35B": "qwen/qwen-2.5-coder-32b-instruct",
|
| 18 |
+
"GLM 5.1": "glm-4-flash",
|
| 19 |
+
"GLM 4.5 Air": "glm-4-air",
|
| 20 |
+
"MiniMax M2.5": "minimax/minimax-01",
|
| 21 |
+
"Gemma 4 26B A4B": "google/gemma-2-27b-it",
|
| 22 |
+
"Gemma 4 31B": "google/gemma-2-27b-it"
|
| 23 |
+
}
|
| 24 |
+
# Mặc định dùng Qwen nếu không tìm thấy
|
| 25 |
+
return mapping.get(model_id, "qwen/qwen-2.5-coder-32b-instruct")
|
| 26 |
+
|
| 27 |
+
def is_native_sdk_model(model_id: str) -> bool: return True
|
| 28 |
+
def is_mistral_model(model_id: str) -> bool: return False
|