ConversationalRetrievalChain引发KeyError
我正在用 langchain 的 HuggingFaceEmbeddings 和 ConversationalRetrievalChain 在 Gemma-2B-it 模型上实现 RAG。
当我运行以下代码时:
chat_history = []
question = "My prompt"
result = qa.invoke({"question": question, "chat_history": chat_history})
我得到了这个结果:
276
277 if self.pipeline.task == "text-generation":
--> 278 text = response["generated_text"]
279 elif self.pipeline.task == "text2text-generation":
280 text = response["generated_text"]
KeyError: 'generated_text'
我不明白为什么会这样。之前是可以正常工作的,但今天突然就不行了。我还试过用 qa.run
来代替 invoke
,但还是出现了同样的错误。
我尝试过更换模型和设备,但都没有解决问题。
1 个回答
2
如果你在使用 transformers.pipeline
,那么要确保没有传入这个 return_tensors='pt'
参数。