From 212952f3e95e21221dae05ab6423631405243444 Mon Sep 17 00:00:00 2001 From: Siddhant Rai Date: Fri, 25 Jul 2025 16:17:18 +0530 Subject: [PATCH] fix: allow api call in stream route + get_prompt error --- application/api/answer/routes/answer.py | 3 ++- application/api/answer/routes/stream.py | 2 -- application/api/answer/services/stream_processor.py | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/application/api/answer/routes/answer.py b/application/api/answer/routes/answer.py index 1ca23b7d..1b374638 100644 --- a/application/api/answer/routes/answer.py +++ b/application/api/answer/routes/answer.py @@ -63,7 +63,8 @@ class AnswerResource(Resource, BaseAnswerResource): data = request.get_json() if error := self.validate_request(data): return error - processor = StreamProcessor(data, None) + decoded_token = getattr(request, "decoded_token", None) + processor = StreamProcessor(data, decoded_token) try: processor.initialize() if not processor.decoded_token: diff --git a/application/api/answer/routes/stream.py b/application/api/answer/routes/stream.py index eb0ba6eb..09176147 100644 --- a/application/api/answer/routes/stream.py +++ b/application/api/answer/routes/stream.py @@ -70,8 +70,6 @@ class StreamResource(Resource, BaseAnswerResource): if error := self.validate_request(data, "index" in data): return error decoded_token = getattr(request, "decoded_token", None) - if not decoded_token: - return make_response({"error": "Unauthorized"}, 401) processor = StreamProcessor(data, decoded_token) try: processor.initialize() diff --git a/application/api/answer/services/stream_processor.py b/application/api/answer/services/stream_processor.py index 8c017a96..ac725898 100644 --- a/application/api/answer/services/stream_processor.py +++ b/application/api/answer/services/stream_processor.py @@ -41,7 +41,7 @@ def get_prompt(prompt_id: str, prompts_collection=None) -> str: except FileNotFoundError: raise FileNotFoundError(f"Prompt file not found: {file_path}") try: - if not prompts_collection: + if prompts_collection is None: mongo = MongoDB.get_client() db = mongo[settings.MONGO_DB_NAME] prompts_collection = db["prompts"]