Skip to content

Commit e27f9ae

Browse files
fix: add system message to enforce Vietnamese output + debug preview
1 parent c166823 commit e27f9ae

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/translate.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,14 @@ async function callLlm(prompt: string): Promise<string> {
6060
const res = await client.chat.completions.create({
6161
model,
6262
max_completion_tokens: MAX_TOKENS,
63-
messages: [{ role: "user", content: prompt }],
63+
messages: [
64+
{
65+
role: "system",
66+
content:
67+
"You are a Chinese-to-Vietnamese translator. You MUST output ONLY Vietnamese text. Never output Chinese.",
68+
},
69+
{ role: "user", content: prompt },
70+
],
6471
});
6572
const text = res.choices[0]?.message?.content;
6673
if (!text) throw new Error("Empty LLM response");
@@ -125,8 +132,9 @@ async function translateFile(datePath: string, report: string): Promise<boolean>
125132
return false;
126133
}
127134

128-
console.log(`[translate] Translating ${report}...`);
135+
console.log(`[translate] Translating ${report} (${zhContent.length} chars)...`);
129136
const viContent = await callLlm(buildPrompt(zhContent));
137+
console.log(`[translate] Result preview: ${viContent.slice(0, 200).replace(/\n/g, " ")}`);
130138
const outPath = path.join(datePath, `${report}-vi.md`);
131139
fs.mkdirSync(path.dirname(outPath), { recursive: true });
132140
fs.writeFileSync(outPath, viContent, "utf-8");

0 commit comments

Comments
 (0)