Repository navigation
fix(py/openai): route legacy JSON requests by wire capability - #6944
FOWEPJF255 wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the OpenAI model adapter to support JSON output fallbacks for legacy models (such as older GPT-4 snapshots and GPT-4 Turbo) that do not support strict structured outputs. It introduces lists of prompt-only and JSON-object-only models, injecting the schema or JSON instructions into the prompt when necessary, and updates GPT-4's capabilities and tests accordingly. The review feedback suggests optimizing performance by pre-computing a combined set of legacy JSON models at the module level, rather than performing set union operations dynamically on every request.
|
The three set-union review suggestions were addressed in c377cd3: _LEGACY_JSON_MODELS is precomputed once and used in both request paths. I also merged current main in e012060 to resolve the ModelSupports conflict while preserving the JSON fallback behavior. The focused OpenAI model suite passes (126 tests with the aggregate coverage gate disabled for this single-module run), Ruff passes on the touched Python files, and uv lock --check and git diff --check pass. CI is running on the updated head. |
|
I resolved the merge conflict in the OpenAI model constants and pushed merge commit a3ee1b3. The resolution keeps both this PR's legacy JSON wire fallbacks and main's managed-field hint. The merged checkout passes 494 genkit-openai tests, Ruff lint and formatting checks on the four touched files, and uv lock --check. GitHub now reports the PR mergeable against current main; check-changes and Google CLA pass. The new main commits since the merged base only touch Flask/MCP paths. |
|
Hi @FOWEPJF255 — heads up that Genkit Python SDK development has moved to https://github.com/genkit-ai/genkit-python! Could you re-open this PR over there (file paths map 1:1 after stripping the leading py/ prefix), and link/close this PR once moved? cc @huangjeff5 |
|
While migrating this PR, I checked the current Python tree and genkit-ai/genkit-python#128. That approved catalog refresh removes the legacy model capability entries used here and deliberately resolves those IDs with generic info on compatible hosts, including schema-less JSON mode. A direct port of this PR would reintroduce model-specific fallbacks and conflict with that direction. The remaining technical distinction is explicit-schema output: this change uses prompt-only output for early GPT-4 and json_object plus prompt instructions for GPT-4 Turbo / the first GPT-4o snapshot, rather than sending json_schema. Would you prefer that behavior retained as a narrowly scoped adapter fix in the new repository, or should this legacy-model fix be retired with the catalog update? I am holding the conflicting migration pending that decision; the Bedrock migration is now genkit-ai/genkit-python#167. |
|
Thanks for checking against |
Summary
Addresses #6621 for cataloged legacy OpenAI chat models. A JSON request with a schema previously sent strict
json_schemato GPT-4 Turbo, which does not support Structured Outputs; a GPT-4 request without a schema senttextand no JSON instruction.The adapter selects a private wire fallback: prompt-only for the earliest GPT-4 models,
json_objectfor GPT-4 Turbo and the early GPT-4o snapshot, and the existing strict schema path for newer models. The legacy catalog entries remain unconstrained, while newer models retainconstrained=ALL. Genkit core now supplies schema instructions for unconstrained models, so the adapter does not duplicate them; schema-less legacy requests still receive a short JSON instruction.Unlisted OpenAI-compatible model IDs keep their existing behavior. No public API was added.
Validation
py/packages/genkit-openai/tests: 429 passed (--no-cov) on Python 3.12.uv lock --checkandgit diff --checkpassed.Prepared with Codex assistance; the focused diff and checks above were reviewed in this run.