Skip to content

fix: pin pydantic-ai to <2 so the package imports on a fresh install#2

Open
OfficialAbhinavSingh wants to merge 1 commit into
ML4SCI:mainfrom
OfficialAbhinavSingh:fix/pin-pydantic-ai-v1
Open

fix: pin pydantic-ai to <2 so the package imports on a fresh install#2
OfficialAbhinavSingh wants to merge 1 commit into
ML4SCI:mainfrom
OfficialAbhinavSingh:fix/pin-pydantic-ai-v1

Conversation

@OfficialAbhinavSingh

Copy link
Copy Markdown

Problem

On a fresh clone, uv sync + uv run pytest fails at collection:

ImportError: cannot import name 'OpenAIModel' from 'pydantic_ai.models.openai'
  src/dlens/__init__.py -> .agents -> ._models
  src/dlens/agents/_models.py:2: from pydantic_ai.models.openai import OpenAIModel

Root cause: pyproject.toml pins pydantic-ai>=1.48.0 with no upper bound, so uv resolves pydantic-ai 2.x (currently 2.12.0). In the 2.x line, OpenAIModel was removed from pydantic_ai.models.openai (split into OpenAIChatModel / OpenAIResponsesModel). The import dlens chain hits _models.py:2 and the whole package — and therefore the smoke test and every script — fails to import.

Reproduce

git clone https://github.com/ML4SCI/DeepLense-AI-Scientist.git
cd DeepLense-AI-Scientist
uv sync
uv run pytest        # ImportError at collection

Fix

Pin to the 1.x line the current code targets (the OpenAIModel wrapper at _models.py:12 and the import at :2 use the 1.x API):

-    "pydantic-ai>=1.48.0",
+    "pydantic-ai>=1.48.0,<2",

Verification

After the pin, a fresh uv sync resolves pydantic-ai 1.107.1 and:

$ uv run pytest tests/
tests/test_smoke.py::test_ping PASSED                              [100%]
1 passed
$ uv run python -c "import dlens; from dlens.agents import OllamaModel, DLensBaseAgent; print('import ok')"
import ok

Note

Migrating to pydantic-ai 2.x (OpenAIChatModel / OpenAIResponsesModel, updating the OpenAIModel wrapper) is a larger, separate change — deliberately left out here to keep this a minimal "repo builds on a fresh clone again" fix. Happy to follow up with the 2.x migration if that's the preferred direction.

An unbounded `pydantic-ai>=1.48.0` resolves to pydantic-ai 2.x, which
removed `OpenAIModel` from `pydantic_ai.models.openai`. That breaks
`import dlens` at `src/dlens/agents/_models.py:2`, so a fresh
`uv sync` + `uv run pytest` fails at collection on the smoke test.

Pin to the 1.x line the current code targets (the `OpenAIModel` wrapper
and imports use the 1.x API). Verified: fresh `uv sync` then
`uv run pytest` passes (test_ping) with pydantic-ai 1.107.1.

Migrating to pydantic-ai 2.x (OpenAIChatModel/OpenAIResponsesModel) is a
larger follow-up and left out of this minimal fix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant