Spaces:
Paused
Paused
Update backend_models.py
Browse files- backend_models.py +12 -5
backend_models.py
CHANGED
|
@@ -3,21 +3,28 @@ from openai import OpenAI
|
|
| 3 |
|
| 4 |
def get_inference_client(model_id: str, provider: str = "auto"):
|
| 5 |
"""
|
| 6 |
-
Ép
|
| 7 |
-
|
| 8 |
"""
|
| 9 |
-
#
|
| 10 |
return OpenAI(
|
| 11 |
base_url="https://api-inference.huggingface.co/v1/",
|
| 12 |
api_key=os.getenv("HF_TOKEN")
|
| 13 |
)
|
| 14 |
|
| 15 |
def get_real_model_id(model_id: str) -> str:
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
def is_native_sdk_model(model_id: str) -> bool:
|
| 20 |
return False
|
| 21 |
|
| 22 |
def is_mistral_model(model_id: str) -> bool:
|
| 23 |
return "mistral" in model_id.lower()
|
|
|
|
|
|
| 3 |
|
| 4 |
def get_inference_client(model_id: str, provider: str = "auto"):
|
| 5 |
"""
|
| 6 |
+
Ép tất cả các model trong danh sách (Kimi, Gemma, Qwen...)
|
| 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")
|
| 13 |
)
|
| 14 |
|
| 15 |
def get_real_model_id(model_id: str) -> str:
|
| 16 |
+
"""
|
| 17 |
+
Hàm này cực kỳ quan trọng:
|
| 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 |
+
# Xóa hậu tố provider để API của Hugging Face nhận diện được model
|
| 22 |
+
base_id = model_id.split(":")[0]
|
| 23 |
+
return base_id
|
| 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 |
+
|