fix: AI language code

This commit is contained in:
Gabe
2025-11-05 01:03:44 +08:00
parent a56fb6c8d6
commit 629bf9461a
3 changed files with 19 additions and 14 deletions

View File

@@ -99,7 +99,7 @@ async (args) => {
{ {
role: "user", role: "user",
content: JSON.stringify({ content: JSON.stringify({
targetLanguage: args.to, targetLanguage: args.toLang,
segments: args.texts.map((text, id) => ({ id, text })), segments: args.texts.map((text, id) => ({ id, text })),
glossary: {}, glossary: {},
}), }),
@@ -132,7 +132,7 @@ async (args) => {
{ {
role: "user", role: "user",
content: JSON.stringify({ content: JSON.stringify({
targetLanguage: args.to, targetLanguage: args.toLang,
segments: args.texts.map((text, id) => ({ id, text })), segments: args.texts.map((text, id) => ({ id, text })),
glossary: {}, glossary: {},
}), }),

View File

@@ -74,12 +74,13 @@ const genUserPrompt = ({
glossary = {}, glossary = {},
from, from,
to, to,
toLang,
texts, texts,
docInfo, docInfo,
}) => { }) => {
if (useBatchFetch) { if (useBatchFetch) {
return JSON.stringify({ return JSON.stringify({
targetLanguage: to, targetLanguage: toLang,
title: docInfo.title, title: docInfo.title,
description: docInfo.description, description: docInfo.description,
segments: texts.map((text, i) => ({ id: i, text })), segments: texts.map((text, i) => ({ id: i, text })),
@@ -557,8 +558,8 @@ const genCloudflareAI = ({ texts, from, to, url, key }) => {
return { url, body, headers }; return { url, body, headers };
}; };
const genCustom = ({ texts, from, to, url, key }) => { const genCustom = ({ texts, fromLang, toLang, url, key }) => {
const body = { texts, from, to }; const body = { texts, from: fromLang, to: toLang };
const headers = { const headers = {
"Content-type": "application/json", "Content-type": "application/json",
Authorization: `Bearer ${key}`, Authorization: `Bearer ${key}`,
@@ -638,6 +639,8 @@ export const genTransReq = async ({ reqHook, ...args }) => {
useBatchFetch, useBatchFetch,
from, from,
to, to,
fromLang,
toLang,
texts, texts,
docInfo, docInfo,
glossary, glossary,
@@ -667,6 +670,8 @@ export const genTransReq = async ({ reqHook, ...args }) => {
useBatchFetch, useBatchFetch,
from, from,
to, to,
fromLang,
toLang,
texts, texts,
docInfo, docInfo,
glossary, glossary,

View File

@@ -312,14 +312,14 @@ export const OPT_LANGS_TO_SPEC = {
["id", "id"], ["id", "id"],
["vi", "vi"], ["vi", "vi"],
]), ]),
[OPT_TRANS_OPENAI]: OPT_LANGS_SPEC_DEFAULT, [OPT_TRANS_OPENAI]: OPT_LANGS_SPEC_NAME,
[OPT_TRANS_GEMINI]: OPT_LANGS_SPEC_DEFAULT, [OPT_TRANS_GEMINI]: OPT_LANGS_SPEC_NAME,
[OPT_TRANS_GEMINI_2]: OPT_LANGS_SPEC_DEFAULT, [OPT_TRANS_GEMINI_2]: OPT_LANGS_SPEC_NAME,
[OPT_TRANS_CLAUDE]: OPT_LANGS_SPEC_DEFAULT, [OPT_TRANS_CLAUDE]: OPT_LANGS_SPEC_NAME,
[OPT_TRANS_OLLAMA]: OPT_LANGS_SPEC_DEFAULT, [OPT_TRANS_OLLAMA]: OPT_LANGS_SPEC_NAME,
[OPT_TRANS_OPENROUTER]: OPT_LANGS_SPEC_DEFAULT, [OPT_TRANS_OPENROUTER]: OPT_LANGS_SPEC_NAME,
[OPT_TRANS_CLOUDFLAREAI]: OPT_LANGS_SPEC_DEFAULT, [OPT_TRANS_CLOUDFLAREAI]: OPT_LANGS_SPEC_NAME,
[OPT_TRANS_CUSTOMIZE]: OPT_LANGS_SPEC_DEFAULT, [OPT_TRANS_CUSTOMIZE]: OPT_LANGS_SPEC_NAME,
}; };
const specToCode = (m) => const specToCode = (m) =>
@@ -342,7 +342,7 @@ Object.entries(OPT_LANGS_TO_SPEC).forEach(([t, m]) => {
}); });
export const defaultNobatchPrompt = `You are a professional, authentic machine translation engine.`; export const defaultNobatchPrompt = `You are a professional, authentic machine translation engine.`;
export const defaultNobatchUserPrompt = `Translate the following source text from ${INPUT_PLACE_FROM} to ${INPUT_PLACE_TO}. Output translation directly without any additional text.\n\nSource Text: ${INPUT_PLACE_TEXT}\n\nTranslated Text:`; export const defaultNobatchUserPrompt = `Translate the following source text to ${INPUT_PLACE_TO}. Output translation directly without any additional text.\n\nSource Text: ${INPUT_PLACE_TEXT}\n\nTranslated Text:`;
export const defaultSystemPrompt = `Act as a translation API. Output a single raw JSON object only. No extra text or fences. export const defaultSystemPrompt = `Act as a translation API. Output a single raw JSON object only. No extra text or fences.