LibreChat/api/app/clients/agents/CustomAgent/CustomAgent.js
Danny Avila 95201908e9
📦 fix: npm warnings; chore: bump deprecated packages (#4707)
* chore: bump langchain deps to address vulnerability warnings

* chore: bump community package and install textsplitters package

* fix: update expected result in tokenSplit tests for accuracy

* chore: remove CodeSherpa tools

* chore: remove E2B tools and loadToolSuite

* chore: remove CodeBrew tool and update related references

* chore: remove HumanTool and ChatTool, update tool references

* chore: remove Zapier tool from manifest.json and update SerpAPI

* chore: remove basic tools

* chore: update import path for RecursiveCharacterTextSplitter

* chore: update import path for DynamicStructuredTool

* chore: remove extractionChain.js and update tool filtering logic

* chore: npm audit fix

* chore: bump google packages

* chore: update DALL-E tool to DALL-E-3 and adjust authentication logic

* ci: update message classes

* chore: elliptic npm audit fix

* chore: update CallbackManager import and remove deprecated tool handling logic

* chore: imports order

* chore: remove unused code

---------

Co-authored-by: Max Sanna <max@maxsanna.com>
2024-11-12 18:51:32 -05:00

50 lines
1.4 KiB
JavaScript

const { ZeroShotAgent } = require('langchain/agents');
const { PromptTemplate, renderTemplate } = require('@langchain/core/prompts');
const { gpt3, gpt4 } = require('./instructions');
class CustomAgent extends ZeroShotAgent {
constructor(input) {
super(input);
}
_stop() {
return ['\nObservation:', '\nObservation 1:'];
}
static createPrompt(tools, opts = {}) {
const { currentDateString, model } = opts;
const inputVariables = ['input', 'chat_history', 'agent_scratchpad'];
let prefix, instructions, suffix;
if (model.includes('gpt-3')) {
prefix = gpt3.prefix;
instructions = gpt3.instructions;
suffix = gpt3.suffix;
} else if (model.includes('gpt-4')) {
prefix = gpt4.prefix;
instructions = gpt4.instructions;
suffix = gpt4.suffix;
}
const toolStrings = tools
.filter((tool) => tool.name !== 'self-reflection')
.map((tool) => `${tool.name}: ${tool.description}`)
.join('\n');
const toolNames = tools.map((tool) => tool.name);
const formatInstructions = (0, renderTemplate)(instructions, 'f-string', {
tool_names: toolNames,
});
const template = [
`Date: ${currentDateString}\n${prefix}`,
toolStrings,
formatInstructions,
suffix,
].join('\n\n');
return new PromptTemplate({
template,
inputVariables,
});
}
}
module.exports = CustomAgent;