Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita341e56

Browse files
authored
docs: document how to use a customAsyncOpenAI in the provider (#2073)
1 parent64a1186 commita341e56

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

‎docs/models/openai.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,21 @@ agent = Agent(model)
6161

6262
`OpenAIProvider` also accepts a custom`AsyncOpenAI` client via the`openai_client` parameter, so you can customise the`organization`,`project`,`base_url` etc. as defined in the[OpenAI API docs](https://platform.openai.com/docs/api-reference).
6363

64-
You could also use the[`AsyncAzureOpenAI`](https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/switching-endpoints) client to use the Azure OpenAI API.
64+
```python {title="custom_openai_client.py"}
65+
from openaiimport AsyncOpenAI
66+
67+
from pydantic_aiimport Agent
68+
from pydantic_ai.models.openaiimport OpenAIModel
69+
from pydantic_ai.providers.openaiimport OpenAIProvider
70+
71+
client= AsyncOpenAI(max_retries=3)
72+
model= OpenAIModel('gpt-4o',provider=OpenAIProvider(openai_client=client))
73+
agent= Agent(model)
74+
...
75+
```
76+
77+
You could also use the[`AsyncAzureOpenAI`](https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/switching-endpoints) client
78+
to use the Azure OpenAI API. Note that the`AsyncAzureOpenAI` is a subclass of`AsyncOpenAI`.
6579

6680
```python
6781
from openaiimport AsyncAzureOpenAI

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp