Add Ollama support for local AI-powered price extraction

- Add database migration for ollama_base_url and ollama_model columns
- Update backend models and queries for Ollama settings
- Add extractWithOllama function using Ollama's /api/chat endpoint
- Add /api/settings/ai/test-ollama endpoint to test connection and list models
- Update frontend Settings page with Ollama configuration UI
- Support model selection from dropdown after testing connection

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
clucraft 2026-01-22 20:14:14 -05:00
parent 6c2aece1e8
commit 082aae8789
7 changed files with 233 additions and 10 deletions

View file

@ -34,9 +34,11 @@ export interface NotificationSettings {
export interface AISettings {
ai_enabled: boolean;
ai_provider: 'anthropic' | 'openai' | null;
ai_provider: 'anthropic' | 'openai' | 'ollama' | null;
anthropic_api_key: string | null;
openai_api_key: string | null;
ollama_base_url: string | null;
ollama_model: string | null;
}
export const userQueries = {
@ -195,7 +197,7 @@ export const userQueries = {
getAISettings: async (id: number): Promise<AISettings | null> => {
const result = await pool.query(
'SELECT ai_enabled, ai_provider, anthropic_api_key, openai_api_key FROM users WHERE id = $1',
'SELECT ai_enabled, ai_provider, anthropic_api_key, openai_api_key, ollama_base_url, ollama_model FROM users WHERE id = $1',
[id]
);
return result.rows[0] || null;
@ -225,13 +227,21 @@ export const userQueries = {
fields.push(`openai_api_key = $${paramIndex++}`);
values.push(settings.openai_api_key);
}
if (settings.ollama_base_url !== undefined) {
fields.push(`ollama_base_url = $${paramIndex++}`);
values.push(settings.ollama_base_url);
}
if (settings.ollama_model !== undefined) {
fields.push(`ollama_model = $${paramIndex++}`);
values.push(settings.ollama_model);
}
if (fields.length === 0) return null;
values.push(id.toString());
const result = await pool.query(
`UPDATE users SET ${fields.join(', ')} WHERE id = $${paramIndex}
RETURNING ai_enabled, ai_provider, anthropic_api_key, openai_api_key`,
RETURNING ai_enabled, ai_provider, anthropic_api_key, openai_api_key, ollama_base_url, ollama_model`,
values
);
return result.rows[0] || null;