October 22, 2024
Chicago 12, Melborne City, USA
python

How to resolve KeyError when chaining llmss


I’m trying to create a process where I can break down a user query into multiple searchable queries using LLMs and then fetch the results online. I’ve set up two chains for extracting information and searching, but encountered a KeyError: 'analysis' during execution.

Here’s the relevant code snippet::

search_tool = DuckDuckGoSearchRun()

extract_chain = (
    extract_prompt
    | llm
    | StrOutputParser()
)

search_chain = (
    search_prompt
    | llm
    | StrOutputParser()
)

chain = {"analysis" : extract_chain} | {"search_results": lambda x: search_tool.run(x["analysis"])} | search_chain

What could be the cause of this error?



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video