mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 00:40:14 +01:00
refactor: Use librechat-data-provider app-wide 🔄 (#1326)
* chore: bump vite, vitejs/plugin-react, mark client package as esm, move react-query as a peer dep in data-provider * chore: import changes due to new data-provider export strategy, also fix type imports where applicable * chore: export react-query services as separate to avoid react dependencies in /api/ * chore: suppress sourcemap warnings and polyfill node:path which is used by filenamify TODO: replace filenamify with an alternative and REMOVE polyfill * chore: /api/ changes to support `librechat-data-provider` * refactor: rewrite Dockerfile.multi in light of /api/ changes to support `librechat-data-provider` * chore: remove volume mapping to node_modules directories in default compose file * chore: remove schemas from /api/ as is no longer needed with use of `librechat-data-provider` * fix(ci): jest `librechat-data-provider/react-query` module resolution
This commit is contained in:
parent
d4c846b543
commit
df1dfa7d46
97 changed files with 1831 additions and 1343 deletions
|
|
@ -1,6 +1,6 @@
|
|||
const Anthropic = require('@anthropic-ai/sdk');
|
||||
const { encoding_for_model: encodingForModel, get_encoding: getEncoding } = require('tiktoken');
|
||||
const { getResponseSender, EModelEndpoint } = require('~/server/services/Endpoints');
|
||||
const { getResponseSender, EModelEndpoint } = require('librechat-data-provider');
|
||||
const { getModelMaxTokens } = require('~/utils');
|
||||
const BaseClient = require('./BaseClient');
|
||||
|
||||
|
|
|
|||
|
|
@ -4,11 +4,7 @@ const { GoogleVertexAI } = require('langchain/llms/googlevertexai');
|
|||
const { ChatGoogleVertexAI } = require('langchain/chat_models/googlevertexai');
|
||||
const { AIMessage, HumanMessage, SystemMessage } = require('langchain/schema');
|
||||
const { encoding_for_model: encodingForModel, get_encoding: getEncoding } = require('tiktoken');
|
||||
const {
|
||||
getResponseSender,
|
||||
EModelEndpoint,
|
||||
endpointSettings,
|
||||
} = require('~/server/services/Endpoints');
|
||||
const { getResponseSender, EModelEndpoint, endpointSettings } = require('librechat-data-provider');
|
||||
const { getModelMaxTokens } = require('~/utils');
|
||||
const { formatMessage } = require('./prompts');
|
||||
const BaseClient = require('./BaseClient');
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
const OpenAI = require('openai');
|
||||
const { HttpsProxyAgent } = require('https-proxy-agent');
|
||||
const { encoding_for_model: encodingForModel, get_encoding: getEncoding } = require('tiktoken');
|
||||
const { getResponseSender, EModelEndpoint } = require('~/server/services/Endpoints');
|
||||
const { getResponseSender, EModelEndpoint } = require('librechat-data-provider');
|
||||
const { encodeAndFormat, validateVisionModel } = require('~/server/services/Files/images');
|
||||
const { getModelMaxTokens, genAzureChatCompletion, extractBaseURL } = require('~/utils');
|
||||
const { truncateText, formatMessage, CUT_OFF_PROMPT } = require('./prompts');
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ const { CallbackManager } = require('langchain/callbacks');
|
|||
const { BufferMemory, ChatMessageHistory } = require('langchain/memory');
|
||||
const { initializeCustomAgent, initializeFunctionsAgent } = require('./agents');
|
||||
const { addImages, buildErrorInput, buildPromptPrefix } = require('./output_parsers');
|
||||
const { EModelEndpoint } = require('~/server/services/Endpoints');
|
||||
const { EModelEndpoint } = require('librechat-data-provider');
|
||||
const { formatLangChainMessages } = require('./prompts');
|
||||
const checkBalance = require('~/models/checkBalance');
|
||||
const { SelfReflectionTool } = require('./tools');
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
const { promptTokensEstimate } = require('openai-chat-tokens');
|
||||
const { EModelEndpoint } = require('~/server/services/Endpoints');
|
||||
const { EModelEndpoint } = require('librechat-data-provider');
|
||||
const { formatFromLangChain } = require('~/app/clients/prompts');
|
||||
const checkBalance = require('~/models/checkBalance');
|
||||
const { isEnabled } = require('~/server/utils');
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@
|
|||
"keyv": "^4.5.4",
|
||||
"keyv-file": "^0.2.0",
|
||||
"langchain": "^0.0.186",
|
||||
"librechat-data-provider": "*",
|
||||
"lodash": "^4.17.21",
|
||||
"meilisearch": "^0.33.0",
|
||||
"module-alias": "^2.2.3",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
const { sendMessage, createOnProgress } = require('~/server/utils');
|
||||
const { saveMessage, getConvoTitle, getConvo } = require('~/models');
|
||||
const { getResponseSender } = require('~/server/services/Endpoints');
|
||||
const { getResponseSender } = require('librechat-data-provider');
|
||||
const { createAbortController, handleAbortError } = require('~/server/middleware');
|
||||
|
||||
const AskController = async (req, res, next, initializeClient) => {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
const { sendMessage, createOnProgress } = require('~/server/utils');
|
||||
const { saveMessage, getConvoTitle, getConvo } = require('~/models');
|
||||
const { getResponseSender } = require('~/server/services/Endpoints');
|
||||
const { getResponseSender } = require('librechat-data-provider');
|
||||
const { createAbortController, handleAbortError } = require('~/server/middleware');
|
||||
|
||||
const EditController = async (req, res, next, initializeClient) => {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ const openAI = require('~/server/services/Endpoints/openAI');
|
|||
const google = require('~/server/services/Endpoints/google');
|
||||
const anthropic = require('~/server/services/Endpoints/anthropic');
|
||||
const gptPlugins = require('~/server/services/Endpoints/gptPlugins');
|
||||
const { parseConvo, EModelEndpoint } = require('~/server/services/Endpoints');
|
||||
const { parseConvo, EModelEndpoint } = require('librechat-data-provider');
|
||||
|
||||
const buildFunction = {
|
||||
[EModelEndpoint.openAI]: openAI.buildOptions,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
const crypto = require('crypto');
|
||||
const { saveMessage } = require('~/models');
|
||||
const { sendMessage, sendError } = require('~/server/utils');
|
||||
const { getResponseSender } = require('~/server/services/Endpoints');
|
||||
const { getResponseSender } = require('librechat-data-provider');
|
||||
|
||||
/**
|
||||
* Denies a request by sending an error message and optionally saves the user's message.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const { getResponseSender } = require('~/server/services/Endpoints');
|
||||
const { getResponseSender } = require('librechat-data-provider');
|
||||
const { validateTools } = require('~/app');
|
||||
const { addTitle } = require('~/server/services/Endpoints/openAI');
|
||||
const { initializeClient } = require('~/server/services/Endpoints/gptPlugins');
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ const anthropic = require('./anthropic');
|
|||
const gptPlugins = require('./gptPlugins');
|
||||
const askChatGPTBrowser = require('./askChatGPTBrowser');
|
||||
const { isEnabled } = require('~/server/utils');
|
||||
const { EModelEndpoint } = require('~/server/services/Endpoints');
|
||||
const { EModelEndpoint } = require('librechat-data-provider');
|
||||
const {
|
||||
uaParser,
|
||||
checkBan,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ const express = require('express');
|
|||
const router = express.Router();
|
||||
const { sendMessage, createOnProgress } = require('~/server/utils');
|
||||
const { saveMessage, getConvoTitle, getConvo } = require('~/models');
|
||||
const { getResponseSender } = require('~/server/services/Endpoints');
|
||||
const { getResponseSender } = require('librechat-data-provider');
|
||||
const { addTitle, initializeClient } = require('~/server/services/Endpoints/openAI');
|
||||
const {
|
||||
handleAbort,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ const express = require('express');
|
|||
const router = express.Router();
|
||||
const { validateTools } = require('~/app');
|
||||
const { saveMessage, getConvoTitle, getConvo } = require('~/models');
|
||||
const { getResponseSender } = require('~/server/services/Endpoints');
|
||||
const { getResponseSender } = require('librechat-data-provider');
|
||||
const { initializeClient } = require('~/server/services/Endpoints/gptPlugins');
|
||||
const { sendMessage, createOnProgress, formatSteps, formatAction } = require('~/server/utils');
|
||||
const {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ const google = require('./google');
|
|||
const anthropic = require('./anthropic');
|
||||
const gptPlugins = require('./gptPlugins');
|
||||
const { isEnabled } = require('~/server/utils');
|
||||
const { EModelEndpoint } = require('~/server/services/Endpoints');
|
||||
const { EModelEndpoint } = require('librechat-data-provider');
|
||||
const {
|
||||
checkBan,
|
||||
uaParser,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const { getResponseSender } = require('~/server/services/Endpoints');
|
||||
const { getResponseSender } = require('librechat-data-provider');
|
||||
const { initializeClient } = require('~/server/services/Endpoints/openAI');
|
||||
const { saveMessage, getConvoTitle, getConvo } = require('~/models');
|
||||
const { sendMessage, createOnProgress } = require('~/server/utils');
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
const { EModelEndpoint } = require('~/server/services/Endpoints');
|
||||
const { EModelEndpoint } = require('librechat-data-provider');
|
||||
|
||||
const {
|
||||
OPENAI_API_KEY: openAIApiKey,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
const { EModelEndpoint } = require('~/server/services/Endpoints');
|
||||
const { EModelEndpoint } = require('librechat-data-provider');
|
||||
const loadAsyncEndpoints = require('./loadAsyncEndpoints');
|
||||
const { config } = require('./EndpointService');
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ const {
|
|||
getChatGPTBrowserModels,
|
||||
getAnthropicModels,
|
||||
} = require('~/server/services/ModelService');
|
||||
const { EModelEndpoint } = require('~/server/services/Endpoints');
|
||||
const { EModelEndpoint } = require('librechat-data-provider');
|
||||
const { useAzurePlugins } = require('~/server/services/Config/EndpointService').config;
|
||||
|
||||
const fitlerAssistantModels = (str) => {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
const { GoogleClient } = require('~/app');
|
||||
const { EModelEndpoint } = require('~/server/services/Endpoints');
|
||||
const { EModelEndpoint } = require('librechat-data-provider');
|
||||
const { getUserKey, checkUserKeyExpiry } = require('~/server/services/UserService');
|
||||
|
||||
const initializeClient = async ({ req, res, endpointOption }) => {
|
||||
|
|
|
|||
|
|
@ -1,5 +0,0 @@
|
|||
const schemas = require('./schemas');
|
||||
|
||||
module.exports = {
|
||||
...schemas,
|
||||
};
|
||||
|
|
@ -1,445 +0,0 @@
|
|||
const { z } = require('zod');
|
||||
|
||||
const EModelEndpoint = {
|
||||
azureOpenAI: 'azureOpenAI',
|
||||
openAI: 'openAI',
|
||||
bingAI: 'bingAI',
|
||||
chatGPTBrowser: 'chatGPTBrowser',
|
||||
google: 'google',
|
||||
gptPlugins: 'gptPlugins',
|
||||
anthropic: 'anthropic',
|
||||
assistant: 'assistant',
|
||||
};
|
||||
|
||||
const alternateName = {
|
||||
[EModelEndpoint.openAI]: 'OpenAI',
|
||||
[EModelEndpoint.assistant]: 'Assistants',
|
||||
[EModelEndpoint.azureOpenAI]: 'Azure OpenAI',
|
||||
[EModelEndpoint.bingAI]: 'Bing',
|
||||
[EModelEndpoint.chatGPTBrowser]: 'ChatGPT',
|
||||
[EModelEndpoint.gptPlugins]: 'Plugins',
|
||||
[EModelEndpoint.google]: 'Google',
|
||||
[EModelEndpoint.anthropic]: 'Anthropic',
|
||||
};
|
||||
|
||||
const endpointSettings = {
|
||||
[EModelEndpoint.google]: {
|
||||
model: {
|
||||
default: 'chat-bison',
|
||||
},
|
||||
maxOutputTokens: {
|
||||
min: 1,
|
||||
max: 2048,
|
||||
step: 1,
|
||||
default: 1024,
|
||||
},
|
||||
temperature: {
|
||||
min: 0,
|
||||
max: 1,
|
||||
step: 0.01,
|
||||
default: 0.2,
|
||||
},
|
||||
topP: {
|
||||
min: 0,
|
||||
max: 1,
|
||||
step: 0.01,
|
||||
default: 0.8,
|
||||
},
|
||||
topK: {
|
||||
min: 1,
|
||||
max: 40,
|
||||
step: 0.01,
|
||||
default: 40,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const google = endpointSettings[EModelEndpoint.google];
|
||||
|
||||
const supportsFiles = {
|
||||
[EModelEndpoint.openAI]: true,
|
||||
[EModelEndpoint.assistant]: true,
|
||||
};
|
||||
|
||||
const openAIModels = [
|
||||
'gpt-3.5-turbo-16k-0613',
|
||||
'gpt-3.5-turbo-16k',
|
||||
'gpt-4-1106-preview',
|
||||
'gpt-3.5-turbo',
|
||||
'gpt-3.5-turbo-1106',
|
||||
'gpt-4-vision-preview',
|
||||
'gpt-4',
|
||||
'gpt-3.5-turbo-instruct-0914',
|
||||
'gpt-3.5-turbo-0613',
|
||||
'gpt-3.5-turbo-0301',
|
||||
'gpt-3.5-turbo-instruct',
|
||||
'gpt-4-0613',
|
||||
'text-davinci-003',
|
||||
'gpt-4-0314',
|
||||
];
|
||||
|
||||
const visionModels = ['gpt-4-vision', 'llava-13b'];
|
||||
|
||||
const eModelEndpointSchema = z.nativeEnum(EModelEndpoint);
|
||||
|
||||
const tPluginAuthConfigSchema = z.object({
|
||||
authField: z.string(),
|
||||
label: z.string(),
|
||||
description: z.string(),
|
||||
});
|
||||
|
||||
const tPluginSchema = z.object({
|
||||
name: z.string(),
|
||||
pluginKey: z.string(),
|
||||
description: z.string(),
|
||||
icon: z.string(),
|
||||
authConfig: z.array(tPluginAuthConfigSchema),
|
||||
authenticated: z.boolean().optional(),
|
||||
isButton: z.boolean().optional(),
|
||||
});
|
||||
|
||||
const tExampleSchema = z.object({
|
||||
input: z.object({
|
||||
content: z.string(),
|
||||
}),
|
||||
output: z.object({
|
||||
content: z.string(),
|
||||
}),
|
||||
});
|
||||
|
||||
const tAgentOptionsSchema = z.object({
|
||||
agent: z.string(),
|
||||
skipCompletion: z.boolean(),
|
||||
model: z.string(),
|
||||
temperature: z.number(),
|
||||
});
|
||||
|
||||
const tConversationSchema = z.object({
|
||||
conversationId: z.string().nullable(),
|
||||
title: z.string().nullable().or(z.literal('New Chat')).default('New Chat'),
|
||||
user: z.string().optional(),
|
||||
endpoint: eModelEndpointSchema.nullable(),
|
||||
suggestions: z.array(z.string()).optional(),
|
||||
messages: z.array(z.string()).optional(),
|
||||
tools: z.array(tPluginSchema).optional(),
|
||||
createdAt: z.string(),
|
||||
updatedAt: z.string(),
|
||||
systemMessage: z.string().nullable().optional(),
|
||||
modelLabel: z.string().nullable().optional(),
|
||||
examples: z.array(tExampleSchema).optional(),
|
||||
chatGptLabel: z.string().nullable().optional(),
|
||||
userLabel: z.string().optional(),
|
||||
model: z.string().nullable().optional(),
|
||||
promptPrefix: z.string().nullable().optional(),
|
||||
temperature: z.number().optional(),
|
||||
topP: z.number().optional(),
|
||||
topK: z.number().optional(),
|
||||
context: z.string().nullable().optional(),
|
||||
top_p: z.number().optional(),
|
||||
frequency_penalty: z.number().optional(),
|
||||
presence_penalty: z.number().optional(),
|
||||
jailbreak: z.boolean().optional(),
|
||||
jailbreakConversationId: z.string().nullable().optional(),
|
||||
conversationSignature: z.string().nullable().optional(),
|
||||
parentMessageId: z.string().optional(),
|
||||
clientId: z.string().nullable().optional(),
|
||||
invocationId: z.number().nullable().optional(),
|
||||
toneStyle: z.string().nullable().optional(),
|
||||
maxOutputTokens: z.number().optional(),
|
||||
agentOptions: tAgentOptionsSchema.nullable().optional(),
|
||||
});
|
||||
|
||||
const openAISchema = tConversationSchema
|
||||
.pick({
|
||||
model: true,
|
||||
chatGptLabel: true,
|
||||
promptPrefix: true,
|
||||
temperature: true,
|
||||
top_p: true,
|
||||
presence_penalty: true,
|
||||
frequency_penalty: true,
|
||||
})
|
||||
.transform((obj) => ({
|
||||
...obj,
|
||||
model: obj.model ?? 'gpt-3.5-turbo',
|
||||
chatGptLabel: obj.chatGptLabel ?? null,
|
||||
promptPrefix: obj.promptPrefix ?? null,
|
||||
temperature: obj.temperature ?? 1,
|
||||
top_p: obj.top_p ?? 1,
|
||||
presence_penalty: obj.presence_penalty ?? 0,
|
||||
frequency_penalty: obj.frequency_penalty ?? 0,
|
||||
}))
|
||||
.catch(() => ({
|
||||
model: 'gpt-3.5-turbo',
|
||||
chatGptLabel: null,
|
||||
promptPrefix: null,
|
||||
temperature: 1,
|
||||
top_p: 1,
|
||||
presence_penalty: 0,
|
||||
frequency_penalty: 0,
|
||||
}));
|
||||
|
||||
const googleSchema = tConversationSchema
|
||||
.pick({
|
||||
model: true,
|
||||
modelLabel: true,
|
||||
promptPrefix: true,
|
||||
examples: true,
|
||||
temperature: true,
|
||||
maxOutputTokens: true,
|
||||
topP: true,
|
||||
topK: true,
|
||||
})
|
||||
.transform((obj) => ({
|
||||
...obj,
|
||||
model: obj.model ?? google.model.default,
|
||||
modelLabel: obj.modelLabel ?? null,
|
||||
promptPrefix: obj.promptPrefix ?? null,
|
||||
examples: obj.examples ?? [{ input: { content: '' }, output: { content: '' } }],
|
||||
temperature: obj.temperature ?? google.temperature.default,
|
||||
maxOutputTokens: obj.maxOutputTokens ?? google.maxOutputTokens.default,
|
||||
topP: obj.topP ?? google.topP.default,
|
||||
topK: obj.topK ?? google.topK.default,
|
||||
}))
|
||||
.catch(() => ({
|
||||
model: google.model.default,
|
||||
modelLabel: null,
|
||||
promptPrefix: null,
|
||||
examples: [{ input: { content: '' }, output: { content: '' } }],
|
||||
temperature: google.temperature.default,
|
||||
maxOutputTokens: google.maxOutputTokens.default,
|
||||
topP: google.topP.default,
|
||||
topK: google.topK.default,
|
||||
}));
|
||||
|
||||
const bingAISchema = tConversationSchema
|
||||
.pick({
|
||||
jailbreak: true,
|
||||
systemMessage: true,
|
||||
context: true,
|
||||
toneStyle: true,
|
||||
jailbreakConversationId: true,
|
||||
conversationSignature: true,
|
||||
clientId: true,
|
||||
invocationId: true,
|
||||
})
|
||||
.transform((obj) => ({
|
||||
...obj,
|
||||
model: '',
|
||||
jailbreak: obj.jailbreak ?? false,
|
||||
systemMessage: obj.systemMessage ?? null,
|
||||
context: obj.context ?? null,
|
||||
toneStyle: obj.toneStyle ?? 'creative',
|
||||
jailbreakConversationId: obj.jailbreakConversationId ?? null,
|
||||
conversationSignature: obj.conversationSignature ?? null,
|
||||
clientId: obj.clientId ?? null,
|
||||
invocationId: obj.invocationId ?? 1,
|
||||
}))
|
||||
.catch(() => ({
|
||||
model: '',
|
||||
jailbreak: false,
|
||||
systemMessage: null,
|
||||
context: null,
|
||||
toneStyle: 'creative',
|
||||
jailbreakConversationId: null,
|
||||
conversationSignature: null,
|
||||
clientId: null,
|
||||
invocationId: 1,
|
||||
}));
|
||||
|
||||
const anthropicSchema = tConversationSchema
|
||||
.pick({
|
||||
model: true,
|
||||
modelLabel: true,
|
||||
promptPrefix: true,
|
||||
temperature: true,
|
||||
maxOutputTokens: true,
|
||||
topP: true,
|
||||
topK: true,
|
||||
})
|
||||
.transform((obj) => ({
|
||||
...obj,
|
||||
model: obj.model ?? 'claude-1',
|
||||
modelLabel: obj.modelLabel ?? null,
|
||||
promptPrefix: obj.promptPrefix ?? null,
|
||||
temperature: obj.temperature ?? 1,
|
||||
maxOutputTokens: obj.maxOutputTokens ?? 4000,
|
||||
topP: obj.topP ?? 0.7,
|
||||
topK: obj.topK ?? 5,
|
||||
}))
|
||||
.catch(() => ({
|
||||
model: 'claude-1',
|
||||
modelLabel: null,
|
||||
promptPrefix: null,
|
||||
temperature: 1,
|
||||
maxOutputTokens: 4000,
|
||||
topP: 0.7,
|
||||
topK: 5,
|
||||
}));
|
||||
|
||||
const chatGPTBrowserSchema = tConversationSchema
|
||||
.pick({
|
||||
model: true,
|
||||
})
|
||||
.transform((obj) => ({
|
||||
...obj,
|
||||
model: obj.model ?? 'text-davinci-002-render-sha',
|
||||
}))
|
||||
.catch(() => ({
|
||||
model: 'text-davinci-002-render-sha',
|
||||
}));
|
||||
|
||||
const gptPluginsSchema = tConversationSchema
|
||||
.pick({
|
||||
model: true,
|
||||
chatGptLabel: true,
|
||||
promptPrefix: true,
|
||||
temperature: true,
|
||||
top_p: true,
|
||||
presence_penalty: true,
|
||||
frequency_penalty: true,
|
||||
tools: true,
|
||||
agentOptions: true,
|
||||
})
|
||||
.transform((obj) => ({
|
||||
...obj,
|
||||
model: obj.model ?? 'gpt-3.5-turbo',
|
||||
chatGptLabel: obj.chatGptLabel ?? null,
|
||||
promptPrefix: obj.promptPrefix ?? null,
|
||||
temperature: obj.temperature ?? 0.8,
|
||||
top_p: obj.top_p ?? 1,
|
||||
presence_penalty: obj.presence_penalty ?? 0,
|
||||
frequency_penalty: obj.frequency_penalty ?? 0,
|
||||
tools: obj.tools ?? [],
|
||||
agentOptions: obj.agentOptions ?? {
|
||||
agent: 'functions',
|
||||
skipCompletion: true,
|
||||
model: 'gpt-3.5-turbo',
|
||||
temperature: 0,
|
||||
},
|
||||
}))
|
||||
.catch(() => ({
|
||||
model: 'gpt-3.5-turbo',
|
||||
chatGptLabel: null,
|
||||
promptPrefix: null,
|
||||
temperature: 0.8,
|
||||
top_p: 1,
|
||||
presence_penalty: 0,
|
||||
frequency_penalty: 0,
|
||||
tools: [],
|
||||
agentOptions: {
|
||||
agent: 'functions',
|
||||
skipCompletion: true,
|
||||
model: 'gpt-3.5-turbo',
|
||||
temperature: 0,
|
||||
},
|
||||
}));
|
||||
|
||||
const assistantSchema = tConversationSchema
|
||||
.pick({
|
||||
model: true,
|
||||
assistant_id: true,
|
||||
thread_id: true,
|
||||
})
|
||||
.transform((obj) => {
|
||||
const newObj = { ...obj };
|
||||
Object.keys(newObj).forEach((key) => {
|
||||
const value = newObj[key];
|
||||
if (value === undefined || value === null) {
|
||||
delete newObj[key];
|
||||
}
|
||||
});
|
||||
return newObj;
|
||||
})
|
||||
.catch(() => ({}));
|
||||
|
||||
const endpointSchemas = {
|
||||
[EModelEndpoint.openAI]: openAISchema,
|
||||
[EModelEndpoint.assistant]: assistantSchema,
|
||||
[EModelEndpoint.azureOpenAI]: openAISchema,
|
||||
[EModelEndpoint.google]: googleSchema,
|
||||
[EModelEndpoint.bingAI]: bingAISchema,
|
||||
[EModelEndpoint.anthropic]: anthropicSchema,
|
||||
[EModelEndpoint.chatGPTBrowser]: chatGPTBrowserSchema,
|
||||
[EModelEndpoint.gptPlugins]: gptPluginsSchema,
|
||||
};
|
||||
|
||||
function getFirstDefinedValue(possibleValues) {
|
||||
let returnValue;
|
||||
for (const value of possibleValues) {
|
||||
if (value) {
|
||||
returnValue = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
const parseConvo = (endpoint, conversation, possibleValues) => {
|
||||
const schema = endpointSchemas[endpoint];
|
||||
|
||||
if (!schema) {
|
||||
throw new Error(`Unknown endpoint: ${endpoint}`);
|
||||
}
|
||||
|
||||
const convo = schema.parse(conversation);
|
||||
|
||||
if (possibleValues && convo) {
|
||||
convo.model = getFirstDefinedValue(possibleValues.model) ?? convo.model;
|
||||
}
|
||||
|
||||
return convo;
|
||||
};
|
||||
|
||||
const getResponseSender = (endpointOption) => {
|
||||
const { model, endpoint, chatGptLabel, modelLabel, jailbreak } = endpointOption;
|
||||
|
||||
if (
|
||||
[
|
||||
EModelEndpoint.openAI,
|
||||
EModelEndpoint.azureOpenAI,
|
||||
EModelEndpoint.gptPlugins,
|
||||
EModelEndpoint.chatGPTBrowser,
|
||||
].includes(endpoint)
|
||||
) {
|
||||
if (chatGptLabel) {
|
||||
return chatGptLabel;
|
||||
} else if (model && model.includes('gpt-3')) {
|
||||
return 'GPT-3.5';
|
||||
} else if (model && model.includes('gpt-4')) {
|
||||
return 'GPT-4';
|
||||
}
|
||||
return alternateName[endpoint] ?? 'ChatGPT';
|
||||
}
|
||||
|
||||
if (endpoint === EModelEndpoint.bingAI) {
|
||||
return jailbreak ? 'Sydney' : 'BingAI';
|
||||
}
|
||||
|
||||
if (endpoint === EModelEndpoint.anthropic) {
|
||||
return modelLabel ?? 'Claude';
|
||||
}
|
||||
|
||||
if (endpoint === EModelEndpoint.google) {
|
||||
if (modelLabel) {
|
||||
return modelLabel;
|
||||
} else if (model && model.includes('code')) {
|
||||
return 'Codey';
|
||||
}
|
||||
|
||||
return 'PaLM2';
|
||||
}
|
||||
|
||||
return '';
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
parseConvo,
|
||||
getResponseSender,
|
||||
EModelEndpoint,
|
||||
supportsFiles,
|
||||
openAIModels,
|
||||
visionModels,
|
||||
alternateName,
|
||||
endpointSettings,
|
||||
};
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
const { visionModels } = require('~/server/services/Endpoints');
|
||||
const { visionModels } = require('librechat-data-provider');
|
||||
|
||||
function validateVisionModel(model) {
|
||||
if (!model) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
const { EModelEndpoint } = require('~/server/services/Endpoints');
|
||||
const { EModelEndpoint } = require('librechat-data-provider');
|
||||
|
||||
const models = [
|
||||
'text-davinci-003',
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
const { EModelEndpoint } = require('~/server/services/Endpoints');
|
||||
const { EModelEndpoint } = require('librechat-data-provider');
|
||||
const { getModelMaxTokens, matchModelName, maxTokensMap } = require('./tokens');
|
||||
|
||||
describe('getModelMaxTokens', () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue