| | const path = require('path'); |
| | const { logger } = require('@librechat/data-schemas'); |
| | const { EModelEndpoint } = require('librechat-data-provider'); |
| | const { loadServiceKey, isUserProvided } = require('@librechat/api'); |
| | const { config } = require('./EndpointService'); |
| |
|
| | const { openAIApiKey, azureOpenAIApiKey, useAzurePlugins, userProvidedOpenAI, googleKey } = config; |
| |
|
| | |
| | |
| | |
| | |
| | async function loadAsyncEndpoints(appConfig) { |
| | let serviceKey, googleUserProvides; |
| |
|
| | |
| | const isGoogleKeyProvided = googleKey && googleKey.trim() !== ''; |
| |
|
| | if (isGoogleKeyProvided) { |
| | |
| | googleUserProvides = isUserProvided(googleKey); |
| | } else { |
| | |
| | const serviceKeyPath = |
| | process.env.GOOGLE_SERVICE_KEY_FILE || path.join(__dirname, '../../..', 'data', 'auth.json'); |
| |
|
| | try { |
| | serviceKey = await loadServiceKey(serviceKeyPath); |
| | } catch (error) { |
| | logger.error('Error loading service key', error); |
| | serviceKey = null; |
| | } |
| | } |
| |
|
| | const google = serviceKey || isGoogleKeyProvided ? { userProvide: googleUserProvides } : false; |
| |
|
| | const useAzure = !!appConfig?.endpoints?.[EModelEndpoint.azureOpenAI]?.plugins; |
| | const gptPlugins = |
| | useAzure || openAIApiKey || azureOpenAIApiKey |
| | ? { |
| | availableAgents: ['classic', 'functions'], |
| | userProvide: useAzure ? false : userProvidedOpenAI, |
| | userProvideURL: useAzure |
| | ? false |
| | : config[EModelEndpoint.openAI]?.userProvideURL || |
| | config[EModelEndpoint.azureOpenAI]?.userProvideURL, |
| | azure: useAzurePlugins || useAzure, |
| | } |
| | : false; |
| |
|
| | return { google, gptPlugins }; |
| | } |
| |
|
| | module.exports = loadAsyncEndpoints; |
| |
|