-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Install setup #98
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
Merged
Merged
Install setup #98
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
72fdb1b
extending install to document setup
samuelcolvin dcd1070
fix docs examples
samuelcolvin 2d6d7d0
improving install docs
samuelcolvin e4b35ca
fix examples tests
samuelcolvin ffb1f7a
extract intro from python files for models
samuelcolvin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
# `pydantic_ai.models.function` | ||
|
||
A model controlled by a local function. | ||
|
||
[`FunctionModel`][pydantic_ai.models.function.FunctionModel] is similar to [`TestModel`][pydantic_ai.models.test.TestModel], | ||
but allows greater control over the model's behavior. | ||
|
||
Its primary use case is for more advanced unit testing than is possible with `TestModel`. | ||
|
||
::: pydantic_ai.models.function |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,20 @@ | ||
# `pydantic_ai.models.gemini` | ||
|
||
Custom interface to the `generativelanguage.googleapis.com` API using | ||
[HTTPX](https://www.python-httpx.org/) and [Pydantic](https://docs.pydantic.dev/latest/. | ||
|
||
The Google SDK for interacting with the `generativelanguage.googleapis.com` API | ||
[`google-generativeai`](https://ai.google.dev/gemini-api/docs/quickstart?lang=python) reads like it was written by a | ||
Java developer who thought they knew everything about OOP, spent 30 minutes trying to learn Python, | ||
gave up and decided to build the library to prove how horrible Python is. It also doesn't use httpx for HTTP requests, | ||
and tries to implement tool calling itself, but doesn't use Pydantic or equivalent for validation. | ||
|
||
We therefore implement support for the API directly. | ||
|
||
Despite these shortcomings, the Gemini model is actually quite powerful and very fast. | ||
|
||
## Setup | ||
|
||
For details on how to set up authentication with this model, see [model configuration for Gemini](../../install.md#gemini). | ||
|
||
::: pydantic_ai.models.gemini |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
# `pydantic_ai.models.groq` | ||
|
||
## Setup | ||
|
||
For details on how to set up authentication with this model, see [model configuration for Groq](../../install.md#groq). | ||
|
||
::: pydantic_ai.models.groq |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
# `pydantic_ai.models.openai` | ||
|
||
## Setup | ||
|
||
For details on how to set up authentication with this model, see [model configuration for OpenAI](../../install.md#openai). | ||
|
||
::: pydantic_ai.models.openai |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,52 @@ | ||
# `pydantic_ai.models.vertexai` | ||
|
||
Custom interface to the `*-aiplatform.googleapis.com` API for Gemini models. | ||
|
||
This model uses [`GeminiAgentModel`][pydantic_ai.models.gemini.GeminiAgentModel] with just the URL and auth method | ||
changed from [`GeminiModel`][pydantic_ai.models.gemini.GeminiModel], it relies on the VertexAI | ||
[`generateContent`](https://cloud.google.com/vertex-ai/docs/reference/rest/v1/projects.locations.endpoints/generateContent) | ||
and | ||
[`streamGenerateContent`](https://cloud.google.com/vertex-ai/docs/reference/rest/v1/projects.locations.endpoints/streamGenerateContent) | ||
function endpoints | ||
having the same schemas as the equivalent [Gemini endpoints][pydantic_ai.models.gemini.GeminiModel]. | ||
|
||
There are four advantages of using this API over the `generativelanguage.googleapis.com` API which | ||
[`GeminiModel`][pydantic_ai.models.gemini.GeminiModel] uses, and one big disadvantage. | ||
|
||
## Setup | ||
|
||
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], | ||
see [model configuration for Gemini via VertexAI](../../install.md#gemini-via-vertexai). | ||
|
||
## Example Usage | ||
|
||
With the default google project already configured in your environment using "application default credentials": | ||
|
||
```py title="vertex_example_env.py" | ||
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: | ||
|
||
```py title="vertex_example_service_account.py" | ||
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. | ||
``` | ||
|
||
::: pydantic_ai.models.vertexai |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.