add openai custom base uri

This commit is contained in:
joe 2024-04-29 16:39:18 +08:00
parent 9b5548e9f8
commit 0b059bb71b
2 changed files with 8 additions and 1 deletions

View file

@ -6,6 +6,7 @@ CHAT_MODEL = "gpt-3.5-turbo" # Name of the model to use
[API_KEYS]
OPENAI = "" # OpenAI API key - sk-1234567890abcdef1234567890abcdef
OPENAI_BASE_URL = "" # Custom Open AI Base URL , may be use cloudflare AI Gateway
[API_ENDPOINTS]
SEARXNG = "http://localhost:32768" # SearxNG API URL

View file

@ -1,10 +1,11 @@
import { ChatOpenAI, OpenAIEmbeddings } from '@langchain/openai';
import { ChatOllama } from '@langchain/community/chat_models/ollama';
import { OllamaEmbeddings } from '@langchain/community/embeddings/ollama';
import { getOllamaApiEndpoint, getOpenaiApiKey } from '../config';
import { getOllamaApiEndpoint, getOpenaiApiBaseUrl, getOpenaiApiKey } from '../config';
export const getAvailableProviders = async () => {
const openAIApiKey = getOpenaiApiKey();
const openAIBaseUrl = getOpenaiApiBaseUrl();
const ollamaEndpoint = getOllamaApiEndpoint();
const models = {};
@ -16,15 +17,20 @@ export const getAvailableProviders = async () => {
openAIApiKey,
modelName: 'gpt-3.5-turbo',
temperature: 0.7,
}),
'gpt-4': new ChatOpenAI({
openAIApiKey,
modelName: 'gpt-4',
temperature: 0.7,
configuration: {
baseURL: openAIBaseUrl,
},
}),
embeddings: new OpenAIEmbeddings({
openAIApiKey,
modelName: 'text-embedding-3-large',
}),
};
} catch (err) {