-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Allow proper type on AnthropicProvider
when using Bedrock
#2490
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
base: main
Are you sure you want to change the base?
Conversation
PR Change SummaryUpgraded AnthropicProvider and AnthropicModel to support both AsyncAnthropic and AsyncAnthropicBedrock.
Modified Files
How can I customize these reviews?Check out the Hyperlint AI Reviewer docs for more information on how to customize the review. If you just want to ignore it on this PR, you can add the Note specifically for link checks, we only check the first 30 links in a file and we cache the results for several hours (for instance, if you just added a page, you might experience this). Our recommendation is to add |
aws_secret_key: str | None = None, | ||
aws_access_key: str | None = None, | ||
aws_region: str | None = None, | ||
aws_profile: str | None = None, | ||
aws_session_token: str | None = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to not complicate things here.
The user can just pass the client when using Bedrock.
except ImportError as _import_error: # pragma: no cover | ||
raise ImportError( | ||
'Please install the `anthropic` package to use the Anthropic provider, ' | ||
'you can use the `anthropic` optional group — `pip install "pydantic-ai-slim[anthropic]"`' | ||
) from _import_error | ||
|
||
from typing_extensions import TypeAlias |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move this import up (before the try..except).
|
||
class AnthropicProvider(Provider[AsyncAnthropic]): | ||
ASYNC_ANTHROPIC_CLIENT: TypeAlias = Union[AsyncAnthropic, AsyncAnthropicBedrock] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it really union what we want?
ASYNC_ANTHROPIC_CLIENT: TypeAlias = Union[AsyncAnthropic, AsyncAnthropicBedrock] | |
AsyncAnthropicClient = TypeVar("AsyncAnthropicClient", AsyncAnthropic, AsyncAnthropicBedrock) |
Does this work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use full uppercase for type aliases, that's for constants. 🙏
print(f'Evaluation took less than 1s: {time.time() - t0 < 1}') | ||
#> Evaluation took less than 1s: True | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've applied this in another PR.
AnthropicProvider
when using Bedrock
Resolves:
#2215
Summary:
Upgrades AnthropicProvider and AnthropicModel to support both AsyncAnthropic and AsyncAnthropicBedrock.