Sources in responses

This commit is contained in:
Alex
2023-06-11 22:56:34 +01:00
parent 577d58c92b
commit 610adcbefc
6 changed files with 147 additions and 78 deletions

View File

@@ -157,6 +157,10 @@ def complete_stream(question, docsearch, chat_history, api_key):
docs_together = "\n".join([doc.page_content for doc in docs])
p_chat_combine = chat_combine_template.replace("{summaries}", docs_together)
messages_combine = [{"role": "system", "content": p_chat_combine}]
for doc in docs:
data = json.dumps({"type": "source", "doc": doc.page_content})
yield f"data:{data}\n\n"
if len(chat_history) > 1:
tokens_current_history = 0
# count tokens in history
@@ -308,6 +312,9 @@ def api_answer():
except Exception:
pass
sources = docsearch.similarity_search(question, k=2)
result['sources'] = [{'title': i.page_content, 'text': i.page_content} for i in sources]
# mock result
# result = {
# "answer": "The answer is 42",