Skip to content

Conversation

samuelcolvin
Copy link
Member

@samuelcolvin samuelcolvin commented Nov 22, 2024

Example Usage

With the default google project already configured in your environment:

from pydantic_ai import Agent
from pydantic_ai.models.vertexai import VertexAIModel

model = VertexAIModel('gemini-1.5-flash')
agent = Agent(model)
result = agent.run_sync('Tell me a joke.')
print(result.data)
#> Did you hear about the toothpaste scandal? They called it Colgate.

Or using a service account JSON file:

from pydantic_ai import Agent
from pydantic_ai.models.vertexai import VertexAIModel

model = VertexAIModel(
    'gemini-1.5-flash',
    service_account_file='path/to/service-account.json',
)
agent = Agent(model)
result = agent.run_sync('Tell me a joke.')
print(result.data)
#> Did you hear about the toothpaste scandal? They called it Colgate.

Copy link

cloudflare-workers-and-pages bot commented Nov 22, 2024

Deploying pydantic-ai with  Cloudflare Pages  Cloudflare Pages

Latest commit: 73ad697
Status: ✅  Deploy successful!
Preview URL: https://25c1191d.pydantic-ai.pages.dev
Branch Preview URL: https://vertexai.pydantic-ai.pages.dev

View logs

Copy link
Member

@adriangb adriangb left a comment

Choose a reason for hiding this comment

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

I'm not familiar with the details of the codebase but in general looks good to me!

Comment on lines +55 to +56
This is async in case slow/async config checks need to be performed that can't be done in `__init__`.
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure this needs to be clarified in the docstring, I think it's okay if that's just how it is.

Comment on lines -75 to +78
agent_model = m.agent_model({}, True, None)
agent_model = await m.agent_model({}, True, 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 will say that it might be nice if these are forced to be keyword arguments, it'd be easy to mess up and do {}, None, True or something and with None being falsely and whatnot it might fail in surprising ways.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is basically an internal API, otherwise I would agree.

Comment on lines +61 to +64
patch = mocker.patch(
'pydantic_ai.models.vertexai.google.auth.default',
return_value=(NoOpCredentials(), 'my-project-id'),
)
Copy link
Member

Choose a reason for hiding this comment

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

I tend to prefer passing this stuff in as parameters, e.g. have a parameter called _auth_provider: AuthProviderProtocol or something and you pass in a test fake, maybe a mock. You wouldn't be able to do this monkey patching business in Rust 😉

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd rather keen the code clear and mock like this.

@samuelcolvin samuelcolvin merged commit 4672bcd into main Nov 23, 2024
16 checks passed
@samuelcolvin samuelcolvin deleted the vertexai branch November 23, 2024 20:41
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