Spaces:
Paused
Paused
Update backend_models.py
Browse files- backend_models.py +18 -10
backend_models.py
CHANGED
|
@@ -3,10 +3,8 @@ from openai import OpenAI
|
|
| 3 |
|
| 4 |
def get_inference_client(model_id: str, provider: str = "auto"):
|
| 5 |
"""
|
| 6 |
-
Ép
|
| 7 |
-
phải gọi vào endpoint miễn phí của Hugging Face.
|
| 8 |
"""
|
| 9 |
-
# Nếu nó đòi Novita, ta cứ phớt lờ và đưa nó sang endpoint miễn phí
|
| 10 |
return OpenAI(
|
| 11 |
base_url="https://api-inference.huggingface.co/v1/",
|
| 12 |
api_key=os.getenv("HF_TOKEN")
|
|
@@ -14,17 +12,27 @@ def get_inference_client(model_id: str, provider: str = "auto"):
|
|
| 14 |
|
| 15 |
def get_real_model_id(model_id: str) -> str:
|
| 16 |
"""
|
| 17 |
-
|
| 18 |
-
Nó biến 'moonshotai/Kimi-K2.6:novita' thành 'moonshotai/Kimi-K2.6'
|
| 19 |
-
'google/gemma-4-31B:fastest' thành 'google/gemma-4-31B'
|
| 20 |
"""
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
def is_native_sdk_model(model_id: str) -> bool:
|
| 26 |
return False
|
| 27 |
|
| 28 |
def is_mistral_model(model_id: str) -> bool:
|
| 29 |
return "mistral" in model_id.lower()
|
| 30 |
-
|
|
|
|
| 3 |
|
| 4 |
def get_inference_client(model_id: str, provider: str = "auto"):
|
| 5 |
"""
|
| 6 |
+
Ép buộc sử dụng endpoint Serverless miễn phí của Hugging Face.
|
|
|
|
| 7 |
"""
|
|
|
|
| 8 |
return OpenAI(
|
| 9 |
base_url="https://api-inference.huggingface.co/v1/",
|
| 10 |
api_key=os.getenv("HF_TOKEN")
|
|
|
|
| 12 |
|
| 13 |
def get_real_model_id(model_id: str) -> str:
|
| 14 |
"""
|
| 15 |
+
Ánh xạ các model trả phí trong menu sang model miễn phí tương đương.
|
|
|
|
|
|
|
| 16 |
"""
|
| 17 |
+
mapping = {
|
| 18 |
+
"Kimi-K2.6": "meta-llama/Llama-3.1-8B-Instruct",
|
| 19 |
+
"Gemma-4-31B-it": "google/gemma-2-9b-it",
|
| 20 |
+
"Qwen3.5-397B-A17B": "Qwen/Qwen2.5-7B-Instruct",
|
| 21 |
+
"DeepSeek-V3": "Qwen/Qwen2.5-Coder-7B-Instruct"
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
# Lấy tên model chính (bỏ qua hậu tố :novita, :cerebras)
|
| 25 |
+
clean_id = model_id.split(":")[0]
|
| 26 |
+
|
| 27 |
+
# Nếu có trong mapping, chuyển sang model miễn phí
|
| 28 |
+
for key, free_model in mapping.items():
|
| 29 |
+
if key in clean_id:
|
| 30 |
+
return free_model
|
| 31 |
+
|
| 32 |
+
return "meta-llama/Llama-3.1-8B-Instruct" # Mặc định an toàn
|
| 33 |
|
| 34 |
def is_native_sdk_model(model_id: str) -> bool:
|
| 35 |
return False
|
| 36 |
|
| 37 |
def is_mistral_model(model_id: str) -> bool:
|
| 38 |
return "mistral" in model_id.lower()
|
|
|