AbuAlone09 commited on
Commit
e2ffe2b
·
verified ·
1 Parent(s): e6449b7

Update backend_models.py

Browse files
Files changed (1) hide show
  1. backend_models.py +10 -9
backend_models.py CHANGED
@@ -1,13 +1,20 @@
1
  import os
2
  from google import genai
 
3
 
4
- # Khởi tạo client mới (thay thế cho việc cấu hình global cũ)
5
  client = genai.Client(api_key=os.getenv("GEMINI_API_KEY"))
6
 
7
- def get_gemini_model_id(model_id: str) -> str:
 
8
  """
9
- Chuyển đổi tên hiển thị sang ID model chuẩn cho thư viện google-genai
 
10
  """
 
 
 
 
11
  mapping = {
12
  "Gemini 3.5 Flash": "gemini-3.5-flash",
13
  "Gemini 3.1 Pro Preview": "gemini-3.1-pro-preview",
@@ -15,11 +22,5 @@ def get_gemini_model_id(model_id: str) -> str:
15
  }
16
  return mapping.get(model_id, "gemini-3.5-flash")
17
 
18
- # Hàm này trả về client để bạn sử dụng trong backend_api.py
19
- def get_genai_client():
20
- return client
21
-
22
-
23
- # Các hàm cũ không còn cần thiết cho Gemini
24
  def is_native_sdk_model(model_id: str) -> bool: return True
25
  def is_mistral_model(model_id: str) -> bool: return False
 
1
  import os
2
  from google import genai
3
+ from huggingface_hub import InferenceClient # Vẫn giữ import này để tránh lỗi module
4
 
5
+ # Khởi tạo client Gemini mới
6
  client = genai.Client(api_key=os.getenv("GEMINI_API_KEY"))
7
 
8
+ # 1. Định nghĩa hàm mà backend_api.py đang tìm kiếm
9
+ def get_inference_client(model_id: str = None, provider: str = "auto"):
10
  """
11
+ Adapter: Trả về một đối tượng phương thức .chat() hoặc .generate()
12
+ để tương thích với luồng xử lý cũ của backend_api.py
13
  """
14
+ return client # Trả về client Gemini đã được cấu hình
15
+
16
+ # 2. Định nghĩa các hàm helper để tránh lỗi "ImportError"
17
+ def get_real_model_id(model_id: str) -> str:
18
  mapping = {
19
  "Gemini 3.5 Flash": "gemini-3.5-flash",
20
  "Gemini 3.1 Pro Preview": "gemini-3.1-pro-preview",
 
22
  }
23
  return mapping.get(model_id, "gemini-3.5-flash")
24
 
 
 
 
 
 
 
25
  def is_native_sdk_model(model_id: str) -> bool: return True
26
  def is_mistral_model(model_id: str) -> bool: return False