Spaces:
Paused
Paused
File size: 1,079 Bytes
0498411 7e68781 e2ffe2b 91f238e e2ffe2b 7e68781 0498411 e2ffe2b e531912 e2ffe2b e531912 e2ffe2b bf604d1 7e68781 bf604d1 7e68781 bf604d1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | import os
from google import genai
from huggingface_hub import InferenceClient # Vẫn giữ import này để tránh lỗi module
# Khởi tạo client Gemini mới
client = genai.Client(api_key=os.getenv("GEMINI_API_KEY"))
# 1. Định nghĩa hàm mà backend_api.py đang tìm kiếm
def get_inference_client(model_id: str = None, provider: str = "auto"):
"""
Adapter: Trả về một đối tượng có phương thức .chat() hoặc .generate()
để tương thích với luồng xử lý cũ của backend_api.py
"""
return client # Trả về client Gemini đã được cấu hình
# 2. Định nghĩa các hàm helper để tránh lỗi "ImportError"
def get_real_model_id(model_id: str) -> str:
mapping = {
"Gemini 3.5 Flash": "gemini-3.5-flash",
"Gemini 3.1 Pro Preview": "gemini-3.1-pro-preview",
"Gemini 2.0 Flash": "gemini-2.0-flash"
}
return mapping.get(model_id, "gemini-3.5-flash")
def is_native_sdk_model(model_id: str) -> bool: return True
def is_mistral_model(model_id: str) -> bool: return False
|