From ecd692e7824f3018124984651e2704fffaa5504d Mon Sep 17 00:00:00 2001 From: Karen Shaw Date: Mon, 9 Sep 2024 17:36:16 +0000 Subject: [PATCH] Return source documents for context in chat sync for testing --- chat/src/handlers/chat_sync.py | 4 ++-- chat/src/helpers/http_response.py | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/chat/src/handlers/chat_sync.py b/chat/src/handlers/chat_sync.py index dd3d88c..cb679f5 100644 --- a/chat/src/handlers/chat_sync.py +++ b/chat/src/handlers/chat_sync.py @@ -10,8 +10,8 @@ logging.getLogger('honeybadger').addHandler(logging.StreamHandler()) RESPONSE_TYPES = { - "base": ["answer", "ref"], - "debug": ["answer", "attributes", "azure_endpoint", "deployment_name", "is_superuser", "k", "openai_api_version", "prompt", "question", "ref", "temperature", "text_key", "token_counts"], + "base": ["answer", "ref", "context"], + "debug": ["answer", "attributes", "azure_endpoint", "deployment_name", "is_superuser", "k", "openai_api_version", "prompt", "question", "ref", "temperature", "text_key", "token_counts", "context"], "log": ["answer", "deployment_name", "is_superuser", "k", "openai_api_version", "prompt", "question", "ref", "size", "source_documents", "temperature", "token_counts"], "error": ["question", "error", "source_documents"] } diff --git a/chat/src/helpers/http_response.py b/chat/src/helpers/http_response.py index fc6abc6..11ba296 100644 --- a/chat/src/helpers/http_response.py +++ b/chat/src/helpers/http_response.py @@ -27,6 +27,8 @@ def get_and_send_original_question(docs): source_document["content"] = doc.page_content source_documents.append(source_document) + self.context = source_documents + original_question = { "question": self.config.question, "source_documents": source_documents, @@ -49,6 +51,7 @@ def prepare_response(self): | self.debug_response_passthrough() ) response = chain.invoke(self.config.question) + response["context"] = self.context except Exception as err: response = { "question": self.config.question,