Spaces:
Paused
Paused
Mirrowel commited on
Commit ·
dcaf0eb
1
Parent(s): c3b2e49
feat: Add request payload sanitization to remove unsupported parameters based on model
Browse files
src/rotator_library/client.py
CHANGED
|
@@ -18,6 +18,7 @@ from .usage_manager import UsageManager
|
|
| 18 |
from .failure_logger import log_failure
|
| 19 |
from .error_handler import classify_error, AllProviders
|
| 20 |
from .providers import PROVIDER_PLUGINS
|
|
|
|
| 21 |
|
| 22 |
class RotatingClient:
|
| 23 |
"""
|
|
@@ -156,6 +157,8 @@ class RotatingClient:
|
|
| 156 |
litellm_kwargs["model"] = f"openai/{model.split('/', 1)[1]}"
|
| 157 |
litellm_kwargs["api_base"] = "https://llm.chutes.ai/v1"
|
| 158 |
|
|
|
|
|
|
|
| 159 |
for attempt in range(self.max_retries):
|
| 160 |
try:
|
| 161 |
lib_logger.info(f"Attempting call with key ...{current_key[-4:]} (Attempt {attempt + 1}/{self.max_retries})")
|
|
|
|
| 18 |
from .failure_logger import log_failure
|
| 19 |
from .error_handler import classify_error, AllProviders
|
| 20 |
from .providers import PROVIDER_PLUGINS
|
| 21 |
+
from .request_sanitizer import sanitize_request_payload
|
| 22 |
|
| 23 |
class RotatingClient:
|
| 24 |
"""
|
|
|
|
| 157 |
litellm_kwargs["model"] = f"openai/{model.split('/', 1)[1]}"
|
| 158 |
litellm_kwargs["api_base"] = "https://llm.chutes.ai/v1"
|
| 159 |
|
| 160 |
+
litellm_kwargs = sanitize_request_payload(litellm_kwargs, model)
|
| 161 |
+
|
| 162 |
for attempt in range(self.max_retries):
|
| 163 |
try:
|
| 164 |
lib_logger.info(f"Attempting call with key ...{current_key[-4:]} (Attempt {attempt + 1}/{self.max_retries})")
|
src/rotator_library/request_sanitizer.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Dict, Any
|
| 2 |
+
|
| 3 |
+
def sanitize_request_payload(payload: Dict[str, Any], model: str) -> Dict[str, Any]:
|
| 4 |
+
"""
|
| 5 |
+
Removes unsupported parameters from the request payload based on the model.
|
| 6 |
+
"""
|
| 7 |
+
if payload.get("thinking") == {"type": "enabled", "budget_tokens": -1}:
|
| 8 |
+
if model not in ["gemini/gemini-2.5-pro", "gemini/gemini-2.5-flash"]:
|
| 9 |
+
del payload["thinking"]
|
| 10 |
+
|
| 11 |
+
return payload
|