AbuAlone09 commited on
Commit
b931a44
·
verified ·
1 Parent(s): f40ffb1

Update backend_models.py

Browse files
Files changed (1) hide show
  1. 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 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")
@@ -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
- 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
-
 
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()