feat: add support for structured outputs with response-schema-file param#96
Merged
Conversation
Co-authored-by: FidelusAleksander <63016446+FidelusAleksander@users.noreply.github.com>
Co-authored-by: FidelusAleksander <63016446+FidelusAleksander@users.noreply.github.com>
Co-authored-by: FidelusAleksander <63016446+FidelusAleksander@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for structured AI outputs by allowing users to supply a JSON schema file, updates the core AI client to use this schema, and enhances documentation, tests, and workflows accordingly.
- Added
response-schema-fileinput handling insrc/main.tsand wired it intogenerateAIResponse - Extended
generateAIResponseinsrc/ai.tsto include aresponse_formatwhen a schema is provided - Updated inputs in
action.yml, added JSON schema example files, new tests, README sections, and a workflow job for structured outputs
Reviewed Changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/main.ts | Read and parse response-schema-file and pass schema to generateAIResponse |
| src/ai.ts | Extended generateAIResponse signature and added response_format handling |
| action.yml | Added new inputs: system-prompt, system-prompt-file, response-schema-file |
| tests/test-schema.json | Added a minimal test schema for structured outputs |
| tests/simple-response.json | Added a basic response schema (not yet covered by tests) |
| tests/main.test.ts | New tests for schema file existence, parsing, and backward compatibility |
| tests/ai.test.ts | Tests for structured vs. non-structured generateAIResponse calls |
| README.md | Documented JSON schema usage, advanced examples, and new inputs |
| .github/workflows/test-action.yml | New job to verify that the structured output’s message field is non-empty |
Comments suppressed due to low confidence (3)
README.md:105
- The README references 'code-review.json', but this file isn't included in the repository. Update the example to use an existing schema file (e.g., 'code-analysis.json') or add the missing 'code-review.json'.
response-schema-file: '__tests__/code-review.json'
tests/simple-response.json:1
- [nitpick] The 'simple-response.json' schema file is added but isn't covered by any tests. Consider adding tests to validate its integration or removing it if it's not used.
{
src/ai.ts:8
- [nitpick] Consider renaming the parameter 'schema' to 'responseSchema' for consistency with the main code and to improve clarity.
schema?: { [key: string]: unknown }
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.
This pull request introduces structured output support for AI responses, enabling users to define JSON schemas for consistent and typed outputs. It also adds advanced usage examples and updates the documentation and tests to reflect these changes.
Structured Output Support
src/ai.ts: Updated thegenerateAIResponsefunction to accept an optionalschemaparameter and incorporate structured output formats using JSON Schema.src/main.ts: Added logic to read and validate a JSON Schema file (response-schema-file) for structured outputs, throwing errors for invalid or missing schema files. [1] [2]action.yml: Added new inputs (response-schema-file,system-prompt,system-prompt-file) to support structured outputs and system prompts.Documentation Updates
README.md: Added sections on structured outputs and advanced usage, including examples of using system prompts with structured outputs. [1] [2] [3]Test Enhancements
__tests__/ai.test.ts: Added tests for structured output schema handling in thegenerateAIResponsefunction.__tests__/main.test.ts: Added tests to validate schema file handling, including cases for valid schemas, missing files, and invalid JSON.Example Schemas
__tests__/test-schema.json: Added a simple schema for testing structured outputs.__tests__/code-analysis.json: Added a schema for code analysis responses, defining properties likesummary,issues, andscore.__tests__/simple-response.json: Added a schema for basic responses with properties likeresponse,confidence, andtags.Workflow Update
.github/workflows/test-action.yml: Added a new job to test structured output functionality, ensuring themessagefield in the response is not empty.