feat: read the harness's chat completions request - #54
Merged
Merged
Conversation
`apis/openai_chat.py` holds `ChatRequest`, the gateway's canonical request: other APIs will convert into it, as miles and polar do. It is an allowlist. A key not declared is refused by name, since dropping it would change what the harness gets back without telling it. Keys `tokin` cannot honour (`n`, `stop`, `tool_choice`, `parallel_tool_calls`, `logprobs`, `response_format`) are narrowed to the values that ask for nothing, because SDKs send those unasked, and the bookkeeping OpenAI accepts is declared and ignored. A test compares the fields against the installed SDK's own parameter list, so a bump of `openai` that adds a key fails until the key is served or refused. Messages are read leniently: unknown keys dropped, OpenAI's lazily validated `Iterable` fields read into lists so a bad item is a 400. `params` hands the engine every field named as a `GenerationParams` key, with the caller's `max_tokens` winning so it can be capped to the context left. Joining text parts moves to `ChatTemplate.conform`, where non-text content is refused: which content a template can read is the family's fact (Qwen3 renders a list of parts as nothing, Qwen3.5 reads it), and it is where a vision family will keep images.
Lawhy
enabled auto-merge (squash)
September 29, 2026 23:24
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.
Step 4 of the
chatblock: the harness-facing request.apis/openai_chat.py:ChatRequest, the canonical request; Anthropic Messages and OpenAI Responses will convert into it later, as miles and polar do.tokincannot honour (n,stop,tool_choice,parallel_tool_calls,logprobs,response_format) accept only their no-op values, since SDKs send those unasked. OpenAI's bookkeeping (user,metadata,store,stream_options,service_tier,safety_identifier,prompt_cache_*) is accepted and ignored.test_every_openai_key_is_served_or_refusedcompares the fields with the installed SDK'sCompletionCreateParams; a Dependabot bump that adds a key fails until it is served or added toREFUSED.contentandtool_callsread into lists so a bad item fails as a 400 rather than later.params(max_tokens, stop_ids)passes every field named as aGenerationParamskey; the caller'smax_tokenswins so the gateway can cap it to the context left.ChatTemplate.conformnow joins text parts and refuses non-text content. Which content a template reads is a family fact (Qwen3 renders a parts list as nothing; Qwen3.5 and GLM read it), and it is where a vision family will keep images.pydantic>=2declared, since it is imported directly.uv run pytest tests -q97 passed; tokenizer suite 943 passed, 11 skipped; ruff, mypy, pre-commit clean.