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
15 changes: 10 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,16 @@ jobs:
enable-cache: true

- run: uv run --frozen coverage combine coverage
# - run: uv run --frozen coverage xml
# - uses: codecov/codecov-action@v4
# with:
# token: ${{ secrets.CODECOV_TOKEN }}
# file: ./coverage.xml

- run: uv run --frozen coverage html --show-contexts --title "PydanticAI coverage for ${{ github.sha }}"

- name: Store coverage html
uses: actions/upload-artifact@v4
with:
name: coverage-html
path: htmlcov
include-hidden-files: true

- run: uv run --frozen coverage report --fail-under 95

# https://github.com/marketplace/actions/alls-green#why used for branch protection checks
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Smokeshow

on:
workflow_run:
workflows: [CI]
types: [completed]

permissions:
statuses: write

jobs:
smokeshow:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest

steps:
- uses: actions/setup-python@v5
with:
python-version: '3.12'

- run: pip install smokeshow

- uses: dawidd6/action-download-artifact@v6
with:
workflow: ci.yml
commit: ${{ github.event.workflow_run.head_sha }}

- run: smokeshow upload coverage-html
env:
SMOKESHOW_GITHUB_STATUS_DESCRIPTION: Coverage {coverage-percentage}
SMOKESHOW_GITHUB_COVERAGE_THRESHOLD: 95
SMOKESHOW_GITHUB_CONTEXT: coverage
SMOKESHOW_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SMOKESHOW_GITHUB_PR_HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
SMOKESHOW_AUTH_KEY: ${{ secrets.SMOKESHOW_AUTH_KEY }}
9 changes: 6 additions & 3 deletions pydantic_ai/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from functools import cache
from typing import TYPE_CHECKING, Protocol, Union

from httpx import AsyncClient as AsyncHTTPClient
import httpx

from ..messages import Message, ModelAnyResponse, ModelStructuredResponse

Expand Down Expand Up @@ -234,11 +234,14 @@ class AbstractToolDefinition(Protocol):


@cache
def cached_async_http_client() -> AsyncHTTPClient:
def cached_async_http_client(timeout: int = 600, connect: int = 5) -> httpx.AsyncClient:
"""Cached HTTPX async client so multiple agents and calls can share the same client.

There are good reasons why in production you should use a `httpx.AsyncClient` as an async context manager as
described in [encode/httpx#2026](https://github.com/encode/httpx/pull/2026), but when experimenting or showing
examples, it's very useful not to, this allows multiple Agents to use a single client.

The default timeouts match those of OpenAI,
see <https://github.com/openai/openai-python/blob/v1.54.4/src/openai/_constants.py#L9>.
"""
return AsyncHTTPClient(timeout=30)
return httpx.AsyncClient(timeout=httpx.Timeout(timeout=timeout, connect=connect))
Loading