fix: accept mapping venice_parameters in chat.completions type hints (#58) - #59
Merged
Merged
Conversation
…58) Both `create()` overloads annotated `venice_parameters: VeniceParameters | None`, narrower than what the code accepts. A mapping of the same fields has always been validated and coerced by `ChatCompletionRequest`, but type checkers rejected the call — and since `create()` is overloaded, the diagnostic reported the whole call as unmatched without naming the offending argument. Widened to `VeniceParameters | Mapping[str, Any] | None`. `ChatCompletionRequest.venice_parameters` stays model-only: it is the validation boundary where mappings are coerced. Annotation-only. Unlike `messages=`, nothing reads `venice_parameters` attributes before the request model — it is popped from kwargs and passed straight through — so no runtime normalization was needed. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Closes #58.
The problem
Both
chat.completions.create()overloads annotatedvenice_parameters: VeniceParameters | None, which is narrower than what the code accepts. A mapping of the same fields has always been validated and coerced byChatCompletionRequest, but type checkers rejected the call:Because
create()is overloaded, the diagnostic doesn't name the offending argument — it reports the whole call as unmatched, which is harder to act on than themessages=version was.Reported in #1 alongside the
messages=variant. That half shipped in 2.0.1; this one didn't.The fix
Mappingadded to thecollections.abcimport — it wasn't there.create()overloads widened toVeniceParameters | Mapping[str, Any] | None.venice_parameters:docstring extended, including theextra="allow"note.ChatCompletionRequest.venice_parametersdeliberately stays model-only — same boundary decision asmessages=: that field is where coercion happens.Annotation-only. Unlike
messages=, nothing readsvenice_parametersattributes before the request model — it is popped from kwargs and passed straight through — so no runtime normalization was needed.resources/responses.pyalready annotates itAny | Noneand was never affected.Verification
Every unit test here would have passed before this change, since runtime always accepted dicts. They pin the equivalence the annotation now advertises; the type-checker probe is what actually discriminates, so it was run in both directions:
venice_parameters={"enable_web_search": "on"}[call-overload]Successvenice_parameters=VeniceParameters(...)SuccessSuccessvenice_parameters=42The last row is the one that matters — widening to
Mapping[str, Any]must not quietly turn the hint intoAny.mypy src/— clean, 172 source filesruff check+ruff format --check— cleantests/unit/resources/test_chat_venice_parameters_mapping.py: request-model coercion, body equivalence throughcreate(),extra="allow"parity between the two forms, invalid values still raising before any request, and E2EE engagement via a mapping (venice_parameters={"enable_e2ee": True}must engage the encrypted flow, or it would silently send plaintext)tests/unit/resources/— 736 passedmake testnot run — that one's yours.Accepting strictly more than before, so this is non-breaking → patch release.
🤖 Generated with Claude Code