Skip to content

Commit

Permalink
Added bool to disable chat_session_id check for search_docs for api
Browse files Browse the repository at this point in the history
  • Loading branch information
hagen-danswer authored and Weves committed Sep 20, 2024
1 parent 9f17994 commit 16d1c19
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions backend/danswer/chat/process_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ def stream_chat_message_objects(
use_existing_user_message: bool = False,
litellm_additional_headers: dict[str, str] | None = None,
is_connected: Callable[[], bool] | None = None,
enforce_chat_session_id_for_search_docs: bool = True,
) -> ChatPacketStream:
"""Streams in order:
1. [conditional] Retrieved documents if a search needs to be run
Expand Down Expand Up @@ -442,6 +443,7 @@ def stream_chat_message_objects(
chat_session=chat_session,
user_id=user_id,
db_session=db_session,
enforce_chat_session_id_for_search_docs=enforce_chat_session_id_for_search_docs,
)

# Generates full documents currently
Expand Down
4 changes: 3 additions & 1 deletion backend/danswer/db/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@ def get_doc_query_identifiers_from_model(
chat_session: ChatSession,
user_id: UUID | None,
db_session: Session,
enforce_chat_session_id_for_search_docs: bool,
) -> list[tuple[str, int]]:
"""Given a list of search_doc_ids"""
search_docs = (
Expand All @@ -617,7 +618,8 @@ def get_doc_query_identifiers_from_model(
for doc in search_docs
]
):
raise ValueError("Invalid reference doc, not from this chat session.")
if enforce_chat_session_id_for_search_docs:
raise ValueError("Invalid reference doc, not from this chat session.")
except IndexError:
# This happens when the doc has no chat_messages associated with it.
# which happens as an edge case where the chat message failed to save
Expand Down
2 changes: 2 additions & 0 deletions backend/ee/danswer/server/query_and_chat/chat_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ def handle_simplified_chat_message(
new_msg_req=full_chat_msg_info,
user=user,
db_session=db_session,
enforce_chat_session_id_for_search_docs=False,
)

return _convert_packet_stream_to_response(packets)
Expand Down Expand Up @@ -301,6 +302,7 @@ def handle_send_message_simple_with_history(
new_msg_req=full_chat_msg_info,
user=user,
db_session=db_session,
enforce_chat_session_id_for_search_docs=False,
)

return _convert_packet_stream_to_response(packets)

0 comments on commit 16d1c19

Please sign in to comment.