In 05_question_answering, when I am trying to run the map_reduce part, I got error:
TypeError: unsupported operand type(s) for +=: ‘OpenAIObject’ and ‘OpenAIObject’
after trying to run
result = qa_chain_mr({“query”: question})
Can somebody help me with this? Thanks.
1 Like
Hi You_Wang,
There is indeed a bug in that notebook. I was facing the same issue. The root cause is:
ChatOpenAI
Output Type: The ChatOpenAI
class (from LangChain) returns responses as OpenAIObject
instances, which are more complex structures containing additional metadata besides the text.
map_reduce
Chain Expectation: The map_reduce
chain type expects the language model to return plain strings so it can concatenate them using the +=
operator.
There are a couple of ways to resolve this issue:
1. Switch to a Plain OpenAI
LLM Instead of ChatOpenAI
from langchain.llms import OpenAI
llm = OpenAI(model_name=llm_name, temperature=0)
2. Use a Compatible Chain Type with ChatOpenAI
If you prefer to utilize the chat-based capabilities of ChatOpenAI
, switch to a chain type that’s compatible with it, such as "refine"
qa_chain_refine = RetrievalQA.from_chain_type(
llm,
retriever=vectordb.as_retriever(),
chain_type="refine"
)
Hope this helps. Happy learning.
Best
Rosa
1 Like
Thanks to arosacastillo and You_Wang, I had been searching for this all over the internet for the past two days!
Hi @Arpit_Sharma3,
Thanks for your message. Which solution did you use in the end? 1 or 2?
Happy learning
Rosa