mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-16 16:30:15 +01:00
* wip: proof of concept for openapi chain * chore(api): update langchain dependency to version 0.0.105 * feat(Plugins): use ChatGPT Plugins/OpenAPI specs (first pass) * chore(manifest.json): update pluginKey for "Browser" tool to "web-browser" chore(handleTools.js): update customConstructor key for "web-browser" tool * fix(handleSubmit.js): set unfinished property to false for all endpoints * fix(handlers.js): remove unnecessary capitalizeWords function and use action.tool directly refactor(endpoints.js): rename availableTools to tools and transform it into a map * feat(endpoints): add plugins selector to endpoints file refactor(CodeBlock.tsx): refactor to typescript refactor(Plugin.tsx): use recoil Map for plugin name and refactor to typescript chore(Message.jsx): linting chore(PluginsOptions/index.jsx): remove comment/linting chore(svg): export Clipboard and CheckMark components from SVG index and refactor to typescript * fix(OpenAPIPlugin.js): rename readYamlFile function to readSpecFile fix(OpenAPIPlugin.js): handle JSON files in readSpecFile function fix(OpenAPIPlugin.js): handle JSON URLs in getSpec function fix(OpenAPIPlugin.js): handle JSON variables in createOpenAPIPlugin function fix(OpenAPIPlugin.js): add description for variables in createOpenAPIPlugin function fix(OpenAPIPlugin.js): add optional flag for is_user_authenticated and has_user_authentication in ManifestDefinition fix(loadSpecs.js): add optional flag for is_user_authenticated and has_user_authentication in ManifestDefinition fix(Plugin.tsx): remove unnecessary callback parameter in getPluginName function fix(getDefaultConversation.js): fix browser console error: handle null value for lastConversationSetup in getDefaultConversation function * feat(api): add new tools Add Ai PDF tool for super-fast, interactive chats with PDFs of any size, complete with page references for fact checking. Add VoxScript tool for searching through YouTube transcripts, financial data sources, Google Search results, and more. Add WebPilot tool for browsing and QA of webpages, PDFs, and data. Generate articles from one or more URLs. feat(api): update OpenAPIPlugin.js - Add support for bearer token authorization in the OpenAPIPlugin. - Add support for custom headers in the OpenAPIPlugin. fix(api): fix loadTools.js - Pass the user parameter to the loadSpecs function. * feat(PluginsClient.js): import findMessageContent function from utils feat(PluginsClient.js): add message parameter to options object in initializeCustomAgent function feat(PluginsClient.js): add content to errorMessage if message content is found feat(PluginsClient.js): break out of loop if message content is found feat(PluginsClient.js): add delay option with value of 8 to generateTextStream function feat(PluginsClient.js): add support for process.env.PORT environment variable in app.listen function feat(askyourpdf.json): add askyourpdf plugin configuration feat(metar.json): add metar plugin configuration feat(askyourpdf.yaml): add askyourpdf plugin OpenAPI specification feat(OpenAPIPlugin.js): add message parameter to createOpenAPIPlugin function feat(OpenAPIPlugin.js): add description_for_model to chain run message feat(addOpenAPISpecs.js): remove verbose option from loadSpecs function call fix(loadSpecs.js): add 'message' parameter to the loadSpecs function feat(findMessageContent.js): add utility function to find message content in JSON objects * fix(PluginStoreDialog.tsx): update z-index value for the dialog container The z-index value for the dialog container was updated to "102" to ensure it appears above other elements on the page. * chore(web_pilot.json): add "params" field with "user_has_request" parameter set to true * chore(eslintrc.js): update eslint rules fix(Login.tsx): add missing semicolon after import statement * fix(package-lock.json): update langchain dependency to version ^0.0.105 * fix(OpenAPIPlugin.js): change header key from 'id' to 'librechat_user_id' for consistency and clarity feat(plugins): add documentation for using official ChatGPT Plugins with OpenAPI specs This commit adds a new file `chatgpt_plugins_openapi.md` to the `docs/features/plugins` directory. The file provides detailed information on how to use official ChatGPT Plugins with OpenAPI specifications. It explains the components of a plugin, including the Plugin Manifest file and the OpenAPI spec. It also covers the process of adding a plugin, editing manifest files, and customizing OpenAPI spec files. Additionally, the commit includes disclaimers about the limitations and compatibility of plugins with LibreChat. The documentation also clarifies that the use of ChatGPT Plugins with LibreChat does not violate OpenAI's Terms of Service. The purpose of this commit is to provide comprehensive documentation for developers who want to integrate ChatGPT Plugins into their projects using OpenAPI specs. It aims to guide them through the process of adding and configuring plugins, as well as addressing potential issues and chore(introduction.md): update link to ChatGPT Plugins documentation docs(introduction.md): clarify the purpose of the plugins endpoint and its capabilities * fix(OpenAPIPlugin.js): update SUFFIX variable to provide a clearer description docs(chatgpt_plugins_openapi.md): update information about adding plugins via url on the frontend * feat(PluginsClient.js): sendIntermediateMessage on successful Agent load fix(PluginsClient.js, server/index.js, gptPlugins.js): linting fixes docs(chatgpt_plugins_openapi.md): update links and add additional information * Update chatgpt_plugins_openapi.md * chore: rebuild package-lock file * chore: format/lint all files with new rules * chore: format all files * chore(README.md): update AI model selection list The AI model selection list in the README.md file has been updated to reflect the current options available. The "Anthropic" model has been added as an alternative name for the "Claude" model. * fix(Plugin.tsx): type issue * feat(tools): add new tool WebPilot feat(tools): remove tool Weather Report feat(tools): add new tool Prompt Perfect feat(tools): add new tool Scholarly Graph Link * feat(OpenAPIPlugin.js): add getSpec and readSpecFile functions feat(OpenAPIPlugin.spec.js): add tests for readSpecFile, getSpec, and createOpenAPIPlugin functions * chore(agent-demo-1.js): remove unused code and dependencies chore(agent-demo-2.js): remove unused code and dependencies chore(demo.js): remove unused code and dependencies * feat(addOpenAPISpecs): add function to transform OpenAPI specs into desired format feat(addOpenAPISpecs.spec): add tests for transformSpec function fix(loadSpecs): remove debugging code * feat(loadSpecs.spec.js): add unit tests for ManifestDefinition, validateJson, and loadSpecs functions * fix: package file resolution bug * chore: move scholarly_graph_link manifest to 'has-issues' * refactor(client/hooks): convert to TS and export from index * Update introduction.md * Update chatgpt_plugins_openapi.md
163 lines
5.4 KiB
JavaScript
163 lines
5.4 KiB
JavaScript
/**
|
|
* Upgrade script
|
|
*/
|
|
const dotenv = require('dotenv');
|
|
const fs = require('fs');
|
|
const { exit } = require('process');
|
|
|
|
// Suppress default warnings
|
|
const originalConsoleWarn = console.warn;
|
|
console.warn = () => {};
|
|
const loader = require('./loader');
|
|
console.warn = originalConsoleWarn;
|
|
|
|
// Old Paths
|
|
const apiEnvPath = loader.resolve('api/.env');
|
|
const clientEnvPath = loader.resolve('client/.env');
|
|
|
|
// Load into env
|
|
dotenv.config({
|
|
path: loader.resolve(apiEnvPath),
|
|
});
|
|
dotenv.config({
|
|
path: loader.resolve(clientEnvPath),
|
|
});
|
|
// JS was doing spooky actions at a distance, lets prevent that
|
|
const initEnv = JSON.parse(JSON.stringify(process.env));
|
|
|
|
// New Paths
|
|
const rootEnvPath = loader.resolve('.env');
|
|
const devEnvPath = loader.resolve('.env.development');
|
|
const prodEnvPath = loader.resolve('.env.production');
|
|
|
|
if (fs.existsSync(rootEnvPath)) {
|
|
console.error('Root env file already exists! Aborting');
|
|
exit(1);
|
|
}
|
|
|
|
// Validate old configs
|
|
if (!fs.existsSync(apiEnvPath)) {
|
|
console.error('Api env doesn\'t exit! Did you mean to run install?');
|
|
exit(1);
|
|
}
|
|
if (!fs.existsSync(clientEnvPath)) {
|
|
console.error('Client env doesn\'t exit! But api/.env does. Manual upgrade required');
|
|
exit(1);
|
|
}
|
|
|
|
/**
|
|
* Refactor the ENV if it has a prod_/dev_ version
|
|
*
|
|
* @param {*} varDev
|
|
* @param {*} varProd
|
|
* @param {*} varName
|
|
*/
|
|
function refactorPairedEnvVar(varDev, varProd, varName) {
|
|
// Lets validate if either of these are undefined, if so lets use the non-undefined one
|
|
if (initEnv[varDev] === undefined && initEnv[varProd] === undefined) {
|
|
console.error(`Both ${varDev} and ${varProd} are undefined! Manual intervention required!`);
|
|
} else if (initEnv[varDev] === undefined) {
|
|
fs.appendFileSync(rootEnvPath, `\n${varName}=${initEnv[varProd]}`);
|
|
} else if (initEnv[varProd] === undefined) {
|
|
fs.appendFileSync(rootEnvPath, `\n${varName}=${initEnv[varDev]}`);
|
|
} else if (initEnv[varDev] === initEnv[varProd]) {
|
|
fs.appendFileSync(rootEnvPath, `\n${varName}=${initEnv[varDev]}`);
|
|
} else {
|
|
fs.appendFileSync(rootEnvPath, `${varName}=${initEnv[varProd]}\n`);
|
|
fs.appendFileSync(devEnvPath, `${varName}=${initEnv[varDev]}\n`);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Upgrade the env files!
|
|
* 1. /api/.env will merge into /.env
|
|
* 2. /client/.env will merge into /.env
|
|
* 3. Any prod_/dev_ keys will be split up into .env.development / .env.production files (if they are different)
|
|
*/
|
|
if (fs.existsSync(apiEnvPath)) {
|
|
fs.copyFileSync(apiEnvPath, rootEnvPath);
|
|
fs.copyFileSync(apiEnvPath, rootEnvPath + '.api.bak');
|
|
fs.unlinkSync(apiEnvPath);
|
|
}
|
|
|
|
// Clean up Domain variables
|
|
fs.appendFileSync(
|
|
rootEnvPath,
|
|
'\n\n##########################\n# Domain Variables:\n# Note: DOMAIN_ vars are passed to vite\n##########################\n',
|
|
);
|
|
refactorPairedEnvVar('CLIENT_URL_DEV', 'CLIENT_URL_PROD', 'DOMAIN_CLIENT');
|
|
refactorPairedEnvVar('SERVER_URL_DEV', 'SERVER_URL_PROD', 'DOMAIN_SERVER');
|
|
|
|
// Remove the old vars
|
|
const removeEnvs = {
|
|
NODE_ENV: 'remove',
|
|
OPENAI_KEY: 'remove',
|
|
CLIENT_URL_DEV: 'remove',
|
|
CLIENT_URL_PROD: 'remove',
|
|
SERVER_URL_DEV: 'remove',
|
|
SERVER_URL_PROD: 'remove',
|
|
JWT_SECRET_DEV: 'remove', // Lets regen
|
|
JWT_SECRET_PROD: 'remove', // Lets regen
|
|
VITE_APP_TITLE: 'remove',
|
|
// Comments to remove:
|
|
'#JWT:': 'remove',
|
|
'# Add a secure secret for production if deploying to live domain.': 'remove',
|
|
'# Site URLs:': 'remove',
|
|
'# Don\'t forget to set Node env to development in the Server configuration section above':
|
|
'remove',
|
|
'# if you want to run in dev mode': 'remove',
|
|
'# Change these values to domain if deploying:': 'remove',
|
|
'# Set Node env to development if running in dev mode.': 'remove',
|
|
};
|
|
loader.writeEnvFile(rootEnvPath, removeEnvs);
|
|
|
|
/**
|
|
* Lets make things more secure!
|
|
* 1. Add CREDS_KEY
|
|
* 2. Add CREDS_IV
|
|
* 3. Add JWT_SECRET
|
|
*/
|
|
fs.appendFileSync(
|
|
rootEnvPath,
|
|
'\n\n##########################\n# Secure Keys:\n##########################\n',
|
|
);
|
|
loader.addSecureEnvVar(rootEnvPath, 'CREDS_KEY', 32);
|
|
loader.addSecureEnvVar(rootEnvPath, 'CREDS_IV', 16);
|
|
loader.addSecureEnvVar(rootEnvPath, 'JWT_SECRET', 32);
|
|
|
|
// Lets update the openai key name, not the best spot in the env file but who cares ¯\_(ツ)_/¯
|
|
loader.writeEnvFile(rootEnvPath, { OPENAI_API_KEY: initEnv['OPENAI_KEY'] });
|
|
|
|
// TODO: we need to copy over the value of: APP_TITLE
|
|
fs.appendFileSync(
|
|
rootEnvPath,
|
|
'\n\n##########################\n# Frontend Vite Variables:\n##########################\n',
|
|
);
|
|
const frontend = {
|
|
APP_TITLE: initEnv['VITE_APP_TITLE'] || '"LibreChat"',
|
|
ALLOW_REGISTRATION: 'true',
|
|
};
|
|
loader.writeEnvFile(rootEnvPath, frontend);
|
|
|
|
// Ensure .env.development and .env.production files end with a newline
|
|
if (fs.existsSync(devEnvPath)) {
|
|
fs.appendFileSync(devEnvPath, '\n');
|
|
}
|
|
if (fs.existsSync(prodEnvPath)) {
|
|
fs.appendFileSync(prodEnvPath, '\n');
|
|
}
|
|
// Remove client file
|
|
fs.copyFileSync(clientEnvPath, rootEnvPath + '.client.bak');
|
|
fs.unlinkSync(clientEnvPath);
|
|
|
|
console.log('###############################################');
|
|
console.log('Upgrade completed! Please review the new .env file and make any changes as needed.');
|
|
console.log('###############################################');
|
|
|
|
// if the .env.development file exists, lets tell the user
|
|
if (fs.existsSync(devEnvPath)) {
|
|
console.log(
|
|
'NOTE: A .env.development file was created. This will take precedence over the .env file when running in dev mode.',
|
|
);
|
|
console.log('###############################################');
|
|
}
|