Skip to content

add json_schema--Just a Demo#688

Open
somnifex wants to merge 2 commits into
fishjar:devfrom
somnifex:dev
Open

add json_schema--Just a Demo#688
somnifex wants to merge 2 commits into
fishjar:devfrom
somnifex:dev

Conversation

@somnifex

Copy link
Copy Markdown

No description provided.

Copilot AI review requested due to automatic review settings May 21, 2026 00:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 read finaltranslation.
  • 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 thread src/apis/trans.js
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 thread src/apis/trans.js
Comment on lines +201 to +204
const closeChar = content[start] === "{" ? "}" : "]";
const end = content.lastIndexOf(closeChar);

return end > start ? content.substring(start, end + 1) : "";
Comment thread src/config/i18n.js
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.`,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants