feat(chat): add response_format passthrough for structured output #60

Closed
timur wants to merge 1 commit from development_json_schema into development
Owner

Implements #59.

Forwards an OpenAI-style response_format field through the broker to upstream providers. Pass-through only — no broker-side schema validation.

  • ChatRequest.response_format: Option<Value> (forwarded unchanged via existing .json(&request) serialisation)
  • OpenAIChatRequest.response_format (REST POST /v1/chat/completions)
  • ai.chat JSON-RPC accepts the new optional param
  • openrpc.json updated

Unblocks hero_memory Phases 4 (Q&A) and 5 (ontology) — see hero_memory#1.

Ready to merge once reviewed.

Implements [#59](https://forge.ourworld.tf/lhumina_code/hero_aibroker/issues/59). Forwards an OpenAI-style `response_format` field through the broker to upstream providers. Pass-through only — no broker-side schema validation. - `ChatRequest.response_format: Option<Value>` (forwarded unchanged via existing `.json(&request)` serialisation) - `OpenAIChatRequest.response_format` (REST POST /v1/chat/completions) - `ai.chat` JSON-RPC accepts the new optional param - `openrpc.json` updated Unblocks hero_memory Phases 4 (Q&A) and 5 (ontology) — see hero_memory#1. Ready to merge once reviewed.
feat(chat): add response_format passthrough for structured output
Some checks failed
Build and Test / build-and-test (pull_request) Failing after 10s
ebfd358f01
Forwards an OpenAI-style response_format field through the broker to the
upstream provider. Enables JSON-schema-constrained completions, which
hero_memory's Q&A and ontology extractors depend on (see
hero_aibroker#59).

- providers/types.rs: ChatRequest gains optional response_format:
  Option<serde_json::Value>. The OpenAIProvider already serialises
  ChatRequest directly to the upstream HTTP body, so the field is
  forwarded unchanged.
- server/src/api/chat.rs: OpenAIChatRequest gains response_format and
  the From<OpenAIChatRequest> for ChatRequest impl carries it across.
- server/src/api/mod.rs: handle_ai_chat reads response_format from
  params.
- openrpc.json: ai.chat documents the optional response_format
  parameter.

Pass-through only — no aibroker-side schema validation. Callers send
either { "type": "json_schema", "json_schema": {...} } or
{ "type": "json_object" } according to the upstream provider's spec.

Refs hero_aibroker#59
Refs hero_memory#1

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Author
Owner

Closing as redundant. Upstream development already implements response_format on ai.chat (with a typed ResponseFormat { kind, json_schema } struct in providers/types.rs plus the openrpc.json param), as part of the cascade-multi-broker work that landed after I branched. hero_memory will pin to development directly.

Closing as redundant. Upstream `development` already implements `response_format` on `ai.chat` (with a typed `ResponseFormat { kind, json_schema }` struct in `providers/types.rs` plus the openrpc.json param), as part of the cascade-multi-broker work that landed after I branched. hero_memory will pin to `development` directly.
timur closed this pull request 2026-05-06 08:39:08 +00:00
mik-tf reopened this pull request 2026-05-06 17:57:28 +00:00
Author
Owner

Closing as already implemented in current development.

response_format passthrough was completed via the OpenRouter / chat refactor work that landed after this PR was opened. Mapping against the current tree (commit 9a03f20):

Surface Where
Typed ChatRequest.response_format: Option<ResponseFormat> (kind + json_schema) crates/hero_aibroker_lib/src/providers/types.rs:205
ai.chat JSON-RPC passthrough — serde_json::from_value(params) straight into ChatRequest crates/hero_aibroker_server/src/api/mod.rs:433
REST /v1/chat/completions — direct deserialize into ChatRequest (the intermediate OpenAIChatRequest was removed) crates/hero_aibroker_server/src/api/chat.rs:74
OpenRPC schema crates/hero_aibroker_server/openrpc.json:899
Generated client AiChatInput.response_format crates/hero_aibroker_server/openrpc.client.generated.rs:623

The current shape is actually a bit better than what this PR proposed — it's typed (ResponseFormat with kind and json_schema fields) rather than a raw Option<Value>, so the OpenRPC schema can document the structure. Linked issue #59 is already closed.

Thanks anyway — closing without merging.

Closing as already implemented in current `development`. `response_format` passthrough was completed via the OpenRouter / chat refactor work that landed after this PR was opened. Mapping against the current tree (commit `9a03f20`): | Surface | Where | |---|---| | Typed `ChatRequest.response_format: Option<ResponseFormat>` (kind + json_schema) | `crates/hero_aibroker_lib/src/providers/types.rs:205` | | `ai.chat` JSON-RPC passthrough — `serde_json::from_value(params)` straight into `ChatRequest` | `crates/hero_aibroker_server/src/api/mod.rs:433` | | REST `/v1/chat/completions` — direct deserialize into `ChatRequest` (the intermediate `OpenAIChatRequest` was removed) | `crates/hero_aibroker_server/src/api/chat.rs:74` | | OpenRPC schema | `crates/hero_aibroker_server/openrpc.json:899` | | Generated client `AiChatInput.response_format` | `crates/hero_aibroker_server/openrpc.client.generated.rs:623` | The current shape is actually a bit better than what this PR proposed — it's typed (`ResponseFormat` with `kind` and `json_schema` fields) rather than a raw `Option<Value>`, so the OpenRPC schema can document the structure. Linked issue #59 is already closed. Thanks anyway — closing without merging.
timur closed this pull request 2026-05-11 10:06:56 +00:00
Some checks failed
Build and Test / build-and-test (pull_request) Failing after 10s

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lhumina_code/hero_aibroker!60
No description provided.