CodeWiki icon indicating copy to clipboard operation
CodeWiki copied to clipboard

ImportError: cannot import name 'OpenAIModel' from pydantic_ai.models.openai (broken by pydantic-ai 2.0.0)

Open jacob-rowdybraude opened this issue 4 months ago • 1 comments

Summary

codewiki generate crashes on import with a fresh install, because pydantic-ai 2.0.0 (released 2026-06-23) removed the deprecated OpenAIModel name in favor of OpenAIChatModel, and codewiki/src/be/llm_services.py still imports the old name. pyproject.toml pins pydantic-ai>=1.0.6 with no upper bound, so any fresh install now resolves pydantic-ai 2.x and breaks.

Traceback

Traceback (most recent call last):
  File ".../bin/codewiki", line 3, in <module>
    from codewiki.cli.main import cli
  File ".../codewiki/cli/main.py", line 35, in <module>
    from codewiki.cli.commands.generate import generate_command
  File ".../codewiki/cli/commands/generate.py", line 30, in <module>
    from codewiki.cli.adapters.doc_generator import CLIDocumentationGenerator
  File ".../codewiki/cli/adapters/doc_generator.py", line 22, in <module>
    from codewiki.src.be.documentation_generator import DocumentationGenerator
  File ".../codewiki/src/be/documentation_generator.py", line 18, in <module>
    from codewiki.src.be.cluster_modules import (
  File ".../codewiki/src/be/cluster_modules.py", line 8, in <module>
    from codewiki.src.be.llm_services import call_llm
  File ".../codewiki/src/be/llm_services.py", line 12, in <module>
    from pydantic_ai.models.openai import OpenAIModel
ImportError: cannot import name 'OpenAIModel' from 'pydantic_ai.models.openai' (.../site-packages/pydantic_ai/models/openai.py). Did you mean: 'OpenAIChatModel'?

Reproduction

pip install git+https://github.com/FSoft-AI4Code/CodeWiki.git
codewiki generate --main-model claude-haiku-4-5-20251001 --update --verbose

Any fresh install pulls in pydantic-ai 2.x since the dependency spec has no upper bound.

Root cause

  • pyproject.toml line 46: pydantic-ai>=1.0.6 (no upper bound)
  • codewiki/src/be/llm_services.py line 12: from pydantic_ai.models.openai import OpenAIModel
  • OpenAIModel was deprecated in pydantic-ai in favor of OpenAIChatModel around Aug 2025, and appears to have been removed entirely in pydantic-ai 2.0.0 (2026-06-23).

Suggested fix

Either:

  1. Update llm_services.py (and any other usages) to import OpenAIChatModel instead of OpenAIModel, or
  2. Cap the dependency, e.g. pydantic-ai>=1.0.6,<2.0.0, until the migration to the new name is done.

Happy to open a PR for option 1 if useful — flagging first since it's a hard crash on every fresh install right now.

jacob-rowdybraude avatar Jul 21 '26 16:07 jacob-rowdybraude

Thanks for the report. Confirmed and fixed at 311f017

anhnh2002 avatar Jul 22 '26 08:07 anhnh2002