Spaces:
Sleeping
Sleeping
fix ValueError below
Browse filesFile "/home/user/app/app.py", line 154, in chat_with_pdf
for user_msg, ai_msg in history:
ValueError: too many values to unpack (expected 2)
app.py
CHANGED
|
@@ -151,9 +151,11 @@ async def chat_with_pdf(message, history, state: SessionState):
|
|
| 151 |
rag_chain = create_retrieval_chain(history_aware_retriever, question_answer_chain)
|
| 152 |
|
| 153 |
chat_history_for_chain = []
|
| 154 |
-
for
|
| 155 |
-
|
| 156 |
-
|
|
|
|
|
|
|
| 157 |
|
| 158 |
response = await rag_chain.ainvoke({
|
| 159 |
"chat_history": chat_history_for_chain,
|
|
@@ -217,4 +219,4 @@ with gr.Blocks(title="PDF Chatbot") as demo:
|
|
| 217 |
outputs=[chat_row, file_upload_input, state]
|
| 218 |
)
|
| 219 |
|
| 220 |
-
demo.launch()
|
|
|
|
| 151 |
rag_chain = create_retrieval_chain(history_aware_retriever, question_answer_chain)
|
| 152 |
|
| 153 |
chat_history_for_chain = []
|
| 154 |
+
for turn in history:
|
| 155 |
+
if isinstance(turn, (list, tuple)) and len(turn) == 2:
|
| 156 |
+
user_msg, ai_msg = turn
|
| 157 |
+
chat_history_for_chain.append(HumanMessage(content=user_msg))
|
| 158 |
+
chat_history_for_chain.append(AIMessage(content=ai_msg))
|
| 159 |
|
| 160 |
response = await rag_chain.ainvoke({
|
| 161 |
"chat_history": chat_history_for_chain,
|
|
|
|
| 219 |
outputs=[chat_row, file_upload_input, state]
|
| 220 |
)
|
| 221 |
|
| 222 |
+
demo.launch()
|