(feat:stream) save conversations optionally

This commit is contained in:
ManishMadan2882
2025-02-25 17:32:35 +05:30
parent d823fba60b
commit caed6df53b
2 changed files with 23 additions and 11 deletions

View File

@@ -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",
)

View File

@@ -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)