...
This commit is contained in:
29
src/lib/actions/translatorActions.ts
Normal file
29
src/lib/actions/translatorActions.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
"use server";
|
||||
|
||||
import { getLLMAnswer } from "../ai";
|
||||
|
||||
export const genIPA = async (text: string) => {
|
||||
return (
|
||||
"[" +
|
||||
(
|
||||
await getLLMAnswer(
|
||||
`${text}\n请生成以上文本的严式国际音标,然后直接发给我,不要附带任何说明,不要擅自增减符号。`,
|
||||
)
|
||||
)
|
||||
.replaceAll("[", "")
|
||||
.replaceAll("]", "") +
|
||||
"]"
|
||||
);
|
||||
};
|
||||
|
||||
export const genLocale = async (text: string) => {
|
||||
return await getLLMAnswer(
|
||||
`${text}\n推断以上文本的地区(locale),然后直接发给我,形如如zh-CN,不要附带任何说明,不要擅自增减符号。`,
|
||||
);
|
||||
};
|
||||
|
||||
export const genTranslation = async (text: string, targetLanguage: string) => {
|
||||
return await getLLMAnswer(
|
||||
`${text}\n请将以上文本翻译到${targetLanguage},然后直接发给我,不要附带任何说明,不要擅自增减符号。`,
|
||||
);
|
||||
};
|
||||
@@ -10,6 +10,7 @@ const MAX_HISTORY_LENGTH = 50;
|
||||
export const tlso = getLocalStorageOperator<
|
||||
typeof TranslationHistoryArraySchema
|
||||
>("translator", TranslationHistoryArraySchema);
|
||||
|
||||
export const tlsoPush = (item: z.infer<typeof TranslationHistorySchema>) => {
|
||||
const oldHistory = tlso.get();
|
||||
if (oldHistory.some((v) => shallowEqual(v, item))) return oldHistory;
|
||||
|
||||
Reference in New Issue
Block a user