fix: tone error (#382)
This commit is contained in:
@@ -419,7 +419,7 @@ export const apiTranslate = async ({
|
||||
toLang,
|
||||
apiSetting = DEFAULT_API_SETTING,
|
||||
docInfo = {},
|
||||
glossary = {},
|
||||
glossary,
|
||||
useCache = true,
|
||||
usePool = true,
|
||||
}) => {
|
||||
|
||||
@@ -30,6 +30,11 @@ import {
|
||||
defaultSubtitlePrompt,
|
||||
defaultNobatchPrompt,
|
||||
defaultNobatchUserPrompt,
|
||||
INPUT_PLACE_TONE,
|
||||
INPUT_PLACE_TITLE,
|
||||
INPUT_PLACE_DESCRIPTION,
|
||||
INPUT_PLACE_TO_LANG,
|
||||
INPUT_PLACE_FROM_LANG,
|
||||
} from "../config";
|
||||
import { msAuth } from "../libs/auth";
|
||||
import { genDeeplFree } from "./deepl";
|
||||
@@ -62,36 +67,62 @@ const keyPick = (apiSlug, key = "", cacheMap) => {
|
||||
return keys[curIndex];
|
||||
};
|
||||
|
||||
const genSystemPrompt = ({ systemPrompt, from, to }) =>
|
||||
const genSystemPrompt = ({
|
||||
systemPrompt,
|
||||
tone,
|
||||
from,
|
||||
to,
|
||||
fromLang,
|
||||
toLang,
|
||||
texts,
|
||||
docInfo: { title = "", description = "" } = {},
|
||||
}) =>
|
||||
systemPrompt
|
||||
.replaceAll(INPUT_PLACE_TITLE, title)
|
||||
.replaceAll(INPUT_PLACE_DESCRIPTION, description)
|
||||
.replaceAll(INPUT_PLACE_TONE, tone)
|
||||
.replaceAll(INPUT_PLACE_FROM, from)
|
||||
.replaceAll(INPUT_PLACE_TO, to);
|
||||
.replaceAll(INPUT_PLACE_TO, to)
|
||||
.replaceAll(INPUT_PLACE_FROM_LANG, fromLang)
|
||||
.replaceAll(INPUT_PLACE_TO_LANG, toLang)
|
||||
.replaceAll(INPUT_PLACE_TEXT, texts[0]);
|
||||
|
||||
const genUserPrompt = ({
|
||||
nobatchUserPrompt,
|
||||
useBatchFetch,
|
||||
tone,
|
||||
glossary = {},
|
||||
glossary,
|
||||
from,
|
||||
to,
|
||||
fromLang,
|
||||
toLang,
|
||||
texts,
|
||||
docInfo,
|
||||
docInfo: { title = "", description = "" } = {},
|
||||
}) => {
|
||||
if (useBatchFetch) {
|
||||
return JSON.stringify({
|
||||
const promptObj = {
|
||||
targetLanguage: toLang,
|
||||
title: docInfo.title,
|
||||
description: docInfo.description,
|
||||
segments: texts.map((text, i) => ({ id: i, text })),
|
||||
glossary,
|
||||
tone,
|
||||
});
|
||||
};
|
||||
|
||||
title && (promptObj.title = title);
|
||||
description && (promptObj.description = description);
|
||||
glossary &&
|
||||
Object.keys(glossary).length !== 0 &&
|
||||
(promptObj.glossary = glossary);
|
||||
tone && (promptObj.tone = tone);
|
||||
|
||||
return JSON.stringify(promptObj);
|
||||
}
|
||||
|
||||
return nobatchUserPrompt
|
||||
.replaceAll(INPUT_PLACE_TITLE, title)
|
||||
.replaceAll(INPUT_PLACE_DESCRIPTION, description)
|
||||
.replaceAll(INPUT_PLACE_TONE, tone)
|
||||
.replaceAll(INPUT_PLACE_FROM, from)
|
||||
.replaceAll(INPUT_PLACE_TO, to)
|
||||
.replaceAll(INPUT_PLACE_FROM_LANG, fromLang)
|
||||
.replaceAll(INPUT_PLACE_TO_LANG, toLang)
|
||||
.replaceAll(INPUT_PLACE_TEXT, texts[0]);
|
||||
};
|
||||
|
||||
@@ -647,6 +678,7 @@ export const genTransReq = async ({ reqHook, ...args }) => {
|
||||
customHeader,
|
||||
customBody,
|
||||
events,
|
||||
tone,
|
||||
} = args;
|
||||
|
||||
if (API_SPE_TYPES.mulkeys.has(apiType)) {
|
||||
@@ -662,6 +694,11 @@ export const genTransReq = async ({ reqHook, ...args }) => {
|
||||
systemPrompt: useBatchFetch ? systemPrompt : nobatchPrompt,
|
||||
from,
|
||||
to,
|
||||
fromLang,
|
||||
toLang,
|
||||
texts,
|
||||
docInfo,
|
||||
tone,
|
||||
});
|
||||
args.userPrompt = !!events
|
||||
? JSON.stringify(events)
|
||||
@@ -674,6 +711,7 @@ export const genTransReq = async ({ reqHook, ...args }) => {
|
||||
toLang,
|
||||
texts,
|
||||
docInfo,
|
||||
tone,
|
||||
glossary,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -9,7 +9,12 @@ export const DEFAULT_CONTEXT_SIZE = 3; // 上下文会话数量
|
||||
export const INPUT_PLACE_URL = "{{url}}"; // 占位符
|
||||
export const INPUT_PLACE_FROM = "{{from}}"; // 占位符
|
||||
export const INPUT_PLACE_TO = "{{to}}"; // 占位符
|
||||
export const INPUT_PLACE_FROM_LANG = "{{fromLang}}"; // 占位符
|
||||
export const INPUT_PLACE_TO_LANG = "{{toLang}}"; // 占位符
|
||||
export const INPUT_PLACE_TEXT = "{{text}}"; // 占位符
|
||||
export const INPUT_PLACE_TONE = "{{tone}}"; // 占位符
|
||||
export const INPUT_PLACE_TITLE = "{{title}}"; // 占位符
|
||||
export const INPUT_PLACE_DESCRIPTION = "{{description}}"; // 占位符
|
||||
export const INPUT_PLACE_KEY = "{{key}}"; // 占位符
|
||||
export const INPUT_PLACE_MODEL = "{{model}}"; // 占位符
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ export default function ReusableAutocomplete({
|
||||
name: name,
|
||||
value: newValue,
|
||||
},
|
||||
preventDefault: () => {},
|
||||
};
|
||||
onChange(syntheticEvent);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user