also auth on embeddings

This commit is contained in:
projectmoon 2024-06-29 11:07:11 +02:00
parent 2e17e31c18
commit 3bbe03cb9c
1 changed files with 17 additions and 16 deletions

View File

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