fix: custom api doc

This commit is contained in:
Gabe
2025-10-17 01:47:36 +08:00
parent 9a8e24f590
commit b2eea5d0d7
3 changed files with 58 additions and 9 deletions

View File

@@ -26,6 +26,8 @@ import {
INPUT_PLACE_KEY,
INPUT_PLACE_MODEL,
DEFAULT_USER_AGENT,
defaultSystemPrompt,
defaultSubtitlePrompt,
} from "../config";
import { msAuth } from "../libs/auth";
import { genDeeplFree } from "./deepl";
@@ -678,13 +680,16 @@ export const genTransReq = async ({ reqHook, ...args }) => {
if (reqHook?.trim() && !events) {
try {
interpreter.run(`exports.reqHook = ${reqHook}`);
const hookResult = await interpreter.exports.reqHook(args, {
url,
body,
headers,
userMsg,
method,
});
const hookResult = await interpreter.exports.reqHook(
{ ...args, defaultSystemPrompt, defaultSubtitlePrompt },
{
url,
body,
headers,
userMsg,
method,
}
);
if (hookResult && hookResult.url) {
return genInit(hookResult);
}
@@ -732,6 +737,8 @@ export const parseTransRes = async (
fromLang,
toLang,
langMap,
extractJson,
parseAIRes,
});
if (hookResult && Array.isArray(hookResult.translations)) {
if (history && userMsg && hookResult.modelMsg) {

View File

@@ -340,7 +340,7 @@ Object.entries(OPT_LANGS_TO_SPEC).forEach(([t, m]) => {
OPT_LANGS_TO_CODE[t] = specToCode(m);
});
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.
Input:
{"targetLanguage":"<lang>","title":"<context>","description":"<context>","segments":[{"id":1,"text":"..."}],"glossary":{"sourceTerm":"targetTerm"},"tone":"<formal|casual>"}
@@ -381,7 +381,7 @@ Fail-safe: On any error, return {"translations":[]}.`;
// 4. **Special Cases**: '[Music]' (and similar cues) are standalone entries. Translate appropriately (e.g., '[音乐]', '[Musique]').
// `;
const defaultSubtitlePrompt = `You are an expert AI for subtitle generation. Convert a JSON array of word-level timestamps into a bilingual VTT file.
export const defaultSubtitlePrompt = `You are an expert AI for subtitle generation. Convert a JSON array of word-level timestamps into a bilingual VTT file.
**Workflow:**
1. Merge \`text\` fields into complete sentences; ignore empty text.