Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions docs/.hooks/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations as _annotations

import re
import urllib.parse
from pathlib import Path

from mkdocs.config import Config
Expand All @@ -12,6 +13,7 @@ def on_page_markdown(markdown: str, page: Page, config: Config, files: Files) ->
"""Called on each file after it is read and before it is converted to HTML."""
markdown = replace_uv_python_run(markdown)
markdown = render_examples(markdown)
markdown = render_video(markdown)
return markdown


Expand Down Expand Up @@ -52,3 +54,28 @@ def sub_example(m: re.Match[str]) -> str:
content = re.sub(r'^""".*?"""', '', content, count=1, flags=re.S).strip()

return content


def render_video(markdown: str) -> str:
return re.sub(r'\{\{ *video\((["\'])(.+?)\1(?:, (\d+))?\) *\}\}', sub_cf_video, markdown)


def sub_cf_video(m: re.Match[str]) -> str:
video_id = m.group(2)
time = m.group(3)
time = f'{time}s' if time else ''

domain = 'https://customer-nmegqx24430okhaq.cloudflarestream.com'
poster = f'{domain}/{video_id}/thumbnails/thumbnail.jpg?time={time}&height=600'
print(poster)
return f"""
<div style="position: relative; padding-top: 67%;">
<iframe
src="{domain}/{video_id}/iframe?poster={urllib.parse.quote_plus(poster)}"
loading="lazy"
style="border: none; position: absolute; top: 0; left: 0; height: 100%; width: 100%;"
allow="accelerometer; gyroscope; autoplay; encrypted-media; picture-in-picture;"
allowfullscreen="true"
></iframe>
</div>
"""
4 changes: 4 additions & 0 deletions docs/examples/stream-whales.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ With [dependencies installed and environment variables set](./index.md#usage), r
python/uv-run -m pydantic_ai_examples.stream_whales
```

Should give an output like this:

{{ video('53dd5e7664c20ae90ed90ae42f606bf3', 25) }}

## Example Code

```py title="stream_whales.py"
Expand Down
5 changes: 2 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ PydanticAI is a Python Agent Framework designed to make it less painful to build
* Type-safe
* Control flow and composing agents is done with vanilla python, allowing you to make use of the same Python development best practices you'd use in any other (non-AI) project
* [Structured response](results.md#structured-result-validation) validation with Pydantic
* [Streamed responses](results.md#streamed-results) , including validation of streamed _structured_ responses with Pydantic
* [Streamed responses](results.md#streamed-results), including validation of streamed _structured_ responses with Pydantic
* Novel, type-safe [dependency injection system](dependencies.md), useful for testing and eval-driven iterative development
* [Logfire integration](logfire.md) for debugging and monitoring the performance and general behavior of your LLM-powered application

Expand Down Expand Up @@ -81,8 +81,7 @@ support_agent = Agent( # (1)!
result_type=SupportResult, # (9)!
system_prompt=( # (4)!
'You are a support agent in our bank, give the '
'customer support and judge the risk level of their query. '
"Reply using the customer's name."
'customer support and judge the risk level of their query.'
),
)

Expand Down
Loading