Skip to content

fix: accept mapping venice_parameters in chat.completions type hints (#58) - #59

Merged
sethbang merged 1 commit into
mainfrom
fix/issue-58-venice-parameters-mapping
Sep 3, 2026
Merged

fix: accept mapping venice_parameters in chat.completions type hints (#58)#59
sethbang merged 1 commit into
mainfrom
fix/issue-58-venice-parameters-mapping

Conversation

@sethbang

@sethbang sethbang commented Sep 3, 2026

Copy link
Copy Markdown
Owner

Closes #58.

The problem

Both chat.completions.create() overloads annotated venice_parameters: VeniceParameters | None, which is 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:

error: No overload variant of "create" of "ChatCompletions" matches argument
types "str", "list[dict[str, str]]", "dict[str, str]"  [call-overload]

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 the messages= version was.

Reported in #1 alongside the messages= variant. That half shipped in 2.0.1; this one didn't.

The fix

  • Mapping added to the collections.abc import — it wasn't there.
  • Both create() overloads widened to VeniceParameters | Mapping[str, Any] | None.
  • The venice_parameters: docstring extended, including the extra="allow" note.

ChatCompletionRequest.venice_parameters deliberately stays model-only — same boundary decision as messages=: that field is where coercion happens.

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. resources/responses.py already annotates it Any | None and 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:

probe before after
venice_parameters={"enable_web_search": "on"} [call-overload] Success
venice_parameters=VeniceParameters(...) Success Success
venice_parameters=42 error still errors

The last row is the one that matters — widening to Mapping[str, Any] must not quietly turn the hint into Any.

  • mypy src/ — clean, 172 source files
  • ruff check + ruff format --check — clean
  • 12 new tests in tests/unit/resources/test_chat_venice_parameters_mapping.py: request-model coercion, body equivalence through create(), 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 passed

make test not run — that one's yours.

Accepting strictly more than before, so this is non-breaking → patch release.

🤖 Generated with Claude Code

…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>
@sethbang
sethbang merged commit 7f2788e into main Sep 3, 2026
21 checks passed
@sethbang
sethbang deleted the fix/issue-58-venice-parameters-mapping branch September 3, 2026 10:12
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.

venice_parameters type hint rejects plain dicts that work at runtime

1 participant