add json_schema--Just a Demo#688
Open
somnifex wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds support for an OpenAI-compatible json_schema response format and a finaltranslation output field so the app can consume structured JSON reliably and display only the final translation.
Changes:
- Add a new system prompt/output mode (
json_finaltranslation) and extend parsers to readfinaltranslation. - Add an option for OpenAI-compatible providers to inject
response_format: { type: "json_schema", ... }. - Add UI + i18n strings and default config to store
useJsonResponseFormat.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/views/Options/Apis.js | Adds UI controls for JSON response format and a new system-prompt output selector entry. |
| src/libs/stream.js | Extends streaming JSON parsing to accept finaltranslation. |
| src/config/i18n.js | Adds i18n keys for the new UI option and output link text. |
| src/config/api.js | Adds openaiCompatible type set, a new default system prompt, and persists useJsonResponseFormat in defaults. |
| src/apis/trans.js | Injects response_format schema into requests and teaches response parsing to prefer finaltranslation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
207
to
223
| if (!useBatchFetch) { | ||
| if (useJsonResponseFormat) { | ||
| try { | ||
| const content = stripMarkdownCodeBlock(raw).trim(); | ||
| const jsonStr = getJsonString(content); | ||
| if (jsonStr) { | ||
| const parsed = JSON.parse(jsonStr); | ||
| const text = | ||
| parsed.finaltranslation ?? parsed.text ?? parsed.translation ?? raw; | ||
| return [[text, parsed.sourceLanguage]]; | ||
| } | ||
| } catch { | ||
| // fallback to raw | ||
| } | ||
| } | ||
| return [[raw]]; | ||
| } |
Comment on lines
+201
to
+204
| const closeChar = content[start] === "{" ? "}" : "]"; | ||
| const end = content.lastIndexOf(closeChar); | ||
|
|
||
| return end > start ? content.substring(start, end + 1) : ""; |
Comment on lines
+381
to
+385
| zh: `Inject OpenAI-compatible json_schema response_format.`, | ||
| en: `Inject OpenAI-compatible json_schema response_format.`, | ||
| zh_TW: `Inject OpenAI-compatible json_schema response_format.`, | ||
| ja: `Inject OpenAI-compatible json_schema response_format.`, | ||
| ko: `Inject OpenAI-compatible json_schema response_format.`, |
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.
No description provided.