Skip to content

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

akoshel
Copy link

@akoshel akoshel commented Aug 9, 2025

Resolves:
#2215

Summary:
Upgrades AnthropicProvider and AnthropicModel to support both AsyncAnthropic and AsyncAnthropicBedrock.

Copy link
Contributor

hyperlint-ai bot commented Aug 9, 2025

PR Change Summary

Upgraded AnthropicProvider and AnthropicModel to support both AsyncAnthropic and AsyncAnthropicBedrock.

  • Upgraded AnthropicProvider to support AsyncAnthropic.
  • Upgraded AnthropicModel to support AsyncAnthropicBedrock.
  • Modified evaluation timing in documentation.

Modified Files

  • docs/evals.md

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 hyperlint-ignore label to the PR. Future changes won't trigger a Hyperlint review.

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 hyperlint-ignore to the PR to ignore the link check for this PR.

Comment on lines +54 to +58
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,
Copy link
Member

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
Copy link
Member

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]
Copy link
Member

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?

Suggested change
ASYNC_ANTHROPIC_CLIENT: TypeAlias = Union[AsyncAnthropic, AsyncAnthropicBedrock]
AsyncAnthropicClient = TypeVar("AsyncAnthropicClient", AsyncAnthropic, AsyncAnthropicBedrock)

Does this work?

Copy link
Member

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. 🙏

Comment on lines +344 to 346
print(f'Evaluation took less than 1s: {time.time() - t0 < 1}')
#> Evaluation took less than 1s: True

Copy link
Member

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.

@Kludex Kludex changed the title Issue 2215 Allow proper type on AnthropicProvider when using Bedrock Aug 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants