Skip to content

Commit 0e6ca3a

Browse files
许君山许君山
authored andcommitted
fix: resolve backend API and conjugation edge cases
Closes #5 - Add res.on('error') handler to Jisho API HTTP stream - Unify hardcoded Ollama models (qwen2.5:7b/14b) to process.env.OLLAMA_MODEL with a default of 'qwen2.5' - Add Godan verb exceptions for 'tou' (問う) and 'kou' (請う) te/ta-form conjugations
1 parent 8f97bdf commit 0e6ca3a

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

backend/conjugationEngine.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ class GodanVerb extends Verb {
6565
if (this.dictionaryForm.endsWith('行く') || this.dictionaryForm.endsWith('いく')) {
6666
return isTe ? 'って' : 'った';
6767
}
68+
if (this.dictionaryForm.endsWith('問う') || this.dictionaryForm.endsWith('とう')) {
69+
return isTe ? 'うて' : 'うた';
70+
}
71+
if (this.dictionaryForm.endsWith('請う') || this.dictionaryForm.endsWith('こう')) {
72+
return isTe ? 'うて' : 'うた';
73+
}
6874
const suffixMap = {
6975
'う': { te: 'って', ta: 'った' },
7076
'つ': { te: 'って', ta: 'った' },

backend/server.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ function searchJisho(keyword, verbOnly = true) {
6868
reject(e);
6969
}
7070
});
71+
res.on('error', reject);
7172
});
7273
req.on('error', reject);
7374
req.setTimeout(5000, () => {
@@ -132,6 +133,7 @@ function lookupWordJisho(keyword) {
132133
reject(e);
133134
}
134135
});
136+
res.on('error', reject);
135137
});
136138
req.on('error', reject);
137139
req.setTimeout(5000, () => {
@@ -216,8 +218,9 @@ const ollama = new Ollama({ host: 'http://127.0.0.1:11434' });
216218
async function translateMeaningsToChinese(meanings) {
217219
try {
218220
const englishDefs = meanings.map((m, i) => `${i + 1}. [${m.pos}] ${m.definitions}`).join('\n');
221+
const model = process.env.OLLAMA_MODEL || 'qwen2.5';
219222
const response = await ollama.chat({
220-
model: 'qwen2.5:7b',
223+
model: model,
221224
messages: [{
222225
role: 'user',
223226
content: `将以下日语单词的英文释义翻译为简洁的中文。每条保持编号,只输出中文翻译,不要输出原文、词性或任何解释。格式:"1. 中文释义"\n\n${englishDefs}`
@@ -404,7 +407,7 @@ app.post('/api/ai-explain', async (req, res) => {
404407
if (!verb) {
405408
return res.status(400).json({ error: 'Missing required parameter: verb' });
406409
}
407-
const selectedModel = model || 'qwen2.5:7b';
410+
const selectedModel = model || process.env.OLLAMA_MODEL || 'qwen2.5';
408411

409412
let prompt;
410413

0 commit comments

Comments
 (0)