Merge main updates into huggingface-space-deployment
Browse files- app/ai/router.py +27 -17
- app/config.py +4 -3
- app/services/container.py +4 -3
app/ai/router.py
CHANGED
|
@@ -17,20 +17,22 @@ class LiteLLMOrchestration:
|
|
| 17 |
self,
|
| 18 |
groq_api_key: str,
|
| 19 |
groq_model: str,
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
| 25 |
max_tool_iterations: int = 3,
|
| 26 |
temperature: float = 0.2,
|
| 27 |
) -> None:
|
| 28 |
self.name = "litellm-orchestration"
|
| 29 |
self.groq_api_key = groq_api_key
|
| 30 |
self.groq_model = groq_model
|
| 31 |
-
self.
|
| 32 |
-
self.
|
| 33 |
-
self.
|
|
|
|
| 34 |
self.openrouter_api_key = openrouter_api_key
|
| 35 |
self.openrouter_model = openrouter_model
|
| 36 |
self.max_tool_iterations = max_tool_iterations
|
|
@@ -43,7 +45,15 @@ class LiteLLMOrchestration:
|
|
| 43 |
|
| 44 |
litellm strips the provider prefix before sending to the API,
|
| 45 |
so 'groq/openai/gpt-oss-120b' sends 'openai/gpt-oss-120b' to Groq.
|
|
|
|
|
|
|
|
|
|
| 46 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
if model.startswith(f"{provider}/"):
|
| 48 |
return model
|
| 49 |
return f"{provider}/{model}"
|
|
@@ -61,19 +71,19 @@ class LiteLLMOrchestration:
|
|
| 61 |
},
|
| 62 |
},
|
| 63 |
{
|
| 64 |
-
"model_name": "
|
| 65 |
"litellm_params": {
|
| 66 |
-
"model": self._litellm_model(self.
|
| 67 |
-
"api_key": self.
|
| 68 |
-
"api_base": "https://
|
| 69 |
},
|
| 70 |
},
|
| 71 |
{
|
| 72 |
-
"model_name": "
|
| 73 |
"litellm_params": {
|
| 74 |
-
"model": self._litellm_model(self.
|
| 75 |
-
"api_key": self.
|
| 76 |
-
"api_base": "https://
|
| 77 |
},
|
| 78 |
},
|
| 79 |
{
|
|
@@ -85,7 +95,7 @@ class LiteLLMOrchestration:
|
|
| 85 |
},
|
| 86 |
},
|
| 87 |
],
|
| 88 |
-
fallbacks=[{"groq": ["
|
| 89 |
num_retries=0,
|
| 90 |
retry_policy={
|
| 91 |
"TimeoutErrorRetries": 0,
|
|
|
|
| 17 |
self,
|
| 18 |
groq_api_key: str,
|
| 19 |
groq_model: str,
|
| 20 |
+
openrouter_api_key: str | None = None,
|
| 21 |
+
openrouter_model: str | None = None,
|
| 22 |
+
groq_api_key_2: str | None = None,
|
| 23 |
+
groq_model_2: str | None = None,
|
| 24 |
+
google_ai_api_key: str | None = None,
|
| 25 |
+
google_ai_model: str | None = None,
|
| 26 |
max_tool_iterations: int = 3,
|
| 27 |
temperature: float = 0.2,
|
| 28 |
) -> None:
|
| 29 |
self.name = "litellm-orchestration"
|
| 30 |
self.groq_api_key = groq_api_key
|
| 31 |
self.groq_model = groq_model
|
| 32 |
+
self.groq_api_key_2 = groq_api_key_2
|
| 33 |
+
self.groq_model_2 = groq_model_2
|
| 34 |
+
self.google_ai_api_key = google_ai_api_key
|
| 35 |
+
self.google_ai_model = google_ai_model
|
| 36 |
self.openrouter_api_key = openrouter_api_key
|
| 37 |
self.openrouter_model = openrouter_model
|
| 38 |
self.max_tool_iterations = max_tool_iterations
|
|
|
|
| 45 |
|
| 46 |
litellm strips the provider prefix before sending to the API,
|
| 47 |
so 'groq/openai/gpt-oss-120b' sends 'openai/gpt-oss-120b' to Groq.
|
| 48 |
+
|
| 49 |
+
Also strips non-litellm prefixes (e.g. 'google/' from OpenRouter
|
| 50 |
+
model IDs) before applying the correct litellm provider prefix.
|
| 51 |
"""
|
| 52 |
+
for prefix in ("google",):
|
| 53 |
+
if model.startswith(f"{prefix}/"):
|
| 54 |
+
model = model[len(prefix) + 1 :]
|
| 55 |
+
break
|
| 56 |
+
|
| 57 |
if model.startswith(f"{provider}/"):
|
| 58 |
return model
|
| 59 |
return f"{provider}/{model}"
|
|
|
|
| 71 |
},
|
| 72 |
},
|
| 73 |
{
|
| 74 |
+
"model_name": "groq_2",
|
| 75 |
"litellm_params": {
|
| 76 |
+
"model": self._litellm_model(self.groq_model_2 or self.groq_model, "groq"),
|
| 77 |
+
"api_key": self.groq_api_key_2 or self.groq_api_key,
|
| 78 |
+
"api_base": "https://api.groq.com/openai/v1",
|
| 79 |
},
|
| 80 |
},
|
| 81 |
{
|
| 82 |
+
"model_name": "google_ai_studio",
|
| 83 |
"litellm_params": {
|
| 84 |
+
"model": self._litellm_model(self.google_ai_model or self.openrouter_model, "gemini"),
|
| 85 |
+
"api_key": self.google_ai_api_key or self.openrouter_api_key,
|
| 86 |
+
"api_base": "https://generativelanguage.googleapis.com/v1beta",
|
| 87 |
},
|
| 88 |
},
|
| 89 |
{
|
|
|
|
| 95 |
},
|
| 96 |
},
|
| 97 |
],
|
| 98 |
+
fallbacks=[{"groq": ["groq_2", "google_ai_studio", "openrouter"]},],
|
| 99 |
num_retries=0,
|
| 100 |
retry_policy={
|
| 101 |
"TimeoutErrorRetries": 0,
|
app/config.py
CHANGED
|
@@ -32,9 +32,10 @@ class Settings(BaseSettings):
|
|
| 32 |
|
| 33 |
groq_api_key: str = Field(min_length=1)
|
| 34 |
groq_model: str = Field(min_length=1)
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
|
|
|
| 38 |
openrouter_api_key: str = Field(min_length=1)
|
| 39 |
openrouter_model: str = Field(min_length=1)
|
| 40 |
ai_temperature: float = 0.2
|
|
|
|
| 32 |
|
| 33 |
groq_api_key: str = Field(min_length=1)
|
| 34 |
groq_model: str = Field(min_length=1)
|
| 35 |
+
groq_api_key_2: str | None = None
|
| 36 |
+
groq_model_2: str | None = None
|
| 37 |
+
google_ai_api_key: str | None = None
|
| 38 |
+
google_ai_model: str | None = None
|
| 39 |
openrouter_api_key: str = Field(min_length=1)
|
| 40 |
openrouter_model: str = Field(min_length=1)
|
| 41 |
ai_temperature: float = 0.2
|
app/services/container.py
CHANGED
|
@@ -31,9 +31,10 @@ class ServiceContainer:
|
|
| 31 |
ai = LiteLLMOrchestration(
|
| 32 |
groq_api_key=settings.groq_api_key,
|
| 33 |
groq_model=settings.groq_model,
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
| 37 |
openrouter_api_key=settings.openrouter_api_key,
|
| 38 |
openrouter_model=settings.openrouter_model,
|
| 39 |
max_tool_iterations=settings.ai_max_tool_iterations,
|
|
|
|
| 31 |
ai = LiteLLMOrchestration(
|
| 32 |
groq_api_key=settings.groq_api_key,
|
| 33 |
groq_model=settings.groq_model,
|
| 34 |
+
groq_api_key_2=settings.groq_api_key_2,
|
| 35 |
+
groq_model_2=settings.groq_model_2,
|
| 36 |
+
google_ai_api_key=settings.google_ai_api_key,
|
| 37 |
+
google_ai_model=settings.google_ai_model,
|
| 38 |
openrouter_api_key=settings.openrouter_api_key,
|
| 39 |
openrouter_model=settings.openrouter_model,
|
| 40 |
max_tool_iterations=settings.ai_max_tool_iterations,
|