Spaces:
Sleeping
Sleeping
replace LiteLLMModel with LiteLLMRouterModel to add fallback feature
Browse files
app.py
CHANGED
|
@@ -8,7 +8,7 @@ import pandas as pd
|
|
| 8 |
from smolagents import (
|
| 9 |
Tool,
|
| 10 |
CodeAgent,
|
| 11 |
-
|
| 12 |
PythonInterpreterTool,
|
| 13 |
VisitWebpageTool,
|
| 14 |
GoogleSearchTool,
|
|
@@ -36,7 +36,7 @@ CUSTOM_PROMPT = """
|
|
| 36 |
and separete them with a comma and a whitespace like "a, b, c" not "a,b,c".
|
| 37 |
|
| 38 |
Attached files can be downloaded via the Internet.
|
| 39 |
-
When downloading files, try to download them in python code before visiting the website.
|
| 40 |
"""
|
| 41 |
|
| 42 |
rate_limiter = RateLimiter()
|
|
@@ -45,9 +45,43 @@ rate_limiter = RateLimiter()
|
|
| 45 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 46 |
class BasicAgent:
|
| 47 |
def __init__(self):
|
| 48 |
-
model =
|
| 49 |
-
model_id=
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
)
|
| 52 |
self.agent = CodeAgent(
|
| 53 |
tools=[
|
|
|
|
| 8 |
from smolagents import (
|
| 9 |
Tool,
|
| 10 |
CodeAgent,
|
| 11 |
+
LiteLLMRouterModel,
|
| 12 |
PythonInterpreterTool,
|
| 13 |
VisitWebpageTool,
|
| 14 |
GoogleSearchTool,
|
|
|
|
| 36 |
and separete them with a comma and a whitespace like "a, b, c" not "a,b,c".
|
| 37 |
|
| 38 |
Attached files can be downloaded via the Internet.
|
| 39 |
+
When downloading files, try to download them in your python code before visiting the website.
|
| 40 |
"""
|
| 41 |
|
| 42 |
rate_limiter = RateLimiter()
|
|
|
|
| 45 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 46 |
class BasicAgent:
|
| 47 |
def __init__(self):
|
| 48 |
+
model = LiteLLMRouterModel(
|
| 49 |
+
model_id="gemini-flash-family",
|
| 50 |
+
model_list=[
|
| 51 |
+
{
|
| 52 |
+
"model_name": "gemini-flash-family",
|
| 53 |
+
"litellm_params": {
|
| 54 |
+
"model": "gemini/gemini-2.5-flash",
|
| 55 |
+
"api_key": os.getenv("GEMINI_API_KEY"),
|
| 56 |
+
"rpm": 10,
|
| 57 |
+
"tpm": 250_000,
|
| 58 |
+
},
|
| 59 |
+
"fallbacks": ["gemini/gemini-2.0-flash"],
|
| 60 |
+
},
|
| 61 |
+
{
|
| 62 |
+
"model_name": "gemini-flash-family",
|
| 63 |
+
"litellm_params": {
|
| 64 |
+
"model": "gemini/gemini-2.0-flash",
|
| 65 |
+
"api_key": os.getenv("GEMINI_API_KEY"),
|
| 66 |
+
"rpm": 15,
|
| 67 |
+
"tpm": 1_000_000,
|
| 68 |
+
},
|
| 69 |
+
"fallbacks": ["gemini/gemini-2.0-flash-lite"]
|
| 70 |
+
},
|
| 71 |
+
{
|
| 72 |
+
"model_name": "gemini-flash-family",
|
| 73 |
+
"litellm_params": {
|
| 74 |
+
"model": "gemini/gemini-2.0-flash-lite",
|
| 75 |
+
"api_key": os.getenv("GEMINI_API_KEY"),
|
| 76 |
+
"rpm": 30,
|
| 77 |
+
"tpm": 1_000_000,
|
| 78 |
+
},
|
| 79 |
+
},
|
| 80 |
+
],
|
| 81 |
+
client_kwargs={
|
| 82 |
+
"routing_strategy": "usage-based-routing-v2"
|
| 83 |
+
},
|
| 84 |
+
num_retries=5,
|
| 85 |
)
|
| 86 |
self.agent = CodeAgent(
|
| 87 |
tools=[
|