feat(ai): integrate local Ollama AI for in-context sentence translation and caching (Task 13)

This commit is contained in:
Antigravity committed 2026-10-06 15:05:24 +03:00
1 parent 0c5951df8d
commit 37a1f1ab35
12 files changed
+605 -15

No files matched your search

+30 -5
View File
@@ -66,11 +66,7 @@ export const api = {
return resp.ok ? await resp.json() : [];
},
async lookup(term) {
const resp = await fetch(`/api/lookup?term=${encodeURIComponent(term)}`);
if (resp.ok) {
return await resp.json();
}
throw new Error(`Lookup failed: ${resp.status}`);
return await api.lookup.search(term);
},
async create(payload) {
return await fetch('/api/cards', {
@@ -98,6 +94,35 @@ export const api = {
}
},
// Dictionary Lookup & AI Sentence Translation
lookup: {
async search(term) {
const resp = await fetch(`/api/lookup?term=${encodeURIComponent(term)}`);
if (resp.ok) {
return await resp.json();
}
throw new Error(`Lookup failed: ${resp.status}`);
},
async translateSentence(sentence, targetWord = '') {
const resp = await fetch('/api/translate-sentence', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
sentence: sentence,
target_word: targetWord
})
});
if (resp.ok) {
return await resp.json();
}
throw new Error(`Sentence translation failed: ${resp.status}`);
},
async getAiStatus() {
const resp = await fetch('/api/ai/status');
return resp.ok ? await resp.json() : { online: false, models: [] };
}
},
// Collections & Tags
collections: {
async getAll() {