Skip to content

Commit 1afaead

Browse files
authored
adding whale video (#78)
1 parent 7776dc5 commit 1afaead

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

docs/.hooks/main.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations as _annotations
22

33
import re
4+
import urllib.parse
45
from pathlib import Path
56

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

1719

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

5456
return content
57+
58+
59+
def render_video(markdown: str) -> str:
60+
return re.sub(r'\{\{ *video\((["\'])(.+?)\1(?:, (\d+))?\) *\}\}', sub_cf_video, markdown)
61+
62+
63+
def sub_cf_video(m: re.Match[str]) -> str:
64+
video_id = m.group(2)
65+
time = m.group(3)
66+
time = f'{time}s' if time else ''
67+
68+
domain = 'https://customer-nmegqx24430okhaq.cloudflarestream.com'
69+
poster = f'{domain}/{video_id}/thumbnails/thumbnail.jpg?time={time}&height=600'
70+
print(poster)
71+
return f"""
72+
<div style="position: relative; padding-top: 67%;">
73+
<iframe
74+
src="{domain}/{video_id}/iframe?poster={urllib.parse.quote_plus(poster)}"
75+
loading="lazy"
76+
style="border: none; position: absolute; top: 0; left: 0; height: 100%; width: 100%;"
77+
allow="accelerometer; gyroscope; autoplay; encrypted-media; picture-in-picture;"
78+
allowfullscreen="true"
79+
></iframe>
80+
</div>
81+
"""

docs/examples/stream-whales.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ With [dependencies installed and environment variables set](./index.md#usage), r
1515
python/uv-run -m pydantic_ai_examples.stream_whales
1616
```
1717

18+
Should give an output like this:
19+
20+
{{ video('53dd5e7664c20ae90ed90ae42f606bf3', 25) }}
21+
1822
## Example Code
1923

2024
```py title="stream_whales.py"

docs/index.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ PydanticAI is a Python Agent Framework designed to make it less painful to build
1515
* Type-safe
1616
* 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
1717
* [Structured response](results.md#structured-result-validation) validation with Pydantic
18-
* [Streamed responses](results.md#streamed-results) , including validation of streamed _structured_ responses with Pydantic
18+
* [Streamed responses](results.md#streamed-results), including validation of streamed _structured_ responses with Pydantic
1919
* Novel, type-safe [dependency injection system](dependencies.md), useful for testing and eval-driven iterative development
2020
* [Logfire integration](logfire.md) for debugging and monitoring the performance and general behavior of your LLM-powered application
2121

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

0 commit comments

Comments
 (0)