fix: make CachingOpenAIModel._map_messages version-adaptive - #87
Open
LiberiFatali wants to merge 1 commit into
Open
fix: make CachingOpenAIModel._map_messages version-adaptive#87LiberiFatali wants to merge 1 commit into
LiberiFatali wants to merge 1 commit into
Conversation
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.
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the 4 failing tests in
tests/test_prompt_caching.pywith a minimal code-only change — no dependency changes.Root cause
CachingOpenAIModel._map_messages(codewiki/src/be/llm_services.py) unconditionally forwardedmodel_request_parametersandmodel_settingstosuper()._map_messages(...), but the pinnedpydantic-ai==1.0.6baseOpenAIChatModel._map_messagesaccepts onlymessages(the 3-argument signature only exists in>=1.107). Every call raised:Fix
_map_messagessignature and forward the matching argument set: 3 args on>=1.107, 1 arg on1.0.6.model_request_parameters=Noneso pydantic-ai 1.0.6's internal one-argumentself._map_messages(messages)call inside_completions_createalso works.Verification
pytest -p no:cacheprovider -o addopts="" tests/ -q→ 41 passed, 0 failed (was 4 failed / 37 passed).requirements.txtorpyproject.toml.