From 45c4cad7462c736596d8f57fee4202ddf148efd3 Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Mon, 25 Nov 2024 13:31:41 +0000 Subject: [PATCH 01/13] Try using uv workspaces --- pydantic_ai_examples/.ruff.toml | 2 - pydantic_ai_examples/pyproject.toml | 57 ++++++++ pydantic_ai_examples/{ => src}/__main__.py | 0 .../{ => src}/bank_support.py | 0 pydantic_ai_examples/{ => src}/chat_app.html | 0 pydantic_ai_examples/{ => src}/chat_app.py | 0 pydantic_ai_examples/{ => src}/chat_app.ts | 0 .../{ => src}/pydantic_model.py | 0 pydantic_ai_examples/{ => src}/rag.py | 0 .../{ => src}/roulette_wheel.py | 0 pydantic_ai_examples/{ => src}/sql_gen.py | 0 .../{ => src}/stream_markdown.py | 0 .../{ => src}/stream_whales.py | 0 .../{ => src}/weather_agent.py | 0 pydantic_ai_slim/README.md | 7 + .../pydantic_ai}/__init__.py | 0 .../pydantic_ai}/_griffe.py | 0 .../pydantic_ai}/_pydantic.py | 0 .../pydantic_ai}/_result.py | 0 .../pydantic_ai}/_retriever.py | 0 .../pydantic_ai}/_system_prompt.py | 0 .../pydantic_ai}/_utils.py | 0 .../pydantic_ai}/agent.py | 0 .../pydantic_ai}/dependencies.py | 0 .../pydantic_ai}/exceptions.py | 0 .../pydantic_ai}/messages.py | 0 .../pydantic_ai}/models/__init__.py | 0 .../pydantic_ai}/models/function.py | 0 .../pydantic_ai}/models/gemini.py | 0 .../pydantic_ai}/models/groq.py | 0 .../pydantic_ai}/models/openai.py | 0 .../pydantic_ai}/models/test.py | 0 .../pydantic_ai}/models/vertexai.py | 0 .../pydantic_ai}/py.typed | 0 .../pydantic_ai}/result.py | 0 pydantic_ai_slim/pyproject.toml | 51 +++++++ pyproject.toml | 36 ++--- tests/test_examples.py | 2 +- uv.lock | 126 +++++++++++------- 39 files changed, 210 insertions(+), 71 deletions(-) delete mode 100644 pydantic_ai_examples/.ruff.toml create mode 100644 pydantic_ai_examples/pyproject.toml rename pydantic_ai_examples/{ => src}/__main__.py (100%) rename pydantic_ai_examples/{ => src}/bank_support.py (100%) rename pydantic_ai_examples/{ => src}/chat_app.html (100%) rename pydantic_ai_examples/{ => src}/chat_app.py (100%) rename pydantic_ai_examples/{ => src}/chat_app.ts (100%) rename pydantic_ai_examples/{ => src}/pydantic_model.py (100%) rename pydantic_ai_examples/{ => src}/rag.py (100%) rename pydantic_ai_examples/{ => src}/roulette_wheel.py (100%) rename pydantic_ai_examples/{ => src}/sql_gen.py (100%) rename pydantic_ai_examples/{ => src}/stream_markdown.py (100%) rename pydantic_ai_examples/{ => src}/stream_whales.py (100%) rename pydantic_ai_examples/{ => src}/weather_agent.py (100%) create mode 100644 pydantic_ai_slim/README.md rename {pydantic_ai => pydantic_ai_slim/pydantic_ai}/__init__.py (100%) rename {pydantic_ai => pydantic_ai_slim/pydantic_ai}/_griffe.py (100%) rename {pydantic_ai => pydantic_ai_slim/pydantic_ai}/_pydantic.py (100%) rename {pydantic_ai => pydantic_ai_slim/pydantic_ai}/_result.py (100%) rename {pydantic_ai => pydantic_ai_slim/pydantic_ai}/_retriever.py (100%) rename {pydantic_ai => pydantic_ai_slim/pydantic_ai}/_system_prompt.py (100%) rename {pydantic_ai => pydantic_ai_slim/pydantic_ai}/_utils.py (100%) rename {pydantic_ai => pydantic_ai_slim/pydantic_ai}/agent.py (100%) rename {pydantic_ai => pydantic_ai_slim/pydantic_ai}/dependencies.py (100%) rename {pydantic_ai => pydantic_ai_slim/pydantic_ai}/exceptions.py (100%) rename {pydantic_ai => pydantic_ai_slim/pydantic_ai}/messages.py (100%) rename {pydantic_ai => pydantic_ai_slim/pydantic_ai}/models/__init__.py (100%) rename {pydantic_ai => pydantic_ai_slim/pydantic_ai}/models/function.py (100%) rename {pydantic_ai => pydantic_ai_slim/pydantic_ai}/models/gemini.py (100%) rename {pydantic_ai => pydantic_ai_slim/pydantic_ai}/models/groq.py (100%) rename {pydantic_ai => pydantic_ai_slim/pydantic_ai}/models/openai.py (100%) rename {pydantic_ai => pydantic_ai_slim/pydantic_ai}/models/test.py (100%) rename {pydantic_ai => pydantic_ai_slim/pydantic_ai}/models/vertexai.py (100%) rename {pydantic_ai => pydantic_ai_slim/pydantic_ai}/py.typed (100%) rename {pydantic_ai => pydantic_ai_slim/pydantic_ai}/result.py (100%) create mode 100644 pydantic_ai_slim/pyproject.toml diff --git a/pydantic_ai_examples/.ruff.toml b/pydantic_ai_examples/.ruff.toml deleted file mode 100644 index 483be1d9c0..0000000000 --- a/pydantic_ai_examples/.ruff.toml +++ /dev/null @@ -1,2 +0,0 @@ -extend = "../pyproject.toml" -line-length = 88 diff --git a/pydantic_ai_examples/pyproject.toml b/pydantic_ai_examples/pyproject.toml new file mode 100644 index 0000000000..9bb5156012 --- /dev/null +++ b/pydantic_ai_examples/pyproject.toml @@ -0,0 +1,57 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +name = "pydantic-ai-examples" +version = "0.0.5" +description = "Agent Framework / shim to use Pydantic with LLMs" +authors = [ + { name = "Samuel Colvin", email = "samuel@pydantic.dev" }, +] +license = "MIT" +readme = "README.md" +classifiers = [ + "Development Status :: 4 - Beta", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", + "Intended Audience :: Developers", + "Intended Audience :: Information Technology", + "Intended Audience :: System Administrators", + "License :: OSI Approved :: MIT License", + "Operating System :: Unix", + "Operating System :: POSIX :: Linux", + "Environment :: Console", + "Environment :: MacOS X", + "Topic :: Software Development :: Libraries :: Python Modules", + "Topic :: Internet", +] +requires-python = ">=3.9" +dependencies = [ + "pydantic-ai-slim[openai,vertexai,groq]", + "asyncpg>=0.30.0", + "fastapi>=0.115.4", + "logfire[asyncpg,fastapi]>=2.3", + "python-multipart>=0.0.17", + "rich>=13.9.2", + "uvicorn>=0.32.0", +] + +[tool.hatch.build] +sources = ["src"] + +[tool.hatch.build.targets.wheel] +packages = ["pydantic_ai_examples"] + +[tool.uv.sources] +pydantic-ai-slim = { workspace = true } + +[tool.ruff] +extend = "../pyproject.toml" +line-length = 88 diff --git a/pydantic_ai_examples/__main__.py b/pydantic_ai_examples/src/__main__.py similarity index 100% rename from pydantic_ai_examples/__main__.py rename to pydantic_ai_examples/src/__main__.py diff --git a/pydantic_ai_examples/bank_support.py b/pydantic_ai_examples/src/bank_support.py similarity index 100% rename from pydantic_ai_examples/bank_support.py rename to pydantic_ai_examples/src/bank_support.py diff --git a/pydantic_ai_examples/chat_app.html b/pydantic_ai_examples/src/chat_app.html similarity index 100% rename from pydantic_ai_examples/chat_app.html rename to pydantic_ai_examples/src/chat_app.html diff --git a/pydantic_ai_examples/chat_app.py b/pydantic_ai_examples/src/chat_app.py similarity index 100% rename from pydantic_ai_examples/chat_app.py rename to pydantic_ai_examples/src/chat_app.py diff --git a/pydantic_ai_examples/chat_app.ts b/pydantic_ai_examples/src/chat_app.ts similarity index 100% rename from pydantic_ai_examples/chat_app.ts rename to pydantic_ai_examples/src/chat_app.ts diff --git a/pydantic_ai_examples/pydantic_model.py b/pydantic_ai_examples/src/pydantic_model.py similarity index 100% rename from pydantic_ai_examples/pydantic_model.py rename to pydantic_ai_examples/src/pydantic_model.py diff --git a/pydantic_ai_examples/rag.py b/pydantic_ai_examples/src/rag.py similarity index 100% rename from pydantic_ai_examples/rag.py rename to pydantic_ai_examples/src/rag.py diff --git a/pydantic_ai_examples/roulette_wheel.py b/pydantic_ai_examples/src/roulette_wheel.py similarity index 100% rename from pydantic_ai_examples/roulette_wheel.py rename to pydantic_ai_examples/src/roulette_wheel.py diff --git a/pydantic_ai_examples/sql_gen.py b/pydantic_ai_examples/src/sql_gen.py similarity index 100% rename from pydantic_ai_examples/sql_gen.py rename to pydantic_ai_examples/src/sql_gen.py diff --git a/pydantic_ai_examples/stream_markdown.py b/pydantic_ai_examples/src/stream_markdown.py similarity index 100% rename from pydantic_ai_examples/stream_markdown.py rename to pydantic_ai_examples/src/stream_markdown.py diff --git a/pydantic_ai_examples/stream_whales.py b/pydantic_ai_examples/src/stream_whales.py similarity index 100% rename from pydantic_ai_examples/stream_whales.py rename to pydantic_ai_examples/src/stream_whales.py diff --git a/pydantic_ai_examples/weather_agent.py b/pydantic_ai_examples/src/weather_agent.py similarity index 100% rename from pydantic_ai_examples/weather_agent.py rename to pydantic_ai_examples/src/weather_agent.py diff --git a/pydantic_ai_slim/README.md b/pydantic_ai_slim/README.md new file mode 100644 index 0000000000..0ba1b619f2 --- /dev/null +++ b/pydantic_ai_slim/README.md @@ -0,0 +1,7 @@ +# Coming soon + +[![CI](https://github.com/pydantic/pydantic-ai/actions/workflows/ci.yml/badge.svg?event=push)](https://github.com/pydantic/pydantic-ai/actions/workflows/ci.yml?query=branch%3Amain) +[![Coverage](https://coverage-badge.samuelcolvin.workers.dev/pydantic/pydantic-ai.svg)](https://coverage-badge.samuelcolvin.workers.dev/redirect/pydantic/pydantic-ai) +[![PyPI](https://img.shields.io/pypi/v/pydantic-ai.svg)](https://pypi.python.org/pypi/pydantic-ai) +[![versions](https://img.shields.io/pypi/pyversions/pydantic-ai.svg)](https://github.com/pydantic/pydantic-ai) +[![license](https://img.shields.io/github/license/pydantic/pydantic-ai.svg?v)](https://github.com/pydantic/pydantic-ai/blob/main/LICENSE) diff --git a/pydantic_ai/__init__.py b/pydantic_ai_slim/pydantic_ai/__init__.py similarity index 100% rename from pydantic_ai/__init__.py rename to pydantic_ai_slim/pydantic_ai/__init__.py diff --git a/pydantic_ai/_griffe.py b/pydantic_ai_slim/pydantic_ai/_griffe.py similarity index 100% rename from pydantic_ai/_griffe.py rename to pydantic_ai_slim/pydantic_ai/_griffe.py diff --git a/pydantic_ai/_pydantic.py b/pydantic_ai_slim/pydantic_ai/_pydantic.py similarity index 100% rename from pydantic_ai/_pydantic.py rename to pydantic_ai_slim/pydantic_ai/_pydantic.py diff --git a/pydantic_ai/_result.py b/pydantic_ai_slim/pydantic_ai/_result.py similarity index 100% rename from pydantic_ai/_result.py rename to pydantic_ai_slim/pydantic_ai/_result.py diff --git a/pydantic_ai/_retriever.py b/pydantic_ai_slim/pydantic_ai/_retriever.py similarity index 100% rename from pydantic_ai/_retriever.py rename to pydantic_ai_slim/pydantic_ai/_retriever.py diff --git a/pydantic_ai/_system_prompt.py b/pydantic_ai_slim/pydantic_ai/_system_prompt.py similarity index 100% rename from pydantic_ai/_system_prompt.py rename to pydantic_ai_slim/pydantic_ai/_system_prompt.py diff --git a/pydantic_ai/_utils.py b/pydantic_ai_slim/pydantic_ai/_utils.py similarity index 100% rename from pydantic_ai/_utils.py rename to pydantic_ai_slim/pydantic_ai/_utils.py diff --git a/pydantic_ai/agent.py b/pydantic_ai_slim/pydantic_ai/agent.py similarity index 100% rename from pydantic_ai/agent.py rename to pydantic_ai_slim/pydantic_ai/agent.py diff --git a/pydantic_ai/dependencies.py b/pydantic_ai_slim/pydantic_ai/dependencies.py similarity index 100% rename from pydantic_ai/dependencies.py rename to pydantic_ai_slim/pydantic_ai/dependencies.py diff --git a/pydantic_ai/exceptions.py b/pydantic_ai_slim/pydantic_ai/exceptions.py similarity index 100% rename from pydantic_ai/exceptions.py rename to pydantic_ai_slim/pydantic_ai/exceptions.py diff --git a/pydantic_ai/messages.py b/pydantic_ai_slim/pydantic_ai/messages.py similarity index 100% rename from pydantic_ai/messages.py rename to pydantic_ai_slim/pydantic_ai/messages.py diff --git a/pydantic_ai/models/__init__.py b/pydantic_ai_slim/pydantic_ai/models/__init__.py similarity index 100% rename from pydantic_ai/models/__init__.py rename to pydantic_ai_slim/pydantic_ai/models/__init__.py diff --git a/pydantic_ai/models/function.py b/pydantic_ai_slim/pydantic_ai/models/function.py similarity index 100% rename from pydantic_ai/models/function.py rename to pydantic_ai_slim/pydantic_ai/models/function.py diff --git a/pydantic_ai/models/gemini.py b/pydantic_ai_slim/pydantic_ai/models/gemini.py similarity index 100% rename from pydantic_ai/models/gemini.py rename to pydantic_ai_slim/pydantic_ai/models/gemini.py diff --git a/pydantic_ai/models/groq.py b/pydantic_ai_slim/pydantic_ai/models/groq.py similarity index 100% rename from pydantic_ai/models/groq.py rename to pydantic_ai_slim/pydantic_ai/models/groq.py diff --git a/pydantic_ai/models/openai.py b/pydantic_ai_slim/pydantic_ai/models/openai.py similarity index 100% rename from pydantic_ai/models/openai.py rename to pydantic_ai_slim/pydantic_ai/models/openai.py diff --git a/pydantic_ai/models/test.py b/pydantic_ai_slim/pydantic_ai/models/test.py similarity index 100% rename from pydantic_ai/models/test.py rename to pydantic_ai_slim/pydantic_ai/models/test.py diff --git a/pydantic_ai/models/vertexai.py b/pydantic_ai_slim/pydantic_ai/models/vertexai.py similarity index 100% rename from pydantic_ai/models/vertexai.py rename to pydantic_ai_slim/pydantic_ai/models/vertexai.py diff --git a/pydantic_ai/py.typed b/pydantic_ai_slim/pydantic_ai/py.typed similarity index 100% rename from pydantic_ai/py.typed rename to pydantic_ai_slim/pydantic_ai/py.typed diff --git a/pydantic_ai/result.py b/pydantic_ai_slim/pydantic_ai/result.py similarity index 100% rename from pydantic_ai/result.py rename to pydantic_ai_slim/pydantic_ai/result.py diff --git a/pydantic_ai_slim/pyproject.toml b/pydantic_ai_slim/pyproject.toml new file mode 100644 index 0000000000..476e614910 --- /dev/null +++ b/pydantic_ai_slim/pyproject.toml @@ -0,0 +1,51 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +name = "pydantic-ai-slim" +version = "0.0.5" +description = "Agent Framework / shim to use Pydantic with LLMs" +authors = [ + { name = "Samuel Colvin", email = "samuel@pydantic.dev" }, +] +license = "MIT" +readme = "README.md" +classifiers = [ + "Development Status :: 4 - Beta", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", + "Intended Audience :: Developers", + "Intended Audience :: Information Technology", + "Intended Audience :: System Administrators", + "License :: OSI Approved :: MIT License", + "Operating System :: Unix", + "Operating System :: POSIX :: Linux", + "Environment :: Console", + "Environment :: MacOS X", + "Topic :: Software Development :: Libraries :: Python Modules", + "Topic :: Internet", +] +requires-python = ">=3.9" +dependencies = [ + "eval-type-backport>=0.2.0", + "griffe>=1.3.2", + "httpx>=0.27.2", + "logfire-api>=1.2.0", + "pydantic>=2.10", +] + +[project.optional-dependencies] +openai = ["openai>=1.54.3"] +vertexai = ["google-auth>=2.36.0", "requests>=2.32.3"] +groq = ["groq>=0.12.0"] +logfire = ["logfire>=2.3"] + +[tool.hatch.build.targets.wheel] +packages = ["pydantic_ai"] diff --git a/pyproject.toml b/pyproject.toml index 7b3611d716..ed92be9633 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,27 +34,19 @@ classifiers = [ ] requires-python = ">=3.9" dependencies = [ - "eval-type-backport>=0.2.0", - "griffe>=1.3.2", - "httpx>=0.27.2", - "logfire-api>=1.2.0", - "pydantic>=2.10", + "pydantic-ai-slim[openai,vertexai,groq]", + "pydantic-ai-examples", ] [project.optional-dependencies] openai = ["openai>=1.54.3"] -vertexai = ["google-auth>=2.36.0", "requests>=2.32.3"] -groq = ["groq>=0.12.0"] -logfire = ["logfire>=2.3"] -examples = [ - "asyncpg>=0.30.0", - "fastapi>=0.115.4", - "logfire[asyncpg,fastapi]>=2.3", - "python-multipart>=0.0.17", - "rich>=13.9.2", - "uvicorn>=0.32.0", - "pydantic-ai[openai,vertexai,groq]", -] + +[tool.uv.sources] +pydantic-ai-slim = { workspace = true } +pydantic-ai-examples = { workspace = true } + +[tool.uv.workspace] +members = ["pydantic_ai_slim", "pydantic_ai_examples"] [dependency-groups] dev = [ @@ -74,17 +66,17 @@ lint = [ "ruff>=0.6.9", ] docs = [ - "mkdocs", + "mkdocs>=1.6.1", "mkdocs-glightbox>=0.4.0", - "mkdocs-material[imaging]", - "mkdocstrings-python", + "mkdocs-material[imaging]>=9.5.45", + "mkdocstrings-python>=1.12.2", ] [tool.hatch.build.targets.wheel] -packages = ["pydantic_ai", "pydantic_ai_examples"] +packages = [] [tool.hatch.build.targets.sdist] -include = ["/README.md", "/Makefile", "/pydantic_ai", "/pydantic_ai_examples", "/tests"] +include = ["/README.md", "/Makefile", "/tests"] [tool.ruff] line-length = 120 diff --git a/tests/test_examples.py b/tests/test_examples.py index ddea816ae5..7773be4ebc 100644 --- a/tests/test_examples.py +++ b/tests/test_examples.py @@ -88,7 +88,7 @@ async def customer_balance(cls, *, id: int, include_pending: bool) -> float: def find_filter_examples() -> Iterable[CodeExample]: - for ex in find_examples('docs', 'pydantic_ai'): + for ex in find_examples('docs', 'pydantic_ai_slim'): if ex.path.name != '_utils.py': yield ex diff --git a/uv.lock b/uv.lock index 666b6851a7..e887f77149 100644 --- a/uv.lock +++ b/uv.lock @@ -6,6 +6,13 @@ resolution-markers = [ "python_full_version >= '3.13'", ] +[manifest] +members = [ + "pydantic-ai", + "pydantic-ai-examples", + "pydantic-ai-slim", +] + [[package]] name = "annotated-types" version = "0.7.0" @@ -1491,39 +1498,14 @@ name = "pydantic-ai" version = "0.0.5" source = { editable = "." } dependencies = [ - { name = "eval-type-backport" }, - { name = "griffe" }, - { name = "httpx" }, - { name = "logfire-api" }, - { name = "pydantic" }, + { name = "pydantic-ai-examples" }, + { name = "pydantic-ai-slim", extra = ["groq", "openai", "vertexai"] }, ] [package.optional-dependencies] -examples = [ - { name = "asyncpg" }, - { name = "fastapi" }, - { name = "google-auth" }, - { name = "groq" }, - { name = "logfire", extra = ["asyncpg", "fastapi"] }, - { name = "openai" }, - { name = "python-multipart" }, - { name = "requests" }, - { name = "rich" }, - { name = "uvicorn" }, -] -groq = [ - { name = "groq" }, -] -logfire = [ - { name = "logfire" }, -] openai = [ { name = "openai" }, ] -vertexai = [ - { name = "google-auth" }, - { name = "requests" }, -] [package.dev-dependencies] dev = [ @@ -1551,23 +1533,9 @@ lint = [ [package.metadata] requires-dist = [ - { name = "asyncpg", marker = "extra == 'examples'", specifier = ">=0.30.0" }, - { name = "eval-type-backport", specifier = ">=0.2.0" }, - { name = "fastapi", marker = "extra == 'examples'", specifier = ">=0.115.4" }, - { name = "google-auth", marker = "extra == 'vertexai'", specifier = ">=2.36.0" }, - { name = "griffe", specifier = ">=1.3.2" }, - { name = "groq", marker = "extra == 'groq'", specifier = ">=0.12.0" }, - { name = "httpx", specifier = ">=0.27.2" }, - { name = "logfire", marker = "extra == 'logfire'", specifier = ">=2.3" }, - { name = "logfire", extras = ["asyncpg", "fastapi"], marker = "extra == 'examples'", specifier = ">=2.3" }, - { name = "logfire-api", specifier = ">=1.2.0" }, { name = "openai", marker = "extra == 'openai'", specifier = ">=1.54.3" }, - { name = "pydantic", specifier = ">=2.10" }, - { name = "pydantic-ai", extras = ["openai", "vertexai", "groq"], marker = "extra == 'examples'" }, - { name = "python-multipart", marker = "extra == 'examples'", specifier = ">=0.0.17" }, - { name = "requests", marker = "extra == 'vertexai'", specifier = ">=2.32.3" }, - { name = "rich", marker = "extra == 'examples'", specifier = ">=13.9.2" }, - { name = "uvicorn", marker = "extra == 'examples'", specifier = ">=0.32.0" }, + { name = "pydantic-ai-examples", editable = "pydantic_ai_examples" }, + { name = "pydantic-ai-slim", extras = ["openai", "vertexai", "groq"], editable = "pydantic_ai_slim" }, ] [package.metadata.requires-dev] @@ -1583,10 +1551,10 @@ dev = [ { name = "pytest-pretty", specifier = ">=1.2.0" }, ] docs = [ - { name = "mkdocs" }, + { name = "mkdocs", specifier = ">=1.6.1" }, { name = "mkdocs-glightbox", specifier = ">=0.4.0" }, - { name = "mkdocs-material", extras = ["imaging"] }, - { name = "mkdocstrings-python" }, + { name = "mkdocs-material", extras = ["imaging"], specifier = ">=9.5.45" }, + { name = "mkdocstrings-python", specifier = ">=1.12.2" }, ] lint = [ { name = "mypy", specifier = ">=1.11.2" }, @@ -1594,6 +1562,72 @@ lint = [ { name = "ruff", specifier = ">=0.6.9" }, ] +[[package]] +name = "pydantic-ai-examples" +version = "0.0.5" +source = { editable = "pydantic_ai_examples" } +dependencies = [ + { name = "asyncpg" }, + { name = "fastapi" }, + { name = "logfire", extra = ["asyncpg", "fastapi"] }, + { name = "pydantic-ai-slim", extra = ["groq", "openai", "vertexai"] }, + { name = "python-multipart" }, + { name = "rich" }, + { name = "uvicorn" }, +] + +[package.metadata] +requires-dist = [ + { name = "asyncpg", specifier = ">=0.30.0" }, + { name = "fastapi", specifier = ">=0.115.4" }, + { name = "logfire", extras = ["asyncpg", "fastapi"], specifier = ">=2.3" }, + { name = "pydantic-ai-slim", extras = ["openai", "vertexai", "groq"], editable = "pydantic_ai_slim" }, + { name = "python-multipart", specifier = ">=0.0.17" }, + { name = "rich", specifier = ">=13.9.2" }, + { name = "uvicorn", specifier = ">=0.32.0" }, +] + +[[package]] +name = "pydantic-ai-slim" +version = "0.0.5" +source = { editable = "pydantic_ai_slim" } +dependencies = [ + { name = "eval-type-backport" }, + { name = "griffe" }, + { name = "httpx" }, + { name = "logfire-api" }, + { name = "pydantic" }, +] + +[package.optional-dependencies] +groq = [ + { name = "groq" }, +] +logfire = [ + { name = "logfire" }, +] +openai = [ + { name = "openai" }, +] +vertexai = [ + { name = "google-auth" }, + { name = "requests" }, +] + +[package.metadata] +requires-dist = [ + { name = "eval-type-backport", specifier = ">=0.2.0" }, + { name = "google-auth", marker = "extra == 'vertexai'", specifier = ">=2.36.0" }, + { name = "griffe", specifier = ">=1.3.2" }, + { name = "groq", marker = "extra == 'groq'", specifier = ">=0.12.0" }, + { name = "httpx", specifier = ">=0.27.2" }, + { name = "logfire", marker = "extra == 'logfire'", specifier = ">=2.3" }, + { name = "logfire-api", specifier = ">=1.2.0" }, + { name = "openai", marker = "extra == 'openai'", specifier = ">=1.54.3" }, + { name = "pydantic", specifier = ">=2.10" }, + { name = "requests", marker = "extra == 'vertexai'", specifier = ">=2.32.3" }, +] + [[package]] name = "pydantic-core" version = "2.27.1" From a66f3f739ada7f7aa762f3e8686ee30ca5e89f8c Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Mon, 25 Nov 2024 15:38:25 +0000 Subject: [PATCH 02/13] organizing examples... --- .github/workflows/ci.yml | 2 +- pydantic_ai_examples/{src => }/__main__.py | 0 pydantic_ai_examples/{src => }/bank_support.py | 0 pydantic_ai_examples/{src => }/chat_app.html | 0 pydantic_ai_examples/{src => }/chat_app.py | 0 pydantic_ai_examples/{src => }/chat_app.ts | 0 pydantic_ai_examples/{src => }/pydantic_model.py | 0 pydantic_ai_examples/pyproject.toml | 5 ++++- pydantic_ai_examples/{src => }/rag.py | 0 pydantic_ai_examples/{src => }/roulette_wheel.py | 0 pydantic_ai_examples/{src => }/sql_gen.py | 0 pydantic_ai_examples/{src => }/stream_markdown.py | 0 pydantic_ai_examples/{src => }/stream_whales.py | 0 pydantic_ai_examples/{src => }/weather_agent.py | 0 pyproject.toml | 2 +- 15 files changed, 6 insertions(+), 3 deletions(-) rename pydantic_ai_examples/{src => }/__main__.py (100%) rename pydantic_ai_examples/{src => }/bank_support.py (100%) rename pydantic_ai_examples/{src => }/chat_app.html (100%) rename pydantic_ai_examples/{src => }/chat_app.py (100%) rename pydantic_ai_examples/{src => }/chat_app.ts (100%) rename pydantic_ai_examples/{src => }/pydantic_model.py (100%) rename pydantic_ai_examples/{src => }/rag.py (100%) rename pydantic_ai_examples/{src => }/roulette_wheel.py (100%) rename pydantic_ai_examples/{src => }/sql_gen.py (100%) rename pydantic_ai_examples/{src => }/stream_markdown.py (100%) rename pydantic_ai_examples/{src => }/stream_whales.py (100%) rename pydantic_ai_examples/{src => }/weather_agent.py (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b7335c46da..190ed8825f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -193,7 +193,7 @@ jobs: with: version_file_path: pyproject.toml - - run: uv build + - run: uv build --all-packages - name: Publish to PyPI uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/pydantic_ai_examples/src/__main__.py b/pydantic_ai_examples/__main__.py similarity index 100% rename from pydantic_ai_examples/src/__main__.py rename to pydantic_ai_examples/__main__.py diff --git a/pydantic_ai_examples/src/bank_support.py b/pydantic_ai_examples/bank_support.py similarity index 100% rename from pydantic_ai_examples/src/bank_support.py rename to pydantic_ai_examples/bank_support.py diff --git a/pydantic_ai_examples/src/chat_app.html b/pydantic_ai_examples/chat_app.html similarity index 100% rename from pydantic_ai_examples/src/chat_app.html rename to pydantic_ai_examples/chat_app.html diff --git a/pydantic_ai_examples/src/chat_app.py b/pydantic_ai_examples/chat_app.py similarity index 100% rename from pydantic_ai_examples/src/chat_app.py rename to pydantic_ai_examples/chat_app.py diff --git a/pydantic_ai_examples/src/chat_app.ts b/pydantic_ai_examples/chat_app.ts similarity index 100% rename from pydantic_ai_examples/src/chat_app.ts rename to pydantic_ai_examples/chat_app.ts diff --git a/pydantic_ai_examples/src/pydantic_model.py b/pydantic_ai_examples/pydantic_model.py similarity index 100% rename from pydantic_ai_examples/src/pydantic_model.py rename to pydantic_ai_examples/pydantic_model.py diff --git a/pydantic_ai_examples/pyproject.toml b/pydantic_ai_examples/pyproject.toml index 9bb5156012..232e3e9362 100644 --- a/pydantic_ai_examples/pyproject.toml +++ b/pydantic_ai_examples/pyproject.toml @@ -44,11 +44,14 @@ dependencies = [ ] [tool.hatch.build] -sources = ["src"] +sources = ["."] [tool.hatch.build.targets.wheel] packages = ["pydantic_ai_examples"] +[tool.hatch.build.targets.wheel.sources] +"" = "pydantic_ai_examples" + [tool.uv.sources] pydantic-ai-slim = { workspace = true } diff --git a/pydantic_ai_examples/src/rag.py b/pydantic_ai_examples/rag.py similarity index 100% rename from pydantic_ai_examples/src/rag.py rename to pydantic_ai_examples/rag.py diff --git a/pydantic_ai_examples/src/roulette_wheel.py b/pydantic_ai_examples/roulette_wheel.py similarity index 100% rename from pydantic_ai_examples/src/roulette_wheel.py rename to pydantic_ai_examples/roulette_wheel.py diff --git a/pydantic_ai_examples/src/sql_gen.py b/pydantic_ai_examples/sql_gen.py similarity index 100% rename from pydantic_ai_examples/src/sql_gen.py rename to pydantic_ai_examples/sql_gen.py diff --git a/pydantic_ai_examples/src/stream_markdown.py b/pydantic_ai_examples/stream_markdown.py similarity index 100% rename from pydantic_ai_examples/src/stream_markdown.py rename to pydantic_ai_examples/stream_markdown.py diff --git a/pydantic_ai_examples/src/stream_whales.py b/pydantic_ai_examples/stream_whales.py similarity index 100% rename from pydantic_ai_examples/src/stream_whales.py rename to pydantic_ai_examples/stream_whales.py diff --git a/pydantic_ai_examples/src/weather_agent.py b/pydantic_ai_examples/weather_agent.py similarity index 100% rename from pydantic_ai_examples/src/weather_agent.py rename to pydantic_ai_examples/weather_agent.py diff --git a/pyproject.toml b/pyproject.toml index ed92be9633..3779e1d211 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -73,7 +73,7 @@ docs = [ ] [tool.hatch.build.targets.wheel] -packages = [] +only-include = ["/README.md"] [tool.hatch.build.targets.sdist] include = ["/README.md", "/Makefile", "/tests"] From f33cb3b726db2539927a9723d0172afef6d6dc71 Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Mon, 25 Nov 2024 15:57:41 +0000 Subject: [PATCH 03/13] tweaking files included in examples --- pydantic_ai_examples/pyproject.toml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pydantic_ai_examples/pyproject.toml b/pydantic_ai_examples/pyproject.toml index 232e3e9362..c021d97416 100644 --- a/pydantic_ai_examples/pyproject.toml +++ b/pydantic_ai_examples/pyproject.toml @@ -44,10 +44,7 @@ dependencies = [ ] [tool.hatch.build] -sources = ["."] - -[tool.hatch.build.targets.wheel] -packages = ["pydantic_ai_examples"] +include = ["*.py", "*.html", "*.ts"] [tool.hatch.build.targets.wheel.sources] "" = "pydantic_ai_examples" From 16e25e3e5036bd303e97e5d202d53a0c082911da Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Mon, 25 Nov 2024 16:17:37 +0000 Subject: [PATCH 04/13] fix linting of tests --- pyproject.toml | 8 ++++---- tests/__init__.py | 0 tests/models/test_gemini.py | 3 ++- tests/models/test_groq.py | 3 ++- tests/models/test_model.py | 3 ++- tests/models/test_model_function.py | 3 ++- tests/models/test_model_test.py | 3 ++- tests/models/test_openai.py | 3 ++- tests/models/test_vertexai.py | 3 ++- tests/test_agent.py | 3 ++- tests/test_examples.py | 3 ++- tests/test_streaming.py | 3 ++- 12 files changed, 24 insertions(+), 14 deletions(-) create mode 100644 tests/__init__.py diff --git a/pyproject.toml b/pyproject.toml index 3779e1d211..4f490a49f1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -82,10 +82,10 @@ include = ["/README.md", "/Makefile", "/tests"] line-length = 120 target-version = "py39" include = [ - "pydantic_ai/**/*.py", + "pydantic_ai_slim/**/*.py", + "pydantic_ai_examples/**/*.py", "tests/**/*.py", "docs/**/*.py", - "pydantic_ai_examples/**/*.py", ] [tool.ruff.lint] @@ -126,7 +126,7 @@ quote-style = "single" typeCheckingMode = "strict" reportUnnecessaryTypeIgnoreComment = true reportMissingTypeStubs = false -include = ["pydantic_ai", "tests", "pydantic_ai_examples"] +include = ["pydantic_ai_slim", "tests", "pydantic_ai_examples"] venvPath = ".venv" # see https://github.com/microsoft/pyright/issues/7771 - we don't want to error on decorated functions in tests # which are not otherwise used @@ -144,7 +144,7 @@ filterwarnings = [ # https://coverage.readthedocs.io/en/latest/config.html#run [tool.coverage.run] # required to avoid warnings about files created by create_module fixture -include = ["pydantic_ai/**/*.py", "tests/**/*.py"] +include = ["pydantic_ai_slim/**/*.py", "tests/**/*.py"] omit = ["tests/test_live.py"] branch = true diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/models/test_gemini.py b/tests/models/test_gemini.py index e61bf8acc7..7ec2d0d3ff 100644 --- a/tests/models/test_gemini.py +++ b/tests/models/test_gemini.py @@ -42,7 +42,8 @@ _GeminiUsageMetaData, ) from pydantic_ai.result import Cost -from tests.conftest import ClientWithHandler, IsNow, TestEnv + +from ..conftest import ClientWithHandler, IsNow, TestEnv pytestmark = pytest.mark.anyio diff --git a/tests/models/test_groq.py b/tests/models/test_groq.py index f439c3751d..18c6efaa3f 100644 --- a/tests/models/test_groq.py +++ b/tests/models/test_groq.py @@ -23,7 +23,8 @@ UserPrompt, ) from pydantic_ai.result import Cost -from tests.conftest import IsNow, try_import + +from ..conftest import IsNow, try_import with try_import() as imports_successful: from groq import AsyncGroq diff --git a/tests/models/test_model.py b/tests/models/test_model.py index 5dc98412a6..1695fc7e63 100644 --- a/tests/models/test_model.py +++ b/tests/models/test_model.py @@ -3,7 +3,8 @@ from pydantic_ai import UserError from pydantic_ai.models import infer_model from pydantic_ai.models.gemini import GeminiModel -from tests.conftest import TestEnv, try_import + +from ..conftest import TestEnv, try_import with try_import() as openai_imports_successful: from pydantic_ai.models.openai import OpenAIModel diff --git a/tests/models/test_model_function.py b/tests/models/test_model_function.py index 5d9b59a0b5..e88a44dfd0 100644 --- a/tests/models/test_model_function.py +++ b/tests/models/test_model_function.py @@ -24,7 +24,8 @@ from pydantic_ai.models.function import AgentInfo, DeltaToolCall, DeltaToolCalls, FunctionModel from pydantic_ai.models.test import TestModel from pydantic_ai.result import Cost -from tests.conftest import IsNow + +from ..conftest import IsNow pytestmark = pytest.mark.anyio diff --git a/tests/models/test_model_test.py b/tests/models/test_model_test.py index e41d47d3f7..331fb3ee38 100644 --- a/tests/models/test_model_test.py +++ b/tests/models/test_model_test.py @@ -20,7 +20,8 @@ UserPrompt, ) from pydantic_ai.models.test import TestModel, _chars, _JsonSchemaTestData # pyright: ignore[reportPrivateUsage] -from tests.conftest import IsNow + +from ..conftest import IsNow def test_call_one(): diff --git a/tests/models/test_openai.py b/tests/models/test_openai.py index f36716fc42..52b90a29e9 100644 --- a/tests/models/test_openai.py +++ b/tests/models/test_openai.py @@ -23,7 +23,8 @@ UserPrompt, ) from pydantic_ai.result import Cost -from tests.conftest import IsNow, try_import + +from ..conftest import IsNow, try_import with try_import() as imports_successful: from openai import AsyncOpenAI diff --git a/tests/models/test_vertexai.py b/tests/models/test_vertexai.py index 2cafdbe781..ff509867b0 100644 --- a/tests/models/test_vertexai.py +++ b/tests/models/test_vertexai.py @@ -10,7 +10,8 @@ from pytest_mock import MockerFixture from pydantic_ai import UserError -from tests.conftest import IsNow, try_import + +from ..conftest import IsNow, try_import with try_import() as imports_successful: from google.oauth2.service_account import Credentials diff --git a/tests/test_agent.py b/tests/test_agent.py index 03ed140d1a..2687148ac4 100644 --- a/tests/test_agent.py +++ b/tests/test_agent.py @@ -23,7 +23,8 @@ from pydantic_ai.models.function import AgentInfo, FunctionModel from pydantic_ai.models.test import TestModel from pydantic_ai.result import Cost, RunResult -from tests.conftest import IsNow, TestEnv + +from .conftest import IsNow, TestEnv def test_result_tuple(): diff --git a/tests/test_examples.py b/tests/test_examples.py index 7773be4ebc..43b388d856 100644 --- a/tests/test_examples.py +++ b/tests/test_examples.py @@ -26,7 +26,8 @@ from pydantic_ai.models import KnownModelName, Model from pydantic_ai.models.function import AgentInfo, DeltaToolCall, DeltaToolCalls, FunctionModel from pydantic_ai.models.test import TestModel -from tests.conftest import ClientWithHandler + +from .conftest import ClientWithHandler try: from pydantic_ai.models.vertexai import VertexAIModel diff --git a/tests/test_streaming.py b/tests/test_streaming.py index a269f850b1..a0b9d94381 100644 --- a/tests/test_streaming.py +++ b/tests/test_streaming.py @@ -22,7 +22,8 @@ from pydantic_ai.models.function import AgentInfo, DeltaToolCall, DeltaToolCalls, FunctionModel from pydantic_ai.models.test import TestModel from pydantic_ai.result import Cost -from tests.conftest import IsNow + +from .conftest import IsNow pytestmark = pytest.mark.anyio From 6b725fdc733ee6d5b1226537493825c2768950c9 Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Mon, 25 Nov 2024 16:25:57 +0000 Subject: [PATCH 05/13] fix docs, build in lint ci step --- .github/workflows/ci.yml | 3 +++ docs/.hooks/main.py | 1 - mkdocs.yml | 7 +++---- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 190ed8825f..6789cff8ee 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,6 +34,9 @@ jobs: env: SKIP: no-commit-to-branch + - run: uv build --all-packages + - run: ls -lh dist/ + # mypy and lint are a bit slower than other jobs, so we run them separately mypy: runs-on: ubuntu-latest diff --git a/docs/.hooks/main.py b/docs/.hooks/main.py index 15ca77009f..53aab4c90c 100644 --- a/docs/.hooks/main.py +++ b/docs/.hooks/main.py @@ -67,7 +67,6 @@ def sub_cf_video(m: re.Match[str]) -> str: domain = 'https://customer-nmegqx24430okhaq.cloudflarestream.com' poster = f'{domain}/{video_id}/thumbnails/thumbnail.jpg?time={time}&height=600' - print(poster) return f"""