From db3a18e3be5748c408bdaec0bba0696e1b9a0825 Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Thu, 14 Nov 2024 23:31:47 +0000 Subject: [PATCH] Smokeshow coverage --- .github/workflows/ci.yml | 15 +++++++++----- .github/workflows/coverage.yaml | 35 +++++++++++++++++++++++++++++++++ pydantic_ai/models/__init__.py | 9 ++++++--- 3 files changed, 51 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/coverage.yaml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d3b9cf8898..de1eb4fefa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml new file mode 100644 index 0000000000..3071b2c587 --- /dev/null +++ b/.github/workflows/coverage.yaml @@ -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 }} diff --git a/pydantic_ai/models/__init__.py b/pydantic_ai/models/__init__.py index b35452a46a..32de16a344 100644 --- a/pydantic_ai/models/__init__.py +++ b/pydantic_ai/models/__init__.py @@ -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 @@ -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 . """ - return AsyncHTTPClient(timeout=30) + return httpx.AsyncClient(timeout=httpx.Timeout(timeout=timeout, connect=connect))