-
Notifications
You must be signed in to change notification settings - Fork 517
feat(kagent-adk): remove litellm as dependency from kagent-adk #1540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a3fa34e
feat: remove litellm as dependency from kagent-adk
jmhbh e67bc57
fix: use boto for bedrock
jmhbh f867d5d
fix: address PR feedback
jmhbh da3c5e1
style: format
jmhbh 3176520
Merge branch 'main' into feat/remove-litellm
jmhbh 83dfd14
fix: address copilot feedback
jmhbh f4e87aa
Merge branch 'main' into feat/remove-litellm
EItanya 856ed9d
fix: resolve invalid json schema issue when calling converse operation
jmhbh 02d4374
fix: address pr feedback
jmhbh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| from ._litellm import KAgentLiteLlm | ||
| from ._anthropic import KAgentAnthropicLlm | ||
| from ._bedrock import KAgentBedrockLlm | ||
| from ._ollama import KAgentOllamaLlm | ||
| from ._openai import AzureOpenAI, OpenAI | ||
|
|
||
| __all__ = ["OpenAI", "AzureOpenAI", "KAgentLiteLlm"] | ||
| __all__ = ["OpenAI", "AzureOpenAI", "KAgentAnthropicLlm", "KAgentBedrockLlm", "KAgentOllamaLlm"] |
43 changes: 43 additions & 0 deletions
43
python/packages/kagent-adk/src/kagent/adk/models/_anthropic.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| """Anthropic model implementation with api_key_passthrough, base_url, and header support.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import logging | ||
| import os | ||
| from functools import cached_property | ||
| from typing import Optional | ||
|
|
||
| from anthropic import AsyncAnthropic | ||
| from google.adk.models.anthropic_llm import AnthropicLlm | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class KAgentAnthropicLlm(AnthropicLlm): | ||
| """Anthropic model with api_key_passthrough, custom base_url, and header support.""" | ||
|
|
||
| api_key_passthrough: Optional[bool] = None | ||
|
|
||
| _api_key: Optional[str] = None | ||
| base_url: Optional[str] = None | ||
| extra_headers: Optional[dict[str, str]] = None | ||
|
|
||
| model_config = {"arbitrary_types_allowed": True} | ||
|
|
||
| def set_passthrough_key(self, token: str) -> None: | ||
| """Forward the Bearer token from the incoming A2A request as the Anthropic API key.""" | ||
| self._api_key = token | ||
| # Invalidate cached client so it's recreated with the new key | ||
| self.__dict__.pop("_anthropic_client", None) | ||
|
|
||
| @cached_property | ||
| def _anthropic_client(self) -> AsyncAnthropic: | ||
| api_key = self._api_key or os.environ.get("ANTHROPIC_API_KEY") | ||
| kwargs = {} | ||
| if api_key: | ||
| kwargs["api_key"] = api_key | ||
| if self.base_url: | ||
| kwargs["base_url"] = self.base_url | ||
| if self.extra_headers: | ||
| kwargs["default_headers"] = self.extra_headers | ||
| return AsyncAnthropic(**kwargs) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.