feat(providers): fix loading issues

This commit is contained in:
ItzCrazyKns 2024-07-08 15:39:27 +05:30
parent 3b4b8a8b02
commit 8539ce82ad
No known key found for this signature in database
GPG Key ID: 8162927C7CCE3065
5 changed files with 27 additions and 11 deletions

View File

@ -5,6 +5,8 @@ import logger from '../../utils/logger';
export const loadGroqChatModels = async () => { export const loadGroqChatModels = async () => {
const groqApiKey = getGroqApiKey(); const groqApiKey = getGroqApiKey();
if (!groqApiKey) return {};
try { try {
const chatModels = { const chatModels = {
'LLaMA3 8b': new ChatOpenAI( 'LLaMA3 8b': new ChatOpenAI(

View File

@ -1,7 +1,7 @@
import { loadGroqChatModels } from './groq'; import { loadGroqChatModels } from './groq';
import { loadOllamaChatModels } from './ollama'; import { loadOllamaChatModels, loadOllamaEmbeddingsModels } from './ollama';
import { loadOpenAIChatModels, loadOpenAIEmbeddingsModel } from './openai'; import { loadOpenAIChatModels, loadOpenAIEmbeddingsModels } from './openai';
import { loadTransformersEmbeddingsModel } from './transformers'; import { loadTransformersEmbeddingsModels } from './transformers';
const chatModelProviders = { const chatModelProviders = {
openai: loadOpenAIChatModels, openai: loadOpenAIChatModels,
@ -10,16 +10,19 @@ const chatModelProviders = {
}; };
const embeddingModelProviders = { const embeddingModelProviders = {
openai: loadOpenAIEmbeddingsModel, openai: loadOpenAIEmbeddingsModels,
local: loadTransformersEmbeddingsModel, local: loadTransformersEmbeddingsModels,
ollama: loadOllamaChatModels, ollama: loadOllamaEmbeddingsModels,
}; };
export const getAvailableChatModelProviders = async () => { export const getAvailableChatModelProviders = async () => {
const models = {}; const models = {};
for (const provider in chatModelProviders) { for (const provider in chatModelProviders) {
models[provider] = await chatModelProviders[provider](); const providerModels = await chatModelProviders[provider]();
if (Object.keys(providerModels).length > 0) {
models[provider] = providerModels
}
} }
models['custom_openai'] = {} models['custom_openai'] = {}
@ -31,7 +34,10 @@ export const getAvailableEmbeddingModelProviders = async () => {
const models = {}; const models = {};
for (const provider in embeddingModelProviders) { for (const provider in embeddingModelProviders) {
models[provider] = await embeddingModelProviders[provider](); const providerModels = await embeddingModelProviders[provider]();
if (Object.keys(providerModels).length > 0) {
models[provider] = providerModels
}
} }
return models; return models;

View File

@ -6,6 +6,8 @@ import { ChatOllama } from '@langchain/community/chat_models/ollama';
export const loadOllamaChatModels = async () => { export const loadOllamaChatModels = async () => {
const ollamaEndpoint = getOllamaApiEndpoint(); const ollamaEndpoint = getOllamaApiEndpoint();
if (!ollamaEndpoint) return {};
try { try {
const response = await fetch(`${ollamaEndpoint}/api/tags`, { const response = await fetch(`${ollamaEndpoint}/api/tags`, {
headers: { headers: {
@ -31,9 +33,11 @@ export const loadOllamaChatModels = async () => {
} }
}; };
export const loadOpenAIEmbeddingsModel = async () => { export const loadOllamaEmbeddingsModels = async () => {
const ollamaEndpoint = getOllamaApiEndpoint(); const ollamaEndpoint = getOllamaApiEndpoint();
if (!ollamaEndpoint) return {};
try { try {
const response = await fetch(`${ollamaEndpoint}/api/tags`, { const response = await fetch(`${ollamaEndpoint}/api/tags`, {
headers: { headers: {

View File

@ -5,6 +5,8 @@ import logger from '../../utils/logger';
export const loadOpenAIChatModels = async () => { export const loadOpenAIChatModels = async () => {
const openAIApiKey = getOpenaiApiKey(); const openAIApiKey = getOpenaiApiKey();
if (!openAIApiKey) return {};
try { try {
const chatModels = { const chatModels = {
'GPT-3.5 turbo': new ChatOpenAI({ 'GPT-3.5 turbo': new ChatOpenAI({
@ -36,9 +38,11 @@ export const loadOpenAIChatModels = async () => {
} }
}; };
export const loadOpenAIEmbeddingsModel = async () => { export const loadOpenAIEmbeddingsModels = async () => {
const openAIApiKey = getOpenaiApiKey(); const openAIApiKey = getOpenaiApiKey();
if (!openAIApiKey) return {};
try { try {
const embeddingModels = { const embeddingModels = {
'Text embedding 3 small': new OpenAIEmbeddings({ 'Text embedding 3 small': new OpenAIEmbeddings({

View File

@ -1,7 +1,7 @@
import logger from '../../utils/logger'; import logger from '../../utils/logger';
import { HuggingFaceTransformersEmbeddings } from '../huggingfaceTransformer'; import { HuggingFaceTransformersEmbeddings } from '../huggingfaceTransformer';
export const loadTransformersEmbeddingsModel = async () => { export const loadTransformersEmbeddingsModels = async () => {
try { try {
const embeddingModels = { const embeddingModels = {
'BGE Small': new HuggingFaceTransformersEmbeddings({ 'BGE Small': new HuggingFaceTransformersEmbeddings({