Skip to content

Add provider for Anthropic's Vertexai Client #1392

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 1 commit into
base: main
Choose a base branch
from

Conversation

ehaca
Copy link
Contributor

@ehaca ehaca commented Apr 6, 2025

Hello folks,
I had some time and started drafting a possible implementation for this issue: #960.
There's still lots of work to do, but I was feeling kind of insecure about my approach and wanted to get some (both general and concrete) feedback if possible before investing more time on it :)

My main questions are:

  1. Is the idea about creating yet another extra something of your liking?
  2. The Pycharm typing issue about
 def __init__(
        self,
        model_name: AnthropicModelName,
        *,
        # breaking this in multiple lines breaks pycharm type recognition. However, I was unable to stop ruff from
        # doing it - # fmt: skip etc didn't work  :(
        provider: Literal['anthropic', 'anthropic-vertex']
        | Provider[AsyncAnthropicVertex]
        | Provider[AsyncAnthropic] =  # fmt: skip
        'anthropic',
    ):
  1. Now I am getting some static typing errors for test_init in tests/models/test_anthropic.py, how should I handle this?

Thank you very much for your feedback and help and have a nice day :)

Comment on lines +120 to +125
# breaking this in multiple lines breaks pycharm type recognition. However, I was unable to stop ruff from
# doing it - # fmt: skip etc didn't work :(
provider: Literal['anthropic', 'anthropic-vertex']
| Provider[AsyncAnthropicVertex]
| Provider[AsyncAnthropic] = # fmt: skip
'anthropic',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to do # fmt: off and # fmt: on after.

instance of `Provider[AsyncAnthropic]`. If not provided, the other parameters will be used.
provider: The provider to use for the Anthropic API. Can be either the string 'anthropic',
'anthropic-vertex', or an instance of Provider[AsyncAnthropic] or Provider[AsyncAnthropicVertex].
Defaults to 'anthropic'.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you should also add an entry to the KnownModelName literal at models/__init__.py

Comment on lines +76 to +79
elif provider == 'anthropic-vertex':
from .anthropic_vertex import AnthropicVertexProvider

return AnthropicVertexProvider()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is tricky. If you want google-vertex:<anthropic-model>, the agent should be able to infer this provider instead of the other... Maybe the provider should offer different clients depending on the model?

Right now, the GoogleVertexProvider is a generic on the client, which currently is httpx.AsyncClient. What the provider can offer a client via method?

class GoogleVertexProvider(Provider):
    def get_client(self, tp: type[T]) -> T:
        if isinstance(tp, httpx.AsyncClient):
            return self.httpx_client
        elif isinstance(tp, AsyncAnthropicVertex):
            return self.anthropic_client
        else:
            raise ValueError('not supported')

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.

3 participants