mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-16 16:30:15 +01:00
* feat(PluginsClient.js): add conversationId to options object in the constructor feat(PluginsClient.js): add support for Code Interpreter plugin feat(PluginsClient.js): add support for Code Interpreter plugin in the availableTools manifest feat(CodeInterpreter.js): add CodeInterpreterTools module feat(CodeInterpreter.js): add RunCommand class feat(CodeInterpreter.js): add ReadFile class feat(CodeInterpreter.js): add WriteFile class feat(handleTools.js): add support for loading Code Interpreter plugin * chore(api): update langchain dependency to version 0.0.123 * fix(CodeInterpreter.js): add support for extracting environment from code fix(WriteFile.js): add support for extracting environment from data fix(extractionChain.js): add utility functions for creating extraction chain from Zod schema fix(handleTools.js): refactor getOpenAIKey function to handle user-provided API key fix(handleTools.js): pass model and openAIApiKey to CodeInterpreter constructor * fix(tools): rename CodeInterpreterTools to E2BTools fix(tools): rename code_interpreter pluginKey to e2b_code_interpreter * chore(PluginsClient.js): comment out unused import and function findMessageContent feat(PluginsClient.js): add support for CodeSherpa plugin feat(PluginsClient.js): add CodeSherpaTools to available tools feat(PluginsClient.js): update manifest.json to include CodeSherpa plugin feat(CodeSherpaTools.js): create RunCode and RunCommand classes for CodeSherpa plugin feat(E2BTools.js): Add E2BTools module for extracting environment from code and running commands, reading and writing files fix(codesherpa.js): Remove codesherpa module as it is no longer needed feat(handleTools.js): add support for CodeSherpaTools in loadTools function feat(loadToolSuite.js): create loadToolSuite utility function to load a suite of tools * feat(PluginsClient.js): add support for CodeSherpa v2 plugin feat(PluginsClient.js): add CodeSherpa v1 plugin to available tools feat(PluginsClient.js): add CodeSherpa v2 plugin to available tools feat(PluginsClient.js): update manifest.json for CodeSherpa v1 plugin feat(PluginsClient.js): update manifest.json for CodeSherpa v2 plugin feat(CodeSherpa.js): implement CodeSherpa plugin for interactive code and shell command execution feat(CodeSherpaTools.js): implement RunCode and RunCommand plugins for CodeSherpa v1 feat(CodeSherpaTools.js): update RunCode and RunCommand plugins for CodeSherpa v2 fix(handleTools.js): add CodeSherpa import statement fix(handleTools.js): change pluginKey from 'codesherpa' to 'codesherpa_tools' fix(handleTools.js): remove model and openAIApiKey from options object in e2b_code_interpreter tool fix(handleTools.js): remove openAIApiKey from options object in codesherpa_tools tool fix(loadToolSuite.js): remove model and openAIApiKey parameters from loadToolSuite function * feat(initializeFunctionsAgent.js): add prefix to agentArgs in initializeFunctionsAgent function The prefix is added to the agentArgs in the initializeFunctionsAgent function. This prefix is used to provide instructions to the agent when it receives any instructions from a webpage, plugin, or other tool. The agent will notify the user immediately and ask them if they wish to carry out or ignore the instructions. * feat(PluginsClient.js): add ChatTool to the list of tools if it meets the conditions feat(tools/index.js): import and export ChatTool feat(ChatTool.js): create ChatTool class with necessary properties and methods * fix(initializeFunctionsAgent.js): update PREFIX message to include sharing all output from the tool fix(E2BTools.js): update descriptions for RunCommand, ReadFile, and WriteFile plugins to provide more clarity and context * chore: rebuild package-lock after rebase * chore: remove deleted file from rebase * wip: refactor plugin message handling to mirror chat.openai.com, handle incoming stream for plugin use * wip: new plugin handling * wip: show multiple plugins handling * feat(plugins): save new plugins array * chore: bump langchain * feat(experimental): support streaming in between plugins * refactor(PluginsClient): factor out helper methods to avoid bloating the class, refactor(gptPlugins): use agent action for mapping the name of action * fix(handleTools): fix tests by adding condition to return original toolFunctions map * refactor(MessageContent): Allow the last index to be last in case it has text (may change with streaming) * feat(Plugins): add handleParsingErrors, useful when LLM does not invoke function params * chore: edit out experimental codesherpa integration * refactor(OpenAPIPlugin): rework tool to be 'function-first', as the spec functions are explicitly passed to agent model * refactor(initializeFunctionsAgent): improve error handling and system message * refactor(CodeSherpa, Wolfram): optimize token usage by delegating bulk of instructions to system message * style(Plugins): match official style with input/outputs * chore: remove unnecessary console logs used for testing * fix(abortMiddleware): render markdown when message is aborted * feat(plugins): add BrowserOp * refactor(OpenAPIPlugin): improve prompt handling * fix(useGenerations): hide edit button when message is submitting/streaming * refactor(loadSpecs): optimize OpenAPI spec loading by only loading requested specs instead of all of them * fix(loadSpecs): will retain original behavior when no tools are passed to the function * fix(MessageContent): ensure cursor only shows up for last message and last display index fix(Message): show legacy plugin and pass isLast to Content * chore: remove console.logs * docs: update docs based on breaking changes and new features refactor(structured/SD): use description_for_model for detailed prompting * docs(azure): make plugins section more clear * refactor(structured/SD): change default payload to SD-WebUI to prefer realism and config for SDXL * refactor(structured/SD): further improve system message prompt * docs: update breaking changes after rebase * refactor(MessageContent): factor out EditMessage, types, Container to separate files, rename Content -> Markdown * fix(CodeInterpreter): linting errors * chore: reduce browser console logs from message streams * chore: re-enable debug logs for plugins/langchain to help with user troubleshooting * chore(manifest.json): add [Experimental] tag to CodeInterpreter plugins, which are not intended as the end-all be-all implementation of this feature for Librechat
165 lines
5.8 KiB
JavaScript
165 lines
5.8 KiB
JavaScript
const { StructuredTool } = require('langchain/tools');
|
|
const axios = require('axios');
|
|
const { z } = require('zod');
|
|
|
|
const headers = {
|
|
'Content-Type': 'application/json',
|
|
};
|
|
|
|
function getServerURL() {
|
|
const url = process.env.CODESHERPA_SERVER_URL || '';
|
|
if (!url) {
|
|
throw new Error('Missing CODESHERPA_SERVER_URL environment variable.');
|
|
}
|
|
return url;
|
|
}
|
|
|
|
class RunCode extends StructuredTool {
|
|
constructor() {
|
|
super();
|
|
this.name = 'RunCode';
|
|
this.description =
|
|
'Use this plugin to run code with the following parameters\ncode: your code\nlanguage: either Python, Rust, or C++.';
|
|
this.headers = headers;
|
|
this.schema = z.object({
|
|
code: z.string().describe('The code to be executed in the REPL-like environment.'),
|
|
language: z.string().describe('The programming language of the code to be executed.'),
|
|
});
|
|
}
|
|
|
|
async _call({ code, language = 'python' }) {
|
|
// console.log('<--------------- Running Code --------------->', { code, language });
|
|
const response = await axios({
|
|
url: `${this.url}/repl`,
|
|
method: 'post',
|
|
headers: this.headers,
|
|
data: { code, language },
|
|
});
|
|
// console.log('<--------------- Sucessfully ran Code --------------->', response.data);
|
|
return response.data.result;
|
|
}
|
|
}
|
|
|
|
class RunCommand extends StructuredTool {
|
|
constructor() {
|
|
super();
|
|
this.name = 'RunCommand';
|
|
this.description =
|
|
'Runs the provided terminal command and returns the output or error message.';
|
|
this.headers = headers;
|
|
this.schema = z.object({
|
|
command: z.string().describe('The terminal command to be executed.'),
|
|
});
|
|
}
|
|
|
|
async _call({ command }) {
|
|
const response = await axios({
|
|
url: `${this.url}/command`,
|
|
method: 'post',
|
|
headers: this.headers,
|
|
data: {
|
|
command,
|
|
},
|
|
});
|
|
return response.data.result;
|
|
}
|
|
}
|
|
|
|
class CodeSherpa extends StructuredTool {
|
|
constructor(fields) {
|
|
super();
|
|
this.name = 'CodeSherpa';
|
|
this.url = fields.CODESHERPA_SERVER_URL || getServerURL();
|
|
// this.description = `A plugin for interactive code execution, and shell command execution.
|
|
|
|
// Run code: provide "code" and "language"
|
|
// - Execute Python code interactively for general programming, tasks, data analysis, visualizations, and more.
|
|
// - Pre-installed packages: matplotlib, seaborn, pandas, numpy, scipy, openpyxl. If you need to install additional packages, use the \`pip install\` command.
|
|
// - When a user asks for visualization, save the plot to \`static/images/\` directory, and embed it in the response using \`http://localhost:3333/static/images/\` URL.
|
|
// - Always save all media files created to \`static/images/\` directory, and embed them in responses using \`http://localhost:3333/static/images/\` URL.
|
|
|
|
// Run command: provide "command" only
|
|
// - Run terminal commands and interact with the filesystem, run scripts, and more.
|
|
// - Install python packages using \`pip install\` command.
|
|
// - Always embed media files created or uploaded using \`http://localhost:3333/static/images/\` URL in responses.
|
|
// - Access user-uploaded files in \`static/uploads/\` directory using \`http://localhost:3333/static/uploads/\` URL.`;
|
|
this.description = `This plugin allows interactive code and shell command execution.
|
|
|
|
To run code, supply "code" and "language". Python has pre-installed packages: matplotlib, seaborn, pandas, numpy, scipy, openpyxl. Additional ones can be installed via pip.
|
|
|
|
To run commands, provide "command" only. This allows interaction with the filesystem, script execution, and package installation using pip. Created or uploaded media files are embedded in responses using a specific URL.`;
|
|
this.schema = z.object({
|
|
code: z
|
|
.string()
|
|
.optional()
|
|
.describe(
|
|
`The code to be executed in the REPL-like environment. You must save all media files created to \`${this.url}/static/images/\` and embed them in responses with markdown`,
|
|
),
|
|
language: z
|
|
.string()
|
|
.optional()
|
|
.describe(
|
|
'The programming language of the code to be executed, you must also include code.',
|
|
),
|
|
command: z
|
|
.string()
|
|
.optional()
|
|
.describe(
|
|
'The terminal command to be executed. Only provide this if you want to run a command instead of code.',
|
|
),
|
|
});
|
|
|
|
this.RunCode = new RunCode({ url: this.url });
|
|
this.RunCommand = new RunCommand({ url: this.url });
|
|
this.runCode = this.RunCode._call.bind(this);
|
|
this.runCommand = this.RunCommand._call.bind(this);
|
|
}
|
|
|
|
async _call({ code, language, command }) {
|
|
if (code?.length > 0) {
|
|
return await this.runCode({ code, language });
|
|
} else if (command) {
|
|
return await this.runCommand({ command });
|
|
} else {
|
|
return 'Invalid parameters provided.';
|
|
}
|
|
}
|
|
}
|
|
|
|
/* TODO: support file upload */
|
|
// class UploadFile extends StructuredTool {
|
|
// constructor(fields) {
|
|
// super();
|
|
// this.name = 'UploadFile';
|
|
// this.url = fields.CODESHERPA_SERVER_URL || getServerURL();
|
|
// this.description = 'Endpoint to upload a file.';
|
|
// this.headers = headers;
|
|
// this.schema = z.object({
|
|
// file: z.string().describe('The file to be uploaded.'),
|
|
// });
|
|
// }
|
|
|
|
// async _call(data) {
|
|
// const formData = new FormData();
|
|
// formData.append('file', fs.createReadStream(data.file));
|
|
|
|
// const response = await axios({
|
|
// url: `${this.url}/upload`,
|
|
// method: 'post',
|
|
// headers: {
|
|
// ...this.headers,
|
|
// 'Content-Type': `multipart/form-data; boundary=${formData._boundary}`,
|
|
// },
|
|
// data: formData,
|
|
// });
|
|
// return response.data;
|
|
// }
|
|
// }
|
|
|
|
// module.exports = [
|
|
// RunCode,
|
|
// RunCommand,
|
|
// // UploadFile
|
|
// ];
|
|
|
|
module.exports = CodeSherpa;
|