0

in this code when i ask anything it give me an error "KeyError: {'input', 'agent_scratchpad'}" I want the gpt to search bing and give back results

def langchain_completion(self
                     ):

    system_template = """
        Your job is a financial advisor and assistant that must make decisions for users based on the user's data and the questions you ask. \
    """
    
    llm = ChatOpenAI(model_name="gpt-4",
                     temperature=self.TEMPERATURE,
                     max_tokens=self.USER_MAX_TOKENS
                    )

    tools = load_tools(["wikipedia", "llm-math", "bing-search"],
                       llm=llm
                      )
    
    my_agent = initialize_agent(tools,
                                 llm,
                                 agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
                                 verbose=False
                                )

    my_agent.agent.llm_chain.prompt.template = system_template

    
    while True:
        question = input("Enter your prompt: ")
        if (question != ""):
            print(my_agent.run(input=question))
        else:
            return "I'm Out"

The error:

File ~\miniconda3\envs\workspace\Lib\site-packages\langchain\utils\formatting.py:18, in StrictFormatter.check_unused_args(self, used_args, args, kwargs) 16 extra = set(kwargs).difference(used_args) 17 if extra: ---> 18 raise KeyError(extra)

KeyError: {'input', 'agent_scratchpad'}

1 Answer 1

1

the error was about changing the original system prompt template without considering the input variables

so

my_agent.agent.llm_chain.prompt.template += system_template

should fix it

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.