代码之家  ›  专栏  ›  技术社区  ›  Sherif Ali

LangChain AgentExecutor call()抱怨需要一个输入键,但在传递输入时得到2个。抱怨删除时缺少输入

  •  0
  • Sherif Ali  · 技术社区  · 2 年前

    我正在使用LangChain Typescript(0.0.96)构建一个可以回答问题的简单聊天机器人。我使用的是AgentExecutor,它使用从DB和EntityMemory中查找信息的工具作为内存。以下是代码的样子:

    // Create memory input
    const input = {"input": question};
    // Load the relevant history using the entities used in the question and the conversation
    relevantEntityHistory = await this.memory.loadMemoryVariables(input);
    
    console.log('Relevant Entity History', relevantEntityHistory);
    /**
    * Relevant Entity History {
    *  history: '',
    *  entities: {
    *    HTML: 'No current information known.',
    *    AI: 'No current information known.',
    *    JavaScript: 'No current information known.'
    *  }
    *}
    */
    
    // Create the agent executor
    if (!this.executor) {
       // Build the agent executor with options
       this.executor = await initializeAgentExecutorWithOptions(this.tools, this.model, {
           agentType: "chat-conversational-react-description",
           verbose: true,
           memory: this.memory,
        });
    }
    
    console.log("Executing with input: ", question);
    // Executing with input:  Please create an HTML page with three columns. The left column will have a list of conversations the customer had with our AI chatbot. The middle column will contain all messages for a selected conversation and a text area for customers to send new messages. The right column will have a list of knowledge base sources that the chatbot can use to answer customer questions.
    
    const result = await this.executor.call({ 
        input: question,
        chat_history: relevantEntityHistory.history,
    });
    

    问题似乎出在 输入:问题 属性发送到executor调用方法。上面的代码给了我这个错误:

    错误:需要一个输入键,但得到2个

    我尝试删除输入,有趣的是,它似乎能够开始执行链,但后来它抱怨“输入变量缺少值 input "

    [chain/start] [1:chain:AgentExecutor] Entering Chain run with input: {
      "chat_history": [],
      "history": "",
      "entities": {
        "Human: \n\nOutput: NONE": "No current information known."
      }
    }
    
    [chain/start] [1:chain:AgentExecutor > 2:chain:LLMChain] Entering Chain run with input: {
      "chat_history": [],
      "history": "",
      "entities": {
        "Human: \n\nOutput: NONE": "No current information known."
      },
      "agent_scratchpad": [],
      "stop": [
        "Observation:"
      ]
    }
    
    [chain/error] [1:chain:AgentExecutor > 2:chain:LLMChain] [3ms] Chain run errored with error: "Missing value for input variable `input`"
    
    [chain/error] [1:chain:AgentExecutor] [8ms] Chain run errored with error: "Missing value for input variable `input`"
    
        at C:\Users\Sheri\autodev\node_modules\langchain\dist\prompts\chat.cjs:224:27
        at Array.reduce (<anonymous>)
        at ChatPromptTemplate.formatMessages (C:\Users\Sheri\autodev\node_modules\langchain\dist\prompts\chat.cjs:222:62)
        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
        at async ChatPromptTemplate.formatPromptValue (C:\Users\Sheri\autodev\node_modules\langchain\dist\prompts\chat.cjs:115:32)
        at async LLMChain._call (C:\Users\Sheri\autodev\node_modules\langchain\dist\chains\llm_chain.cjs:120:29)
        at async LLMChain.call (C:\Users\Sheri\autodev\node_modules\langchain\dist\chains\base.cjs:80:29)
        at async LLMChain.predict (C:\Users\Sheri\autodev\node_modules\langchain\dist\chains\llm_chain.cjs:139:24)
        at async ChatConversationalAgent._plan (C:\Users\Sheri\autodev\node_modules\langchain\dist\agents\agent.cjs:211:24)
        at async AgentExecutor._call (C:\Users\Sheri\autodev\node_modules\langchain\dist\agents\executor.cjs:88:28)
    

    任何关于我遗漏了什么或如何在我的情况下正确传递“输入”的指针都将不胜感激。谢谢


    快速更新

    我尝试使用executor run()方法而不是call(),尽管我不完全清楚它们之间的区别(Typescript文档仍然有点单薄)。以下是代码的这一部分:

    const result = await this.executor.run({
        input: question,
    });
    

    但我还是或多或少地收到了同样的错误

    Error retrieving response from  as knowledge base using OpenAI: Error: Chain agent_executor expects multiple inputs, cannot use 'run'
        at AgentExecutor.run (C:\Users\Sheri\autodev\node_modules\langchain\dist\chains\base.cjs:53:19)
        at WebsiteBasedConversationAgent.<anonymous> (C:\Users\Sheri\autodev\dist\services\agents\WebsiteBasedConversationAgent.js:99:48)
        at Generator.next (<anonymous>)
        at fulfilled (C:\Users\Sheri\autodev\dist\services\agents\WebsiteBasedConversationAgent.js:5:58)
        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    

    我还试着在代码中注释loadMemoryVariables()行,以防它以某种方式导致重复输入但没有骰子

    0 回复  |  直到 2 年前
        1
  •  0
  •   Edward Vergel    2 年前

    我遇到了几乎相同的问题,但使用AbortSignal对象和openai函数代理运行。

    您需要更改以下内容:

    const result = await this.executor.call({ 
        input: question,
        chat_history: relevantEntityHistory.history,
    });
    

    对此:

    const history = relevantEntityHistory.history
    const result = await this.executor.call({ 
        input: question,
        chat_history: history,
    });
    

    希望它对你有用!