Spaces:
Paused
Paused
Feat: Set Google Gemini GenerativeLanguage API endpoint as default
Browse files- tinytroupe/openai_utils.py +16 -2
tinytroupe/openai_utils.py
CHANGED
|
@@ -55,7 +55,7 @@ class OpenAIClient:
|
|
| 55 |
Sets up the OpenAI API configurations for this client.
|
| 56 |
"""
|
| 57 |
if self.client is None:
|
| 58 |
-
self.client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
|
| 59 |
|
| 60 |
@config_manager.config_defaults(
|
| 61 |
model="model",
|
|
@@ -171,7 +171,7 @@ class OpenAIClient:
|
|
| 171 |
#
|
| 172 |
# Model fallback strategy using config
|
| 173 |
if i <= 3:
|
| 174 |
-
current_model = config["OpenAI"].get("MODEL", "
|
| 175 |
current_wait_time = 35
|
| 176 |
elif i <= 5:
|
| 177 |
current_model = config["OpenAI"].get("FALLBACK_MODEL_LARGE", "alias-large")
|
|
@@ -236,6 +236,20 @@ class OpenAIClient:
|
|
| 236 |
"""
|
| 237 |
|
| 238 |
# adjust parameters depending on the model
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 239 |
if self._is_reasoning_model(model):
|
| 240 |
# Reasoning models have slightly different parameters
|
| 241 |
del chat_api_params["stream"]
|
|
|
|
| 55 |
Sets up the OpenAI API configurations for this client.
|
| 56 |
"""
|
| 57 |
if self.client is None:
|
| 58 |
+
self.client = OpenAI(api_key=os.getenv("GOOGLE_API_KEY", os.getenv("OPENAI_API_KEY", "dummy_token")), base_url="https://generativelanguage.googleapis.com/v1beta/openai/")
|
| 59 |
|
| 60 |
@config_manager.config_defaults(
|
| 61 |
model="model",
|
|
|
|
| 171 |
#
|
| 172 |
# Model fallback strategy using config
|
| 173 |
if i <= 3:
|
| 174 |
+
current_model = config["OpenAI"].get("MODEL", "gemini-3-flash-preview")
|
| 175 |
current_wait_time = 35
|
| 176 |
elif i <= 5:
|
| 177 |
current_model = config["OpenAI"].get("FALLBACK_MODEL_LARGE", "alias-large")
|
|
|
|
| 236 |
"""
|
| 237 |
|
| 238 |
# adjust parameters depending on the model
|
| 239 |
+
|
| 240 |
+
# --- GOOGLE GEMINI PARAMETER SANITIZATION ---
|
| 241 |
+
if "reasoning_effort" in chat_api_params:
|
| 242 |
+
del chat_api_params["reasoning_effort"]
|
| 243 |
+
if "frequency_penalty" in chat_api_params:
|
| 244 |
+
del chat_api_params["frequency_penalty"]
|
| 245 |
+
if "presence_penalty" in chat_api_params:
|
| 246 |
+
del chat_api_params["presence_penalty"]
|
| 247 |
+
if "stop" in chat_api_params and not chat_api_params["stop"]:
|
| 248 |
+
del chat_api_params["stop"]
|
| 249 |
+
if "max_completion_tokens" in chat_api_params:
|
| 250 |
+
chat_api_params["max_tokens"] = chat_api_params.pop("max_completion_tokens")
|
| 251 |
+
# ---------------------------------------------
|
| 252 |
+
|
| 253 |
if self._is_reasoning_model(model):
|
| 254 |
# Reasoning models have slightly different parameters
|
| 255 |
del chat_api_params["stream"]
|