Spaces:
Paused
Paused
| 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 | |