You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/agents.md
+30-12Lines changed: 30 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -206,26 +206,44 @@ print(result_sync.data)
206
206
207
207
### Model specific settings
208
208
209
-
<!-- TODO: replace this with the gemini safety settings example once added via https://github.com/pydantic/pydantic-ai/issues/373 -->
210
-
211
-
If you wish to further customize model behavior, you can use a subclass of [`ModelSettings`][pydantic_ai.settings.ModelSettings], like [`AnthropicModelSettings`][pydantic_ai.models.anthropic.AnthropicModelSettings], associated with your model of choice.
209
+
If you wish to further customize model behavior, you can use a subclass of [`ModelSettings`][pydantic_ai.settings.ModelSettings], like [`GeminiModelSettings`][pydantic_ai.models.gemini.GeminiModelSettings], associated with your model of choice.
212
210
213
211
For example:
214
212
215
213
```py
216
-
from pydantic_ai import Agent
217
-
from pydantic_ai.models.anthropicimportAnthropicModelSettings
214
+
from pydantic_ai import Agent, UnexpectedModelBehavior
215
+
from pydantic_ai.models.geminiimportGeminiModelSettings
'Write a list of 5 very rude things that I might say to the universe after stubbing my toe in the dark:',
222
+
model_settings=GeminiModelSettings(
223
+
temperature=0.0, # general model settings can also be specified
224
+
gemini_safety_settings=[
225
+
{
226
+
'category': 'HARM_CATEGORY_HARASSMENT',
227
+
'threshold': 'BLOCK_LOW_AND_ABOVE',
228
+
},
229
+
{
230
+
'category': 'HARM_CATEGORY_HATE_SPEECH',
231
+
'threshold': 'BLOCK_LOW_AND_ABOVE',
232
+
},
233
+
],
234
+
),
235
+
)
236
+
except UnexpectedModelBehavior as e:
237
+
print(e) # (1)!
238
+
"""
239
+
Safety settings triggered, body:
240
+
<safety settings details>
241
+
"""
227
242
```
228
243
244
+
1. This error is raised because the safety thresholds were exceeded.
245
+
Generally, `result` would contain a normal `ModelResponse`.
246
+
229
247
## Runs vs. Conversations
230
248
231
249
An agent **run** might represent an entire conversation — there's no limit to how many messages can be exchanged in a single run. However, a **conversation** might also be composed of multiple runs, especially if you need to maintain state between separate interactions or API calls.
0 commit comments