diff --git a/application/api/answer/routes.py b/application/api/answer/routes.py index 5ab54fca..a2e2d1af 100644 --- a/application/api/answer/routes.py +++ b/application/api/answer/routes.py @@ -210,7 +210,8 @@ def complete_stream( conversation_id, user_api_key, isNoneDoc=False, - index=None + index=None, + should_save_conversation=True ): try: response_full = "" @@ -247,16 +248,20 @@ def complete_stream( user_api_key=user_api_key ) - conversation_id = save_conversation( - conversation_id, - question, - response_full, - source_log_docs, - tool_calls, - llm, - index, - api_key=user_api_key - ) + if should_save_conversation: + conversation_id = save_conversation( + conversation_id, + question, + response_full, + source_log_docs, + tool_calls, + llm, + index, + api_key=user_api_key + ) + else: + conversation_id = None + # send data.type = "end" to indicate that the stream has ended as json data = json.dumps({"type": "id", "id": str(conversation_id)}) yield f"data: {data}\n\n" @@ -322,6 +327,9 @@ class Stream(Resource): "index": fields.Integer( required=False, description="The position where query is to be updated" ), + "save_conversation": fields.Boolean( + required=False, default=True, description="Flag to save conversation" + ), }, ) @@ -336,6 +344,8 @@ class Stream(Resource): if missing_fields: return missing_fields + save_conv = data.get("save_conversation", True) + try: question = data["question"] history = limit_chat_history( @@ -394,6 +404,7 @@ class Stream(Resource): user_api_key=user_api_key, isNoneDoc=data.get("isNoneDoc"), index=index, + should_save_conversation=save_conv, ), mimetype="text/event-stream", ) diff --git a/frontend/src/conversation/conversationHandlers.ts b/frontend/src/conversation/conversationHandlers.ts index ddd84bd3..0b54a366 100644 --- a/frontend/src/conversation/conversationHandlers.ts +++ b/frontend/src/conversation/conversationHandlers.ts @@ -262,6 +262,7 @@ export function handleFetchSharedAnswerStreaming( //for shared conversations question: question, history: JSON.stringify(history), api_key: apiKey, + save_conversation: false, }; conversationService .answerStream(payload, signal)