gpt4 book ai didi

openai-api - Langchain 使用人工工具抛出解析响应错误

转载 作者:行者123 更新时间:2023-12-02 22:47:43 25 4
gpt4 key购买 nike

我正在尝试使用 langchain 代理为软件工程师生成一个月的面试计划。期望代理应该询问用户几个问题并制定计划。

import os
from langchain.memory import ConversationBufferMemory
from langchain.chat_models import ChatOpenAI
from langchain.agents import load_tools, initialize_agent
from langchain.agents import AgentType

os.environ["OPENAI_API_KEY"] = "sk-"

def _handle_error(error) -> str:
return str(error)[:50]


if __name__ == '__main__':
llm = ChatOpenAI(temperature=0.0)
tools = load_tools(
["human"],
llm=llm,
)
memory = ConversationBufferMemory(memory_key="chat_history")
agent_chain = initialize_agent(
tools,
llm,
agent=AgentType.CONVERSATIONAL_REACT_DESCRIPTION,
verbose=True,
memory=memory,
max_iterations=3,
handle_parsing_errors=_handle_error
)

agent_chain.run(
"I want you to create a one-month interview preparation plan with the help of OpenAI by understanding my current skill level. Ask questions to user and get the answers and use them to generate plan")

它抛出以下错误: enter image description here

预计它会问一些问题,如下面的 chatGPT 屏幕截图所示 enter image description here

最佳答案

试试这个..

# agent_chain.run(
# "I want you to create a one-month interview preparation plan with the help of OpenAI by understanding my current skill level. Ask questions to user and get the answers and use them to generate plan")

try:
response= agent_chain.run("I want you to create a one-month interview preparation plan with the help of OpenAI by understanding my current skill level. Ask questions to user and get the answers and use them to generate plan")
except Exception as e:
response = str(e)
if response.startswith("Could not parse LLM output: `"):
response = response.removeprefix("Could not parse LLM output: `").removesuffix("`")
print(response)

输出 - enter image description here

关于openai-api - Langchain 使用人工工具抛出解析响应错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77039247/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com