Skip to content

Commit 9ff37a0

Browse files
Standardize "py" -> "python" in code blocks with pre-commit (#217)
1 parent 4edb122 commit 9ff37a0

22 files changed

+88
-88
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ PydanticAI is in early beta, the API is still subject to change and there's a lo
4949

5050
Here's a minimal example of PydanticAI:
5151

52-
```py
52+
```python
5353
from pydantic_ai import Agent
5454

5555
# Define a very simple agent including the model to use, you can also set the model when running the agent.
@@ -80,7 +80,7 @@ Here is a concise example using PydanticAI to build a support agent for a bank:
8080

8181
**(Better documented example [in the docs](https://ai.pydantic.dev/#tools-dependency-injection-example))**
8282

83-
```py
83+
```python
8484
from dataclasses import dataclass
8585

8686
from pydantic import BaseModel, Field

docs/agents.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ In typing terms, agents are generic in their dependency and result types, e.g.,
1717

1818
Here's a toy example of an agent that simulates a roulette wheel:
1919

20-
```py title="roulette_wheel.py"
20+
```python {title="roulette_wheel.py"}
2121
from pydantic_ai import Agent, RunContext
2222

2323
roulette_agent = Agent( # (1)!
@@ -67,7 +67,7 @@ There are three ways to run an agent:
6767

6868
Here's a simple example demonstrating all three:
6969

70-
```py title="run_agent.py"
70+
```python {title="run_agent.py"}
7171
from pydantic_ai import Agent
7272

7373
agent = Agent('openai:gpt-4o')
@@ -95,7 +95,7 @@ You can also pass messages from previous runs to continue a conversation or prov
9595
to manage conflicts between event loops that occur between jupyter's event loops and `pydantic-ai`'s.
9696

9797
Before you execute any agent runs, do the following:
98-
```py {test="skip", lint="skip"}
98+
```python {test="skip" lint="skip"}
9999
import nest_asyncio
100100
nest_asyncio.apply()
101101
```
@@ -106,7 +106,7 @@ An agent **run** might represent an entire conversation — there's no limit to
106106

107107
Here's an example of a conversation comprised of multiple runs:
108108

109-
```py title="conversation_example.py" hl_lines="13"
109+
```python {title="conversation_example.py" hl_lines="13"}
110110
from pydantic_ai import Agent
111111

112112
agent = Agent('openai:gpt-4o')
@@ -144,7 +144,7 @@ In particular, agents are generic in both the type of their dependencies and the
144144

145145
Consider the following script with type mistakes:
146146

147-
```py title="type_mistakes.py" hl_lines="18 28"
147+
```python {title="type_mistakes.py" hl_lines="18 28"}
148148
from dataclasses import dataclass
149149

150150
from pydantic_ai import Agent, RunContext
@@ -203,7 +203,7 @@ You can add both to a single agent; they're appended in the order they're define
203203

204204
Here's an example using both types of system prompts:
205205

206-
```py title="system_prompts.py"
206+
```python {title="system_prompts.py"}
207207
from datetime import date
208208

209209
from pydantic_ai import Agent, RunContext
@@ -258,7 +258,7 @@ There are a number of ways to register tools with an agent:
258258

259259
Here's an example using both:
260260

261-
```py title="dice_game.py"
261+
```python {title="dice_game.py"}
262262
import random
263263

264264
from pydantic_ai import Agent, RunContext
@@ -301,7 +301,7 @@ _(This example is complete, it can be run "as is")_
301301

302302
Let's print the messages from that game to see what happened:
303303

304-
```py title="dice_game_messages.py"
304+
```python {title="dice_game_messages.py"}
305305
from dice_game import dice_result
306306

307307
print(dice_result.all_messages())
@@ -399,7 +399,7 @@ sequenceDiagram
399399

400400
As well as using the decorators, we can register tools via the `tools` argument to the [`Agent` constructor][pydantic_ai.Agent.__init__]. This is useful when you want to re-use tools, and can also give more fine-grained control over the tools.
401401

402-
```py title="dice_game_tool_kwarg.py"
402+
```python {title="dice_game_tool_kwarg.py"}
403403
import random
404404

405405
from pydantic_ai import Agent, RunContext, Tool
@@ -452,7 +452,7 @@ Even better, PydanticAI extracts the docstring from functions and (thanks to [gr
452452

453453
To demonstrate a tool's schema, here we use [`FunctionModel`][pydantic_ai.models.function.FunctionModel] to print the schema a model would receive:
454454

455-
```py title="tool_schema.py"
455+
```python {title="tool_schema.py"}
456456
from pydantic_ai import Agent
457457
from pydantic_ai.messages import Message, ModelAnyResponse, ModelTextResponse
458458
from pydantic_ai.models.function import AgentInfo, FunctionModel
@@ -509,7 +509,7 @@ If a tool has a single parameter that can be represented as an object in JSON sc
509509

510510
Here's an example, we use [`TestModel.agent_model_function_tools`][pydantic_ai.models.test.TestModel.agent_model_function_tools] to inspect the tool schema that would be passed to the model.
511511

512-
```py title="single_parameter_tool.py"
512+
```python {title="single_parameter_tool.py"}
513513
from pydantic import BaseModel
514514

515515
from pydantic_ai import Agent
@@ -577,7 +577,7 @@ Here's a simple `prepare` method that only includes the tool if the value of the
577577

578578
As with the previous example, we use [`TestModel`][pydantic_ai.models.test.TestModel] to demonstrate the behavior without calling a real model.
579579

580-
```py title="tool_only_if_42.py"
580+
```python {title="tool_only_if_42.py"}
581581
from typing import Union
582582

583583
from pydantic_ai import Agent, RunContext
@@ -612,7 +612,7 @@ Here's a more complex example where we change the description of the `name` para
612612

613613
For the sake of variation, we create this tool using the [`Tool`][pydantic_ai.tools.Tool] dataclass.
614614

615-
```py title="customize_name.py"
615+
```python {title="customize_name.py"}
616616
from __future__ import annotations
617617

618618
from typing import Literal
@@ -678,7 +678,7 @@ You can also raise [`ModelRetry`][pydantic_ai.exceptions.ModelRetry] from within
678678

679679
Here's an example:
680680

681-
```py title="tool_retry.py"
681+
```python {title="tool_retry.py"}
682682
from fake_database import DatabaseConn
683683
from pydantic import BaseModel
684684

@@ -726,7 +726,7 @@ If models behave unexpectedly (e.g., the retry limit is exceeded, or their API r
726726

727727
In these cases, [`agent.last_run_messages`][pydantic_ai.Agent.last_run_messages] can be used to access the messages exchanged during the run to help diagnose the issue.
728728

729-
```py
729+
```python
730730
from pydantic_ai import Agent, ModelRetry, UnexpectedModelBehavior
731731

732732
agent = Agent('openai:gpt-4o')

docs/api/models/ollama.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ For details on how to set up authentication with this model, see [model configur
88

99
With `ollama` installed, you can run the server with the model you want to use:
1010

11-
```bash title="terminal-run-ollama"
11+
```bash {title="terminal-run-ollama"}
1212
ollama run llama3.2
1313
```
1414
(this will pull the `llama3.2` model if you don't already have it downloaded)
1515

1616
Then run your code, here's a minimal example:
1717

18-
```py title="ollama_example.py"
18+
```python {title="ollama_example.py"}
1919
from pydantic import BaseModel
2020

2121
from pydantic_ai import Agent
@@ -37,7 +37,7 @@ print(result.cost())
3737

3838
## Example using a remote server
3939

40-
```py title="ollama_example_with_remote_server.py"
40+
```python {title="ollama_example_with_remote_server.py"}
4141
from pydantic import BaseModel
4242

4343
from pydantic_ai import Agent

docs/api/models/vertexai.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ see [model configuration for Gemini via VertexAI](../../install.md#gemini-via-ve
1919

2020
With the default google project already configured in your environment using "application default credentials":
2121

22-
```py title="vertex_example_env.py"
22+
```python {title="vertex_example_env.py"}
2323
from pydantic_ai import Agent
2424
from pydantic_ai.models.vertexai import VertexAIModel
2525

@@ -32,7 +32,7 @@ print(result.data)
3232

3333
Or using a service account JSON file:
3434

35-
```py title="vertex_example_service_account.py"
35+
```python {title="vertex_example_service_account.py"}
3636
from pydantic_ai import Agent
3737
from pydantic_ai.models.vertexai import VertexAIModel
3838

docs/dependencies.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Here's an example of defining an agent that requires dependencies.
1212

1313
(**Note:** dependencies aren't actually used in this example, see [Accessing Dependencies](#accessing-dependencies) below)
1414

15-
```py title="unused_dependencies.py"
15+
```python {title="unused_dependencies.py"}
1616
from dataclasses import dataclass
1717

1818
import httpx
@@ -54,7 +54,7 @@ _(This example is complete, it can be run "as is")_
5454
Dependencies are accessed through the [`RunContext`][pydantic_ai.tools.RunContext] type, this should be the first parameter of system prompt functions etc.
5555

5656

57-
```py title="system_prompt_dependencies.py" hl_lines="20-27"
57+
```python {title="system_prompt_dependencies.py" hl_lines="20-27"}
5858
from dataclasses import dataclass
5959

6060
import httpx
@@ -112,7 +112,7 @@ to use `async` methods where dependencies perform IO, although synchronous depen
112112

113113
Here's the same example as above, but with a synchronous dependency:
114114

115-
```py title="sync_dependencies.py"
115+
```python {title="sync_dependencies.py"}
116116
from dataclasses import dataclass
117117

118118
import httpx
@@ -160,7 +160,7 @@ _(This example is complete, it can be run "as is")_
160160

161161
As well as system prompts, dependencies can be used in [tools](agents.md#function-tools) and [result validators](results.md#result-validators-functions).
162162

163-
```py title="full_example.py" hl_lines="27-35 38-48"
163+
```python {title="full_example.py" hl_lines="27-35 38-48"}
164164
from dataclasses import dataclass
165165

166166
import httpx
@@ -233,7 +233,7 @@ while calling application code which in turn calls the agent.
233233

234234
This is done via the [`override`][pydantic_ai.Agent.override] method on the agent.
235235

236-
```py title="joke_app.py"
236+
```python {title="joke_app.py"}
237237
from dataclasses import dataclass
238238

239239
import httpx
@@ -275,7 +275,7 @@ async def application_code(prompt: str) -> str: # (3)!
275275
3. Application code that calls the agent, in a real application this might be an API endpoint.
276276
4. Call the agent from within the application code, in a real application this call might be deep within a call stack. Note `app_deps` here will NOT be used when deps are overridden.
277277

278-
```py title="test_joke_app.py" hl_lines="10-12"
278+
```python {title="test_joke_app.py" hl_lines="10-12"}
279279
from joke_app import MyDeps, application_code, joke_agent
280280

281281

@@ -300,7 +300,7 @@ async def test_application_code():
300300

301301
Since dependencies can be any python type, and agents are just python objects, agents can be dependencies of other agents.
302302

303-
```py title="agents_as_dependencies.py"
303+
```python {title="agents_as_dependencies.py"}
304304
from dataclasses import dataclass
305305

306306
from pydantic_ai import Agent, RunContext

docs/examples/bank-support.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ python/uv-run -m pydantic_ai_examples.bank_support
1818

1919
## Example Code
2020

21-
```py title="bank_support.py"
21+
```python {title="bank_support.py"}
2222
#! pydantic_ai_examples/bank_support.py
2323
```

docs/examples/chat-app.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,18 @@ TODO screenshot.
2929

3030
Python code that runs the chat app:
3131

32-
```py title="chat_app.py"
32+
```python {title="chat_app.py"}
3333
#! pydantic_ai_examples/chat_app.py
3434
```
3535

3636
Simple HTML page to render the app:
3737

38-
```html title="chat_app.html"
38+
```html {title="chat_app.html"}
3939
#! pydantic_ai_examples/chat_app.html
4040
```
4141

4242
TypeScript to handle rendering the messages, to keep this simple (and at the risk of offending frontend developers) the typescript code is passed to the browser as plain text and transpiled in the browser.
4343

44-
```ts title="chat_app.ts"
44+
```ts {title="chat_app.ts"}
4545
#! pydantic_ai_examples/chat_app.ts
4646
```

docs/examples/pydantic-model.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ PYDANTIC_AI_MODEL=gemini-1.5-pro python/uv-run -m pydantic_ai_examples.pydantic_
2525

2626
## Example Code
2727

28-
```py title="pydantic_model.py"
28+
```python {title="pydantic_model.py"}
2929
#! pydantic_ai_examples/pydantic_model.py
3030
```

docs/examples/rag.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ python/uv-run -m pydantic_ai_examples.rag search "How do I configure logfire to
4444

4545
## Example Code
4646

47-
```py title="rag.py"
47+
```python {title="rag.py"}
4848
#! pydantic_ai_examples/rag.py
4949
```

docs/examples/sql-gen.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ This model uses `gemini-1.5-flash` by default since Gemini is good at single sho
3434

3535
## Example Code
3636

37-
```py title="sql_gen.py"
37+
```python {title="sql_gen.py"}
3838
#! pydantic_ai_examples/sql_gen.py
3939
```

0 commit comments

Comments
 (0)