From ce6c0e820f1b9d9d91ffc18baa03c5b6cf95b3b6 Mon Sep 17 00:00:00 2001 From: Anirban Kar Date: Sun, 22 Dec 2024 01:22:29 +0530 Subject: [PATCH 1/2] fix: ollama base url hotfix --- app/lib/modules/llm/providers/ollama.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/lib/modules/llm/providers/ollama.ts b/app/lib/modules/llm/providers/ollama.ts index ebe6b1b1a..e202a102d 100644 --- a/app/lib/modules/llm/providers/ollama.ts +++ b/app/lib/modules/llm/providers/ollama.ts @@ -81,13 +81,23 @@ export default class OllamaProvider extends BaseProvider { providerSettings?: Record; }) => LanguageModelV1 = (options) => { const { apiKeys, providerSettings, serverEnv, model } = options; - const { baseUrl } = this.getProviderBaseUrlAndKey({ + let { baseUrl } = this.getProviderBaseUrlAndKey({ apiKeys, providerSettings, serverEnv: serverEnv as any, defaultBaseUrlKey: 'OLLAMA_API_BASE_URL', defaultApiTokenKey: '', }); + + // Check if we're not in the browser + if (typeof window === 'undefined') { + // Backend: Check if we're running in Docker + const isDocker = process.env.RUNNING_IN_DOCKER === 'true'; + + baseUrl = isDocker ? baseUrl.replace('localhost', 'host.docker.internal') : baseUrl; + baseUrl = isDocker ? baseUrl.replace('127.0.0.1', 'host.docker.internal') : baseUrl; + } + const ollamaInstance = ollama(model, { numCtx: DEFAULT_NUM_CTX, }) as LanguageModelV1 & { config: any }; From 497831addcfe6e4d1c3adb3a7b6d867b7e8510e3 Mon Sep 17 00:00:00 2001 From: Anirban Kar Date: Sun, 22 Dec 2024 01:24:08 +0530 Subject: [PATCH 2/2] cleanup logic --- app/lib/modules/llm/providers/ollama.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/app/lib/modules/llm/providers/ollama.ts b/app/lib/modules/llm/providers/ollama.ts index e202a102d..2c99be3cf 100644 --- a/app/lib/modules/llm/providers/ollama.ts +++ b/app/lib/modules/llm/providers/ollama.ts @@ -89,14 +89,11 @@ export default class OllamaProvider extends BaseProvider { defaultApiTokenKey: '', }); - // Check if we're not in the browser - if (typeof window === 'undefined') { - // Backend: Check if we're running in Docker - const isDocker = process.env.RUNNING_IN_DOCKER === 'true'; + // Backend: Check if we're running in Docker + const isDocker = process.env.RUNNING_IN_DOCKER === 'true'; - baseUrl = isDocker ? baseUrl.replace('localhost', 'host.docker.internal') : baseUrl; - baseUrl = isDocker ? baseUrl.replace('127.0.0.1', 'host.docker.internal') : baseUrl; - } + baseUrl = isDocker ? baseUrl.replace('localhost', 'host.docker.internal') : baseUrl; + baseUrl = isDocker ? baseUrl.replace('127.0.0.1', 'host.docker.internal') : baseUrl; const ollamaInstance = ollama(model, { numCtx: DEFAULT_NUM_CTX,