Skip to content

Commit 54ac381

Browse files
许君山许君山
authored andcommitted
feat: prompt AI to review and verify conjugation results
1 parent 3ca6f5f commit 54ac381

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

backend/server.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,25 @@ app.get('/api/ai-models', async (req, res) => {
9696
});
9797

9898
// AI 动词解析及例句生成 API
99-
app.get('/api/ai-explain', async (req, res) => {
99+
app.post('/api/ai-explain', async (req, res) => {
100100
try {
101-
const { verb, model } = req.query;
101+
const { verb, model, conjugationResult } = req.body;
102102
if (!verb) {
103103
return res.status(400).json({ error: 'Missing required parameter: verb' });
104104
}
105105
const selectedModel = model || 'qwen2.5:7b';
106106

107-
const prompt = `你是一个日语语言学专家。请你用中文简明扼要地解释日语动词 "${verb}" 的含义,并提供2个实用的日常例句(包含日文、平假名注音和中文翻译)。不要输出多余的寒暄,直接输出结构化的内容。`;
107+
const prompt = `你是一个严谨的日语语言学专家。
108+
我为你提供了一个日语动词 "${verb}" 以及程序自动生成的活用变形结果:
109+
\`\`\`json
110+
${JSON.stringify(conjugationResult, null, 2)}
111+
\`\`\`
112+
113+
请你执行以下两个任务:
114+
1. **核对纠错**:快速核对上方 JSON 中的变形结果(特别是て形、た形等特殊音变)。如果变形完全正确,请简短地给出一句肯定评价(如"系统生成的变形结果正确");如果发现错误,请明确指出哪里错了,并给出正确的变形形式。
115+
2. **释义与例句**:用中文简明扼要地解释该动词的含义,并提供2个实用的日常例句(必须包含日文原文、平假名注音和精准的中文翻译)。
116+
117+
注意:直接输出结构化的 Markdown 格式内容,不需要任何多余的开场白或寒暄。`;
108118

109119
res.setHeader('Content-Type', 'text/event-stream');
110120
res.setHeader('Cache-Control', 'no-cache');

frontend/src/App.vue

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,17 @@ const fetchAiExplanation = async () => {
321321
aiRawExplanation.value = '';
322322
323323
try {
324-
const response = await fetch(`/api/ai-explain?verb=${encodeURIComponent(result.value.dictionaryForm)}&model=${encodeURIComponent(selectedModel.value || 'qwen2.5:7b')}`);
324+
const response = await fetch('/api/ai-explain', {
325+
method: 'POST',
326+
headers: {
327+
'Content-Type': 'application/json'
328+
},
329+
body: JSON.stringify({
330+
verb: result.value.dictionaryForm,
331+
model: selectedModel.value || 'qwen2.5:7b',
332+
conjugationResult: result.value // 把前端拿到的变形结果也发给后端
333+
})
334+
});
325335
326336
if (!response.ok) {
327337
throw new Error('网络请求失败');

0 commit comments

Comments
 (0)