Spaces:
Runtime error
Runtime error
Commit
·
04e36cb
1
Parent(s):
08463bd
Update conversation.py
Browse files- conversation.py +25 -8
conversation.py
CHANGED
@@ -41,14 +41,31 @@ def create_conversation(query: str, chat_history: list, collection_name: str) ->
|
|
41 |
return_source_documents=False,
|
42 |
)
|
43 |
result = cqa({'question': query, 'chat_history': chat_history})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
chat_history.append((query, result['answer']))
|
45 |
-
return '',
|
46 |
-
# except Exception as e:
|
47 |
-
# chat_history.append((query, e))
|
48 |
-
# return '', chat_history
|
49 |
-
except pinecone.exceptions.PineconeException as pe:
|
50 |
-
chat_history.append((query, f"Pinecone Error: {pe}"))
|
51 |
-
return '', chat_history
|
52 |
except Exception as e:
|
53 |
chat_history.append((query, f"Unexpected Error: {e}"))
|
54 |
-
return '', chat_history
|
|
|
41 |
return_source_documents=False,
|
42 |
)
|
43 |
result = cqa({'question': query, 'chat_history': chat_history})
|
44 |
+
# chat_history.append((query, result['answer']))
|
45 |
+
# return '', chat_history
|
46 |
+
|
47 |
+
source_documents = result.get('source_documents', [])
|
48 |
+
|
49 |
+
# Filter the source_documents to keep 'page', 'source', and 'page_content'
|
50 |
+
filtered_documents = [{'page': doc.metadata.get('page', None),
|
51 |
+
'source': os.path.basename(doc.metadata.get('source', None)),
|
52 |
+
'page_content': doc.page_content}
|
53 |
+
for doc in source_documents]
|
54 |
+
# Format and print the output with spaces between documents
|
55 |
+
output = ""
|
56 |
+
for doc in filtered_documents:
|
57 |
+
page = doc['page']
|
58 |
+
source = doc['source']
|
59 |
+
page_content = doc['page_content']
|
60 |
+
|
61 |
+
output += f"Page: {page}\n"
|
62 |
+
output += f"Source: {source}\n"
|
63 |
+
output += f"Page Content: {page_content}\n"
|
64 |
+
output += "\n" # Adding new lines between documents for better readability
|
65 |
+
|
66 |
+
|
67 |
chat_history.append((query, result['answer']))
|
68 |
+
return '',chat_history, output
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
except Exception as e:
|
70 |
chat_history.append((query, f"Unexpected Error: {e}"))
|
71 |
+
return '', chat_history, output
|