@@ -515,6 +515,18 @@ async def _run_sql_executor(
515
515
516
516
return sql_data
517
517
518
+ async def _run_preview_data (
519
+ self ,
520
+ data : Dict ,
521
+ ):
522
+ return [
523
+ {
524
+ "data" : data ,
525
+ }
526
+ ], {
527
+ "data" : data ,
528
+ }
529
+
518
530
def _run_sql_answer (
519
531
self ,
520
532
query : str ,
@@ -747,7 +759,10 @@ async def start_conversation(
747
759
should_put_in_conversation_history = True ,
748
760
)
749
761
else :
750
- _ , index = await self ._query_event_manager .emit_content_block (
762
+ (
763
+ chart_generation_result ,
764
+ index ,
765
+ ) = await self ._query_event_manager .emit_content_block (
751
766
query_id ,
752
767
trace_id ,
753
768
index = index ,
@@ -762,6 +777,27 @@ async def start_conversation(
762
777
block_type = "tool_use" ,
763
778
should_put_in_conversation_history = True ,
764
779
)
780
+
781
+ if chart_schema := chart_generation_result .get (
782
+ "chart_result" , {}
783
+ ).get ("chart_schema" ):
784
+ (
785
+ _ ,
786
+ index ,
787
+ ) = await self ._query_event_manager .emit_content_block (
788
+ query_id ,
789
+ trace_id ,
790
+ index = index ,
791
+ emit_content_func = self ._run_preview_data ,
792
+ emit_content_func_kwargs = {
793
+ "data" : {
794
+ "chart_schema" : chart_schema ,
795
+ },
796
+ },
797
+ content_block_label = "PREVIEW_DATA" ,
798
+ block_type = "tool_use" ,
799
+ )
800
+
765
801
else : # TEXT_TO_SQL
766
802
(
767
803
retrieval_results ,
@@ -949,10 +985,24 @@ async def start_conversation(
949
985
][0 ]["sql" ]
950
986
has_sql = True
951
987
else :
952
- has_sql = True
953
988
sql = historical_question_result ["sql" ]
989
+ has_sql = True
954
990
955
991
if has_sql :
992
+ _ , index = await self ._query_event_manager .emit_content_block (
993
+ query_id ,
994
+ trace_id ,
995
+ index = index ,
996
+ emit_content_func = self ._run_preview_data ,
997
+ emit_content_func_kwargs = {
998
+ "data" : {
999
+ "sql" : sql ,
1000
+ },
1001
+ },
1002
+ content_block_label = "PREVIEW_DATA" ,
1003
+ block_type = "tool_use" ,
1004
+ )
1005
+
956
1006
sql_data = await self ._run_sql_executor (
957
1007
sql = sql ,
958
1008
project_id = project_id ,
0 commit comments