Skip to content

fix: make CachingOpenAIModel._map_messages version-adaptive - #87

Open
LiberiFatali wants to merge 1 commit into
FSoft-AI4Code:mainfrom
LiberiFatali:fix/pydantic-ai-pin
Open

fix: make CachingOpenAIModel._map_messages version-adaptive#87
LiberiFatali wants to merge 1 commit into
FSoft-AI4Code:mainfrom
LiberiFatali:fix/pydantic-ai-pin

Conversation

@LiberiFatali

Copy link
Copy Markdown
Contributor

Fixes the 4 failing tests in tests/test_prompt_caching.py with a minimal code-only change — no dependency changes.

Root cause

CachingOpenAIModel._map_messages (codewiki/src/be/llm_services.py) unconditionally forwarded model_request_parameters and model_settings to super()._map_messages(...), but the pinned pydantic-ai==1.0.6 base OpenAIChatModel._map_messages accepts only messages (the 3-argument signature only exists in >=1.107). Every call raised:

TypeError: OpenAIChatModel._map_messages() got an unexpected keyword argument 'model_settings'

Fix

  • Inspect the base _map_messages signature and forward the matching argument set: 3 args on >=1.107, 1 arg on 1.0.6.
  • Default model_request_parameters=None so pydantic-ai 1.0.6's internal one-argument self._map_messages(messages) call inside _completions_create also works.

Verification

  • pytest -p no:cacheprovider -o addopts="" tests/ -q41 passed, 0 failed (was 4 failed / 37 passed).
  • No changes to requirements.txt or pyproject.toml.

pydantic-ai 1.0.6 (the pinned version) has OpenAIChatModel._map_messages
accepting only messages, while >=1.107 added model_request_parameters and
model_settings. The override forwarded the newer arguments unconditionally,
so every _map_messages call raised
'TypeError: _map_messages() got an unexpected keyword argument
'model_settings''. Inspect the base signature and forward the matching
argument set, and default model_request_parameters to None so pydantic-ai
1.0.6's internal one-argument call also works.
@LiberiFatali

Copy link
Copy Markdown
Contributor Author

@anhnh2002 After this is merged, I will create a PR for adding GitHub Actions to run tests and code linting automatically on future PRs.

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