From 7445928c7e73eceebda784701712e4a393c4762d Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 22 May 2025 13:14:10 +0100 Subject: [PATCH] (fix:stream) handle empty history input and improve user identification --- application/api/answer/routes.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/application/api/answer/routes.py b/application/api/answer/routes.py index ea599b20..2aa473d4 100644 --- a/application/api/answer/routes.py +++ b/application/api/answer/routes.py @@ -439,7 +439,7 @@ class Stream(Resource): try: question = data["question"] history = limit_chat_history( - json.loads(data.get("history", [])), gpt_model=gpt_model + json.loads(data.get("history", "[]")), gpt_model=gpt_model ) conversation_id = data.get("conversation_id") prompt_id = data.get("prompt_id", "default") @@ -451,8 +451,10 @@ class Stream(Resource): retriever_name = data.get("retriever", "classic") agent_id = data.get("agent_id", None) agent_type = settings.AGENT_NAME + decoded_token = getattr(request, "decoded_token", None) + user_sub = decoded_token.get("sub") if decoded_token else None agent_key, is_shared_usage, shared_token = get_agent_key( - agent_id, request.decoded_token.get("sub") + agent_id, user_sub ) if agent_key: