Skip to content

Commit 1e16660

Browse files
authored
Install setup (#98)
1 parent 9d7114f commit 1e16660

File tree

15 files changed

+420
-107
lines changed

15 files changed

+420
-107
lines changed

docs/api/models/function.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
# `pydantic_ai.models.function`
22

3+
A model controlled by a local function.
4+
5+
[`FunctionModel`][pydantic_ai.models.function.FunctionModel] is similar to [`TestModel`][pydantic_ai.models.test.TestModel],
6+
but allows greater control over the model's behavior.
7+
8+
Its primary use case is for more advanced unit testing than is possible with `TestModel`.
9+
310
::: pydantic_ai.models.function

docs/api/models/gemini.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
11
# `pydantic_ai.models.gemini`
22

3+
Custom interface to the `generativelanguage.googleapis.com` API using
4+
[HTTPX](https://www.python-httpx.org/) and [Pydantic](https://docs.pydantic.dev/latest/.
5+
6+
The Google SDK for interacting with the `generativelanguage.googleapis.com` API
7+
[`google-generativeai`](https://ai.google.dev/gemini-api/docs/quickstart?lang=python) reads like it was written by a
8+
Java developer who thought they knew everything about OOP, spent 30 minutes trying to learn Python,
9+
gave up and decided to build the library to prove how horrible Python is. It also doesn't use httpx for HTTP requests,
10+
and tries to implement tool calling itself, but doesn't use Pydantic or equivalent for validation.
11+
12+
We therefore implement support for the API directly.
13+
14+
Despite these shortcomings, the Gemini model is actually quite powerful and very fast.
15+
16+
## Setup
17+
18+
For details on how to set up authentication with this model, see [model configuration for Gemini](../../install.md#gemini).
19+
320
::: pydantic_ai.models.gemini

docs/api/models/groq.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
# `pydantic_ai.models.groq`
22

3+
## Setup
4+
5+
For details on how to set up authentication with this model, see [model configuration for Groq](../../install.md#groq).
6+
37
::: pydantic_ai.models.groq

docs/api/models/openai.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
# `pydantic_ai.models.openai`
22

3+
## Setup
4+
5+
For details on how to set up authentication with this model, see [model configuration for OpenAI](../../install.md#openai).
6+
37
::: pydantic_ai.models.openai

docs/api/models/vertexai.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,52 @@
11
# `pydantic_ai.models.vertexai`
22

3+
Custom interface to the `*-aiplatform.googleapis.com` API for Gemini models.
4+
5+
This model uses [`GeminiAgentModel`][pydantic_ai.models.gemini.GeminiAgentModel] with just the URL and auth method
6+
changed from [`GeminiModel`][pydantic_ai.models.gemini.GeminiModel], it relies on the VertexAI
7+
[`generateContent`](https://cloud.google.com/vertex-ai/docs/reference/rest/v1/projects.locations.endpoints/generateContent)
8+
and
9+
[`streamGenerateContent`](https://cloud.google.com/vertex-ai/docs/reference/rest/v1/projects.locations.endpoints/streamGenerateContent)
10+
function endpoints
11+
having the same schemas as the equivalent [Gemini endpoints][pydantic_ai.models.gemini.GeminiModel].
12+
13+
There are four advantages of using this API over the `generativelanguage.googleapis.com` API which
14+
[`GeminiModel`][pydantic_ai.models.gemini.GeminiModel] uses, and one big disadvantage.
15+
16+
## Setup
17+
18+
For details on how to set up authentication with this model as well as a comparison with the `generativelanguage.googleapis.com` API used by [`GeminiModel`][pydantic_ai.models.gemini.GeminiModel],
19+
see [model configuration for Gemini via VertexAI](../../install.md#gemini-via-vertexai).
20+
21+
## Example Usage
22+
23+
With the default google project already configured in your environment using "application default credentials":
24+
25+
```py title="vertex_example_env.py"
26+
from pydantic_ai import Agent
27+
from pydantic_ai.models.vertexai import VertexAIModel
28+
29+
model = VertexAIModel('gemini-1.5-flash')
30+
agent = Agent(model)
31+
result = agent.run_sync('Tell me a joke.')
32+
print(result.data)
33+
#> Did you hear about the toothpaste scandal? They called it Colgate.
34+
```
35+
36+
Or using a service account JSON file:
37+
38+
```py title="vertex_example_service_account.py"
39+
from pydantic_ai import Agent
40+
from pydantic_ai.models.vertexai import VertexAIModel
41+
42+
model = VertexAIModel(
43+
'gemini-1.5-flash',
44+
service_account_file='path/to/service-account.json',
45+
)
46+
agent = Agent(model)
47+
result = agent.run_sync('Tell me a joke.')
48+
print(result.data)
49+
#> Did you hear about the toothpaste scandal? They called it Colgate.
50+
```
51+
352
::: pydantic_ai.models.vertexai

docs/examples/index.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,9 @@ If you clone the repo, you should instead use `uv sync --extra examples` to inst
2020

2121
### Setting model environment variables
2222

23-
All these examples will need you to set either:
23+
These examples will need you to set up authentication with one or more of the LLMs, see the [model configuration](../install.md#model-configuration) docs for details on how to do this.
2424

25-
* `OPENAI_API_KEY` to use OpenAI models, go to [platform.openai.com](https://platform.openai.com/) and follow your nose until you find how to generate an API key
26-
* or, `GEMINI_API_KEY` to use Google Gemini models, go to [aistudio.google.com](https://aistudio.google.com/) and do the same to generate an API key
27-
28-
Then set the API key as an environment variable with:
25+
TL;DR: in most cases you'll need to set one of the following environment variables:
2926

3027
=== "OpenAI"
3128

0 commit comments

Comments
 (0)