From e9cebb481064abfb24210a58adf04547542a3e77 Mon Sep 17 00:00:00 2001 From: Collin <69058468+CollinCashio@users.noreply.github.com> Date: Fri, 9 Feb 2024 13:25:29 -0600 Subject: [PATCH] Ollama-JS Request Headers Fix (#830) * add basic auth to ollama llm * revert btoa api-key change in favor of request headers * remove unnecessary async --------- Co-authored-by: Collin Cashio --- core/llm/llms/Ollama.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/core/llm/llms/Ollama.ts b/core/llm/llms/Ollama.ts index d54e0d8fd..1e2fa32aa 100644 --- a/core/llm/llms/Ollama.ts +++ b/core/llm/llms/Ollama.ts @@ -24,6 +24,7 @@ class Ollama extends BaseLLM { } this.fetch(`${this.apiBase}/api/show`, { method: "POST", + headers: {}, body: JSON.stringify({ name: this._getModel() }), }).then(async (response) => { if (response.status !== 200) { @@ -177,6 +178,16 @@ class Ollama extends BaseLLM { ): AsyncGenerator { const client = new ollama.Ollama({ host: this.apiBase, + + fetch: (input, config) => { + return fetch(input, { + ...config, + headers: { + ...(config?.headers || {}), + ...(this.requestOptions?.headers || {}) + } + }); + } }); const response = await client.chat({ ...this._convertArgs(options, messages),