Hi community,
I'm studying the course building neo4j-backed chatbot with python and have some confusion and error during runtime. Any helps would be much appreciated
.from_llm or .from_chain_type?
the material discuss about .from_llm, but the code snippet show .from_chain_type. not sure which exactly is it?
Error invoking the second tool: vector search at agent invoke.
I strictly follow the material, right up until the part where I add the second tool, vector search, into the tool list. If I ask a general question, it is ok. but if I asked specifically about the 'plot' it returned some validation error - however, if I enter the query directly via kg_qa, it will be ok.
To illustrate, I have also added some images here(the system won't allow me to attach file)
ValidationError: 2 validation errors for AIMessage
content
str type expected (type=type_error.str)
content
value is not a valid list (type=type_error.list)
It was unclear to me that I had to revise agent.generate_response() as I progressed through the module. The def generate_response(prompt) is also provided in solutions/tools/cypher.py, solutions/tools/vector.py
But this creates a new question though. How can we manage and process the incoming responses? is there a way to know which response comes from which 'Tool' in the chain?
For example,
if the response is from general chat, then -->response = agent_executor.invoke({"input": prompt})
if the response is from vector search, then -->response = kg_qa({"query": prompt})
if the response is from graph chain, then -->response = cypher_qa.run(prompt)
There's an even simpler solution that requires less fiddling
Change the return_direct from True to False - this stops the agent output getting returned directly to the LLM output, which is what's throwing a format error as it's not in form of a string (making it false means that it introduces an intermediate step to format it correctly into a string)
I think I encounter the same issue as Swatakit but the proposed fix (return_direct from True to False ) make the LLM to loop and so stop (Agent stopped due to iteration limit or time limt).
Here the feedback when return_direct is set to False.
Here the error message I got when the return_direct is set to True.
//////////////
ValidationError: 2 validation errors for AIMessage content str type expected (type=type_error.str) content value is not a valid list (type=type_error.list)
Traceback:
File "E:\PythonProgram\Lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 535, in _run_script
exec(code, module.dict)
File "E:\Projet IA\GraphLLMCours\Create A chat BOT\llm-chatbot-python-main\bot.py", line 40, in
handle_submit(prompt)
File "E:\Projet IA\GraphLLMCours\Create A chat BOT\llm-chatbot-python-main\bot.py", line 24, in handle_submit
response = generate_response(message)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\Projet IA\GraphLLMCours\Create A chat BOT\llm-chatbot-python-main\agent.py", line 91, in generate_response
response = agent_executor.invoke({"input": prompt})
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\PythonProgram\Lib\site-packages\langchain\chains\base.py", line 89, in invoke
return self(
^^^^^
File "E:\PythonProgram\Lib\site-packages\langchain\chains\base.py", line 314, in call
final_outputs: Dict[str, Any] = self.prep_outputs(
^^^^^^^^^^^^^^^^^^
File "E:\PythonProgram\Lib\site-packages\langchain\chains\base.py", line 410, in prep_outputs
self.memory.save_context(inputs, outputs)
File "E:\PythonProgram\Lib\site-packages\langchain\memory\chat_memory.py", line 39, in save_context
self.chat_memory.add_ai_message(output_str)
File "E:\PythonProgram\Lib\site-packages\langchain_core\chat_history.py", line 65, in add_ai_message
self.add_message(AIMessage(content=message))
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\PythonProgram\Lib\site-packages\langchain_core\load\serializable.py", line 107, in init
super().init(**kwargs)
File "E:\PythonProgram\Lib\site-packages\pydantic\v1\main.py", line 341, in init
raise validation_errorThe solution doesn't fix the inconsistency
//////////////////////
On your query, I think you have to submit a description of a plot e.g. "movie about alien attacking earth" because, the movie plot then converts to-->embedding-->vector search--> return results