(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, conversation_id,
user_api_key, user_api_key,
isNoneDoc=False, isNoneDoc=False,
index=None index=None,
should_save_conversation=True
): ):
try: try:
response_full = "" response_full = ""
@@ -247,16 +248,20 @@ def complete_stream(
user_api_key=user_api_key user_api_key=user_api_key
) )
conversation_id = save_conversation( if should_save_conversation:
conversation_id, conversation_id = save_conversation(
question, conversation_id,
response_full, question,
source_log_docs, response_full,
tool_calls, source_log_docs,
llm, tool_calls,
index, llm,
api_key=user_api_key index,
) api_key=user_api_key
)
else:
conversation_id = None
# send data.type = "end" to indicate that the stream has ended as json # send data.type = "end" to indicate that the stream has ended as json
data = json.dumps({"type": "id", "id": str(conversation_id)}) data = json.dumps({"type": "id", "id": str(conversation_id)})
yield f"data: {data}\n\n" yield f"data: {data}\n\n"
@@ -322,6 +327,9 @@ class Stream(Resource):
"index": fields.Integer( "index": fields.Integer(
required=False, description="The position where query is to be updated" 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: if missing_fields:
return missing_fields return missing_fields
save_conv = data.get("save_conversation", True)
try: try:
question = data["question"] question = data["question"]
history = limit_chat_history( history = limit_chat_history(
@@ -394,6 +404,7 @@ class Stream(Resource):
user_api_key=user_api_key, user_api_key=user_api_key,
isNoneDoc=data.get("isNoneDoc"), isNoneDoc=data.get("isNoneDoc"),
index=index, index=index,
should_save_conversation=save_conv,
), ),
mimetype="text/event-stream", mimetype="text/event-stream",
) )

View File

@@ -262,6 +262,7 @@ export function handleFetchSharedAnswerStreaming( //for shared conversations
question: question, question: question,
history: JSON.stringify(history), history: JSON.stringify(history),
api_key: apiKey, api_key: apiKey,
save_conversation: false,
}; };
conversationService conversationService
.answerStream(payload, signal) .answerStream(payload, signal)