From f657721467069b21a408d41c4de20aa53c3aa4dd Mon Sep 17 00:00:00 2001 From: junjun Date: Tue, 15 Jul 2025 18:07:14 +0800 Subject: [PATCH] feat: chat --- backend/apps/chat/task/llm.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/backend/apps/chat/task/llm.py b/backend/apps/chat/task/llm.py index 9a7b5613..060bacc9 100644 --- a/backend/apps/chat/task/llm.py +++ b/backend/apps/chat/task/llm.py @@ -746,7 +746,21 @@ def run_task(llm_service: LLMService, in_chat: bool = True): # todo row permission sql_json_str = extract_nested_json(full_sql_text) data = orjson.loads(sql_json_str) - sql_result = llm_service.generate_filter(data['sql'], data['tables']) # maybe no sql and tables + + sql = '' + message = '' + error = False + if data['success']: + sql = data['sql'] + else: + message = data['message'] + error = True + if error: + raise Exception(message) + if sql.strip() == '': + raise Exception("SQL query is empty") + + sql_result = llm_service.generate_filter(data.get('sql'), data.get('tables')) # maybe no sql and tables print(sql_result) sql = llm_service.check_save_sql(res=sql_result) # sql = llm_service.check_save_sql(res=full_sql_text)