Skip to content

Add OpenAI JSON Schema (structured output) support to $gpt#1865

Merged
nmaguiar merged 4 commits into
t8from
copilot/add-openai-responses-api-support
Jul 6, 2026
Merged

Add OpenAI JSON Schema (structured output) support to $gpt#1865
nmaguiar merged 4 commits into
t8from
copilot/add-openai-responses-api-support

Conversation

Copilot AI commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

The OpenAI provider lacked support for the response_format: json_schema mode, which enforces server-side schema validation and guarantees structured JSON output from the model.

Changes

js/owrap.ai.js

  • rawResponse (OpenAI provider) — new low-level method mirroring rawPrompt but sets response_format: { type: "json_schema", json_schema: { name, description, schema, strict } }. Integrates with conversation history, debug channels, and stats capture. Defaults: description → "API Response", strict → true.

  • jsonSchemaPrompt(aPrompt, aResponseSchema, aModel, aTemperature, tools) — prototype method that calls rawResponse and returns the parsed JSON. Throws for providers that don't implement rawResponse.

  • jsonSchemaPromptWithStats(...) — same, returns { response, stats }.

  • $gpt.jsonSchemaPrompt / $gpt.jsonSchemaPromptWithStats — convenience wrappers on the global $gpt object.

tests/autoTestAll.AI.{js,yaml}

Five new unit tests (all using mock _request): raw request structure, response parsing, stats capture, schema defaults, and unsupported-provider error.

Usage

var result = $gpt({ type: "openai", options: { key: "sk-...", model: "gpt-4o" } })
    .jsonSchemaPrompt("Extract: Alice, alice@example.com, 30", {
        name: "PersonInfo",
        description: "Extract person details",
        schema: {
            type: "object",
            properties: {
                name:  { type: "string" },
                email: { type: "string" },
                age:   { type: "number" }
            },
            required: ["name", "email"],
            additionalProperties: false
        },
        strict: true
    })
// → { name: "Alice", email: "alice@example.com", age: 30 }

Copilot AI changed the title [WIP] Add support for OpenAI Responses API in owrap.ai.js Add OpenAI JSON Schema (structured output) support to $gpt Jul 4, 2026
Copilot AI requested a review from nmaguiar July 4, 2026 04:20
Implement the /responses endpoint integration in owrap.ai.js, including response schema normalization, input text conversion, and error handling. Update AI tests to verify the new responses endpoint usage and JSON schema formatting.
@nmaguiar nmaguiar marked this pull request as ready for review July 6, 2026 13:24
@nmaguiar nmaguiar merged commit b58f160 into t8 Jul 6, 2026
1 check passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in Continuous Enhancement Jul 6, 2026
@nmaguiar nmaguiar deleted the copilot/add-openai-responses-api-support branch July 6, 2026 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Development

Successfully merging this pull request may close these issues.

2 participants