Commit 109cfef2ae
109cfef2ae202d32677032ecff1f4fcc12d30e49
parent: f5c756707f
Unsigned
cmc <hello@cleberg.net> · 2026-04-19 03:57 UTC
clarify ollama settings in docker environments
Layout: unified · split
src/components/SettingsPanel.tsx
+5 −3
| @@ -86,7 +86,7 @@ export function SettingsPanel({ settings, onChange, onClose }: Props) { |
| 86 | onChange={e => setUrl(e.target.value)} |
86 | onChange={e => setUrl(e.target.value)} |
| 87 | onBlur={commitUrl} |
87 | onBlur={commitUrl} |
| 88 | onKeyDown={e => e.key === 'Enter' && commitUrl()} |
88 | onKeyDown={e => e.key === 'Enter' && commitUrl()} |
| 89 | placeholder="http://localhost:11434" |
89 | placeholder="empty = same-origin proxy (recommended)" |
| 90 | spellCheck={false} |
90 | spellCheck={false} |
| 91 | /> |
91 | /> |
| 92 | <button |
92 | <button |
| @@ -147,8 +147,10 @@ export function SettingsPanel({ settings, onChange, onClose }: Props) { |
| 147 | Install from <strong>ollama.com</strong>, then pull any model to get started. |
147 | Install from <strong>ollama.com</strong>, then pull any model to get started. |
| 148 | </p> |
148 | </p> |
| 149 | <p> |
149 | <p> |
| 150 | If connection fails, ensure Ollama is running and CORS is open:<br /> |
150 | Leave <strong>Server URL</strong> empty to route through the app's |
| 151 | <code>OLLAMA_ORIGINS=* ollama serve</code> |
151 | own server (works automatically with the Docker setup). For local |
| |
152 | dev, set it to <code>http://localhost:11434</code> and ensure CORS |
| |
153 | is open: <code>OLLAMA_ORIGINS=* ollama serve</code> |
| 152 | </p> |
154 | </p> |
| 153 | </div> |
155 | </div> |
| 154 | </div> |
156 | </div> |
src/engine/aiGenerator.ts
+8 −3
| @@ -84,7 +84,10 @@ export async function generateWithAI( |
| 84 | settings: OllamaSettings, |
84 | settings: OllamaSettings, |
| 85 | signal?: AbortSignal, |
85 | signal?: AbortSignal, |
| 86 | ): Promise<BrandOutputs> { |
86 | ): Promise<BrandOutputs> { |
| 87 | const url = `${settings.baseUrl.replace(/\/$/, '')}/api/chat`; |
87 | // Empty baseUrl means "same origin" — nginx proxies /api/ to Ollama internally. |
| |
88 | // A full URL (e.g. http://localhost:11434) is used as-is for local dev. |
| |
89 | const base = settings.baseUrl ? settings.baseUrl.replace(/\/$/, '') : ''; |
| |
90 | const url = `${base}/api/chat`; |
| 88 | |
91 | |
| 89 | let res: Response; |
92 | let res: Response; |
| 90 | try { |
93 | try { |
| @@ -104,7 +107,8 @@ export async function generateWithAI( |
| 104 | }); |
107 | }); |
| 105 | } catch (err) { |
108 | } catch (err) { |
| 106 | if ((err as Error).name === 'AbortError') throw err; |
109 | if ((err as Error).name === 'AbortError') throw err; |
| 107 | throw new Error(`Cannot reach Ollama at ${settings.baseUrl}. Is it running?`); |
110 | const target = settings.baseUrl || '(same origin /api/)'; |
| |
111 | throw new Error(`Cannot reach Ollama at ${target}. Is it running?`); |
| 108 | } |
112 | } |
| 109 | |
113 | |
| 110 | if (!res.ok) { |
114 | if (!res.ok) { |
| @@ -130,7 +134,8 @@ export async function generateWithAI( |
| 130 | |
134 | |
| 131 | // Test connectivity and return available model names |
135 | // Test connectivity and return available model names |
| 132 | export async function testOllamaConnection(baseUrl: string): Promise<string[]> { |
136 | export async function testOllamaConnection(baseUrl: string): Promise<string[]> { |
| 133 | const url = `${baseUrl.replace(/\/$/, '')}/api/tags`; |
137 | const base = baseUrl ? baseUrl.replace(/\/$/, '') : ''; |
| |
138 | const url = `${base}/api/tags`; |
| 134 | const res = await fetch(url, { signal: AbortSignal.timeout(5000) }); |
139 | const res = await fetch(url, { signal: AbortSignal.timeout(5000) }); |
| 135 | if (!res.ok) throw new Error(`Ollama responded with ${res.status}`); |
140 | if (!res.ok) throw new Error(`Ollama responded with ${res.status}`); |
| 136 | const data = await res.json() as { models?: Array<{ name: string }> }; |
141 | const data = await res.json() as { models?: Array<{ name: string }> }; |
src/hooks/useSettings.ts
+1 −1
| @@ -8,7 +8,7 @@ export interface OllamaSettings { |
| 8 | |
8 | |
| 9 | const DEFAULTS: OllamaSettings = { |
9 | const DEFAULTS: OllamaSettings = { |
| 10 | enabled: false, |
10 | enabled: false, |
| 11 | baseUrl: 'http://localhost:11434', |
11 | baseUrl: '', // empty = same-origin proxy (/api/ via nginx); set to http://localhost:11434 for local dev |
| 12 | model: 'llama3.2', |
12 | model: 'llama3.2', |
| 13 | }; |
13 | }; |
| 14 | |
14 | |