Skip to content

feat: implement ai asistant in local ollama - #49

Open
danielgarciaperal2001-glitch wants to merge 1 commit into
ErTasselli:mainfrom
danielgarciaperal2001-glitch:main
Open

danielgarciaperal2001-glitch wants to merge 1 commit into
ErTasselli:mainfrom
danielgarciaperal2001-glitch:main

Conversation

@danielgarciaperal2001-glitch

Copy link
Copy Markdown

Description:

The AI assistant was hard-wired to the Anthropic SDK. This makes it a small provider layer so the backend and the model can be picked at runtime from the AI widget: Claude stays the default and behaves exactly as before, and a local Ollama model can be used instead — no API key, nothing leaving the machine.

New server/src/ai/ module with one file per backend (anthropic.ts, ollama.ts) behind a shared AiProvider contract; Claude's existing behaviour (default model, thinking: adaptive, refusal handling) is moved over unchanged.
GET /api/ai/providers and GET /api/ai/models?provider= added; POST /api/ai/chat now accepts optional provider and model and falls back to Claude when they're omitted, so existing clients keep working.
The AI widget gets a backend dropdown, a model dropdown (populated live from the Ollama daemon) and a reload button; the choice is persisted in the existing Zustand store. The AI ●/○ indicator in the top bar now reflects whether any backend is usable.
Optional config: OLLAMA_BASE_URL (default http://127.0.0.1:11434/) and OLLAMA_MODEL; also wired into docker-compose.yml.
Security: the browser never contacts Ollama and cannot supply a URL — the API server resolves the base URL from the environment, so this can't be turned into an SSRF proxy. The new endpoints sit behind the existing API key and rate limit.
Testing: npm test -w server (35 passed, incl. 9 new tests for the AI routes), npm run build -w server, npm run build -w web all pass. Also verified end-to-end against a local Ollama daemon: switching the dropdown lists the installed models and a question is answered by the local model using the live terminal context.

Note: this contribution was developed with an AI coding agent and reviewed, built and tested by a human.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant