mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-18 09:20:15 +01:00
feat(Functions Agent): use official langchain function executor/agent for better output handling (#538)
* style(FunctionsAgent.js): remove unnecessary comments and update PREFIX variable refactor(initializeFunctionsAgent.js): update to use initializeAgentExecutorWithOptions deps(package.json): update langchain to v0.0.95 refactor(askGPTPlugins.js): pass endpointOption to onStart function * fix(ChatAgent.js): handle undefined delta content in progressMessage.choices array
This commit is contained in:
parent
49e2cdf76c
commit
f84da37c9c
6 changed files with 47 additions and 28 deletions
|
|
@ -1,32 +1,47 @@
|
|||
const FunctionsAgent = require('./FunctionsAgent');
|
||||
const { AgentExecutor } = require('langchain/agents');
|
||||
// const FunctionsAgent = require('./FunctionsAgent');
|
||||
// const { AgentExecutor, initializeAgentExecutorWithOptions } = require('langchain/agents');
|
||||
const { initializeAgentExecutorWithOptions } = require('langchain/agents');
|
||||
const { BufferMemory, ChatMessageHistory } = require('langchain/memory');
|
||||
|
||||
const initializeFunctionsAgent = async ({
|
||||
tools,
|
||||
model,
|
||||
pastMessages,
|
||||
currentDateString,
|
||||
// currentDateString,
|
||||
...rest
|
||||
}) => {
|
||||
const agent = FunctionsAgent.fromLLMAndTools(
|
||||
model,
|
||||
tools,
|
||||
{
|
||||
currentDateString,
|
||||
});
|
||||
// const agent = FunctionsAgent.fromLLMAndTools(
|
||||
// model,
|
||||
// tools,
|
||||
// {
|
||||
// currentDateString,
|
||||
// });
|
||||
|
||||
|
||||
const memory = new BufferMemory({
|
||||
chatHistory: new ChatMessageHistory(pastMessages),
|
||||
// returnMessages: true, // commenting this out retains memory
|
||||
memoryKey: 'chat_history',
|
||||
humanPrefix: 'User',
|
||||
aiPrefix: 'Assistant',
|
||||
inputKey: 'input',
|
||||
outputKey: 'output'
|
||||
outputKey: 'output',
|
||||
returnMessages: true,
|
||||
});
|
||||
|
||||
return AgentExecutor.fromAgentAndTools({ agent, tools, memory, ...rest });
|
||||
// return AgentExecutor.fromAgentAndTools({ agent, tools, memory, ...rest });
|
||||
|
||||
return await initializeAgentExecutorWithOptions(
|
||||
tools,
|
||||
model,
|
||||
{
|
||||
agentType: "openai-functions",
|
||||
memory,
|
||||
maxIterations: 4,
|
||||
...rest,
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
};
|
||||
|
||||
module.exports = initializeFunctionsAgent;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue