Skip to content

Commit 449d478

Browse files
committed
refactor
1 parent 6a94da8 commit 449d478

File tree

1 file changed

+7
-27
lines changed

1 file changed

+7
-27
lines changed

β€Žwren-ai-service/src/web/v2/services/conversation.py

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,8 @@ async def start_conversation(
560560
sql_data = conversation_request.sql_data
561561
chart_schema = conversation_request.chart_schema
562562
index = 0
563+
has_sql = False
564+
sql = ""
563565

564566
try:
565567
await self._query_event_manager.emit_message_start(
@@ -888,7 +890,6 @@ async def start_conversation(
888890
should_put_in_conversation_history=True,
889891
)
890892

891-
sql = ""
892893
if failed_dry_run_results := text_to_sql_generation_results[
893894
"post_process"
894895
]["invalid_generation_results"]:
@@ -931,6 +932,7 @@ async def start_conversation(
931932
sql = sql_correction_results["post_process"][
932933
"valid_generation_results"
933934
][0]["sql"]
935+
has_sql = True
934936
else:
935937
await self._query_event_manager.emit_error(
936938
query_id=query_id,
@@ -945,34 +947,12 @@ async def start_conversation(
945947
sql = text_to_sql_generation_results["post_process"][
946948
"valid_generation_results"
947949
][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
974951
else:
952+
has_sql = True
975953
sql = historical_question_result["sql"]
954+
955+
if has_sql:
976956
sql_data = await self._run_sql_executor(
977957
sql=sql,
978958
project_id=project_id,

0 commit comments

Comments
Β (0)