@@ -560,6 +560,8 @@ async def start_conversation(
560
560
sql_data = conversation_request .sql_data
561
561
chart_schema = conversation_request .chart_schema
562
562
index = 0
563
+ has_sql = False
564
+ sql = ""
563
565
564
566
try :
565
567
await self ._query_event_manager .emit_message_start (
@@ -888,7 +890,6 @@ async def start_conversation(
888
890
should_put_in_conversation_history = True ,
889
891
)
890
892
891
- sql = ""
892
893
if failed_dry_run_results := text_to_sql_generation_results [
893
894
"post_process"
894
895
]["invalid_generation_results" ]:
@@ -931,6 +932,7 @@ async def start_conversation(
931
932
sql = sql_correction_results ["post_process" ][
932
933
"valid_generation_results"
933
934
][0 ]["sql" ]
935
+ has_sql = True
934
936
else :
935
937
await self ._query_event_manager .emit_error (
936
938
query_id = query_id ,
@@ -945,34 +947,12 @@ async def start_conversation(
945
947
sql = text_to_sql_generation_results ["post_process" ][
946
948
"valid_generation_results"
947
949
][0 ]["sql" ]
948
-
949
- if sql :
950
- sql_data = await self ._run_sql_executor (
951
- sql = sql ,
952
- project_id = project_id ,
953
- )
954
-
955
- (
956
- _ ,
957
- index ,
958
- ) = await self ._query_event_manager .emit_content_block (
959
- query_id ,
960
- trace_id ,
961
- index = index ,
962
- emit_content_func = self ._run_sql_answer ,
963
- emit_content_func_kwargs = {
964
- "query" : user_query ,
965
- "sql" : sql ,
966
- "sql_data" : sql_data ,
967
- "configurations" : configurations ,
968
- "query_id" : query_id ,
969
- },
970
- content_block_label = "SQL_ANSWER" ,
971
- block_type = "text" ,
972
- stream = True ,
973
- )
950
+ has_sql = True
974
951
else :
952
+ has_sql = True
975
953
sql = historical_question_result ["sql" ]
954
+
955
+ if has_sql :
976
956
sql_data = await self ._run_sql_executor (
977
957
sql = sql ,
978
958
project_id = project_id ,
0 commit comments