Skip to content

Commit c643ddc

Browse files
authored
Merge pull request #91 from grasp-technologies/release-0.6.20
simple LiteLLM fallbacks
2 parents 46361fe + 42c4993 commit c643ddc

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "grasp_agents"
3-
version = "0.6.19"
3+
version = "0.6.20"
44
description = "Grasp Agents Library"
55
readme = "README.md"
66
requires-python = ">=3.11.4,<4"

src/grasp_agents/litellm/lite_llm.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ class LiteLLMSettings(OpenAILLMSettings, total=False):
4141
thinking: AnthropicThinkingParam | None
4242

4343

44+
LiteLLMModelName = str
45+
46+
4447
@dataclass(frozen=True)
4548
class LiteLLM(CloudLLM):
4649
llm_settings: LiteLLMSettings | None = None
@@ -55,6 +58,10 @@ class LiteLLM(CloudLLM):
5558
allowed_openai_params: list[str] | None = None
5659
# Mock LLM response for testing
5760
mock_response: str | None = None
61+
# Fallback models to use if the main model fails
62+
fallbacks: list[LiteLLMModelName] = field(default_factory=list[LiteLLMModelName])
63+
# Mock falling back to other models in the fallbacks list for testing
64+
mock_testing_fallbacks: bool = False
5865

5966
router: Router = field(init=False)
6067

@@ -71,6 +78,7 @@ def __post_init__(self) -> None:
7178
"additional_drop_params": self.additional_drop_params,
7279
"allowed_openai_params": self.allowed_openai_params,
7380
"mock_response": self.mock_response,
81+
"mock_testing_fallbacks": self.mock_testing_fallbacks,
7482
# "max_retries": self.max_client_retries,
7583
# "timeout": self.client_timeout,
7684
# "deployment_id": deployment_id,
@@ -114,13 +122,17 @@ def __post_init__(self) -> None:
114122
"Custom HTTP clients are not yet supported when using LiteLLM."
115123
)
116124

125+
main_litellm_model = {
126+
"model_name": self.model_name,
127+
"litellm_params": {"model": self.model_name},
128+
}
129+
fallback_litellm_models = [
130+
{"model_name": fb, "litellm_params": {"model": fb}} for fb in self.fallbacks
131+
]
132+
117133
_router = Router(
118-
model_list=[
119-
{
120-
"model_name": self.model_name,
121-
"litellm_params": {"model": self.model_name},
122-
}
123-
],
134+
model_list=[main_litellm_model, *fallback_litellm_models],
135+
fallbacks=[{self.model_name: self.fallbacks}],
124136
num_retries=self.max_client_retries,
125137
timeout=self.client_timeout,
126138
)

src/grasp_agents/telemetry/phoenix.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ def init_phoenix(
2222
batch: bool = False,
2323
use_litellm_instr: bool = True,
2424
use_llm_provider_instr: bool = True,
25-
api_token: str | None = None,
2625
):
2726
collector_endpoint = os.getenv("TELEMETRY_COLLECTOR_HTTP_ENDPOINT")
2827

@@ -50,9 +49,7 @@ def init_phoenix(
5049
LLM_PROVIDER_NAMES if use_llm_provider_instr or use_litellm_instr else set()
5150
)
5251
exporter = FilteringExporter(
53-
inner=HTTPSpanExporter(
54-
endpoint=collector_endpoint, api_token=api_token, headers=None
55-
),
52+
inner=HTTPSpanExporter(endpoint=collector_endpoint, headers=None),
5653
blocklist=blocklist,
5754
)
5855
if batch:

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)