AbuAlone09 commited on
Commit
5a5470f
·
verified ·
1 Parent(s): 0b02baa

Update backend_models.py

Browse files
Files changed (1) hide show
  1. backend_models.py +15 -20
backend_models.py CHANGED
@@ -3,26 +3,21 @@ from openai import OpenAI
3
 
4
  def get_inference_client(model_id: str, provider: str = "auto"):
5
  """
6
- Tự động phân biệt giữa model miễn phí model trả phí.
 
7
  """
8
- # Danh sách model miễn phí của Hugging Face
9
- free_models = [
10
- "meta-llama/Llama-3.1-8B-Instruct",
11
- "google/gemma-2-9b-it",
12
- "Qwen/Qwen2.5-7B-Instruct",
13
- "mistralai/Mistral-7B-Instruct-v0.3"
14
- ]
15
-
16
- if model_id in free_models:
17
- # Dùng endpoint miễn phí
18
- return OpenAI(
19
- base_url="https://api-inference.huggingface.co/v1/",
20
- api_key=os.getenv("HF_TOKEN")
21
- )
22
- else:
23
- # Nếu dùng model trả phí mà đã hết quota, ta trả về client rỗng hoặc báo lỗi
24
- # để hệ thống không bị crash đột ngột
25
- raise Exception(f"Model {model_id} yêu cầu trả phí (Out of credits). Hãy chọn các model Llama hoặc Gemma trong menu.")
26
 
27
  def get_real_model_id(model_id: str) -> str:
28
- return model_id
 
 
 
 
 
 
 
 
3
 
4
  def get_inference_client(model_id: str, provider: str = "auto"):
5
  """
6
+ Ép hệ thống sử dụng endpoint miễn phí của Hugging Face
7
+ cho tất cả các model trong danh sách.
8
  """
9
+ # Xóa bỏ hoàn toàn header X-HF-Bill-To để tránh lỗi 402
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
+ # Trả về ID sạch, không có hậu tố :novita hay :cerebras
17
+ return model_id.split(":")[0]
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()