From 4383306770fccf11e8d2a2e274097ca70a33a3e2 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Tue, 26 Nov 2024 14:00:49 -0800 Subject: [PATCH] refac --- backend/open_webui/main.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/backend/open_webui/main.py b/backend/open_webui/main.py index 0dca21b08..aa936db47 100644 --- a/backend/open_webui/main.py +++ b/backend/open_webui/main.py @@ -531,9 +531,16 @@ async def chat_completion_files_handler( queries_response = queries_response["choices"][0]["message"]["content"] try: + bracket_start = queries_response.find("{") + bracket_end = queries_response.rfind("}") + 1 + + if bracket_start == -1 or bracket_end == -1: + raise Exception("No JSON object found in the response") + + queries_response = queries_response[bracket_start:bracket_end] queries_response = json.loads(queries_response) except Exception as e: - queries_response = {"queries": []} + queries_response = {"queries": [queries_response]} queries = queries_response.get("queries", []) except Exception as e: