diff --git a/src/lib/providers.ts b/src/lib/providers.ts index bce1d15..da60376 100644 --- a/src/lib/providers.ts +++ b/src/lib/providers.ts @@ -10,6 +10,19 @@ import { } from '../config'; import logger from '../utils/logger'; +function getOllamaHeaders() { + const ollamaAuthHeader = getOllamaAuthHeader(); + let headers; + if (typeof ollamaAuthHeader !== undefined) { + return { + 'Content-Type': 'application/json', + 'Authorization': ollamaAuthHeader + }; + } else { + return { 'Content-Type': 'application/json' }; + } +} + export const getAvailableChatModelProviders = async () => { const openAIApiKey = getOpenaiApiKey(); const groqApiKey = getGroqApiKey(); @@ -97,17 +110,8 @@ export const getAvailableChatModelProviders = async () => { } if (ollamaEndpoint) { - let headers; - if (typeof ollamaAuthHeader !== undefined) { - headers = { - 'Content-Type': 'application/json', - 'Authorization': ollamaAuthHeader - }; - } else { - headers = { 'Content-Type': 'application/json' }; - } - try { + const headers = getOllamaHeaders(); const response = await fetch(`${ollamaEndpoint}/api/tags`, { headers }); const { models: ollamaModels } = (await response.json()) as any; @@ -133,6 +137,7 @@ export const getAvailableChatModelProviders = async () => { export const getAvailableEmbeddingModelProviders = async () => { const openAIApiKey = getOpenaiApiKey(); const ollamaEndpoint = getOllamaApiEndpoint(); + const ollamaAuthHeader = getOllamaAuthHeader(); const models = {}; @@ -154,13 +159,9 @@ export const getAvailableEmbeddingModelProviders = async () => { } if (ollamaEndpoint) { + const headers = getOllamaHeaders(); try { - const response = await fetch(`${ollamaEndpoint}/api/tags`, { - headers: { - 'Content-Type': 'application/json', - }, - }); - + const response = await fetch(`${ollamaEndpoint}/api/tags`, { headers }); const { models: ollamaModels } = (await response.json()) as any; models['ollama'] = ollamaModels.reduce((acc, model) => {