2020from infra .observability .token_usage import TokenUtils
2121from llm_utils .graph_utils .enriched_graph import builder as enriched_builder
2222from llm_utils .graph_utils .basic_graph import builder
23- from llm_utils .graph_utils .simplified_graph import builder as simplified_builder
2423
2524
2625TITLE = "Lang2SQL"
@@ -61,7 +60,6 @@ def execute_query(
6160 dict: 다음 정보를 포함한 Lang2SQL 실행 결과 딕셔너리:
6261 - "generated_query": 생성된 SQL 쿼리 (`AIMessage`)
6362 - "messages": 전체 LLM 응답 메시지 목록
64- - "refined_input": AI가 재구성한 입력 질문
6563 - "searched_tables": 참조된 테이블 목록 등 추가 정보
6664 """
6765
@@ -72,7 +70,6 @@ def execute_query(
7270 top_n = top_n ,
7371 device = device ,
7472 use_enriched_graph = st .session_state .get ("use_enriched" , False ),
75- use_simplified_graph = st .session_state .get ("use_simplified" , False ),
7673 session_state = st .session_state ,
7774 )
7875
@@ -164,7 +161,17 @@ def should_show(_key: str) -> bool:
164161 if should_show ("show_question_reinterpreted_by_ai" ):
165162 st .markdown ("---" )
166163 st .markdown ("**AI가 재해석한 사용자 질문:**" )
167- st .code (res ["refined_input" ].content )
164+ try :
165+ if len (res ["messages" ]) > 1 :
166+ candidate = res ["messages" ][ - 2 ]
167+ question_text = (
168+ candidate .content if hasattr (candidate , "content" ) else str (candidate )
169+ )
170+ else :
171+ question_text = res ["messages" ][0 ].content
172+ except Exception :
173+ question_text = str (res ["messages" ][0 ].content )
174+ st .code (question_text )
168175
169176 if should_show ("show_referenced_tables" ):
170177 st .markdown ("---" )
@@ -200,8 +207,19 @@ def should_show(_key: str) -> bool:
200207 sql = LLMResponseParser .extract_sql (sql_raw )
201208 df = database .run_sql (sql )
202209 st .markdown ("**쿼리 결과 시각화:**" )
210+ try :
211+ if len (res ["messages" ]) > 1 :
212+ candidate = res ["messages" ][ - 2 ]
213+ chart_question = (
214+ candidate .content if hasattr (candidate , "content" ) else str (candidate )
215+ )
216+ else :
217+ chart_question = res ["messages" ][0 ].content
218+ except Exception :
219+ chart_question = str (res ["messages" ][0 ].content )
220+
203221 display_code = DisplayChart (
204- question = res [ "refined_input" ]. content ,
222+ question = chart_question ,
205223 sql = sql ,
206224 df_metadata = f"Running df.dtypes gives:\n { df .dtypes } " ,
207225 )
@@ -225,21 +243,14 @@ def should_show(_key: str) -> bool:
225243use_enriched = st .sidebar .checkbox (
226244 "프로파일 추출 & 컨텍스트 보강 워크플로우 사용" , value = False
227245)
228- use_simplified = st .sidebar .checkbox (
229- "단순화된 워크플로우 사용 (QUERY_REFINER 제거)" , value = False
230- )
231246
232247# 세션 상태 초기화
233248if (
234249 "graph" not in st .session_state
235250 or st .session_state .get ("use_enriched" ) != use_enriched
236- or st .session_state .get ("use_simplified" ) != use_simplified
237251):
238252 # 그래프 선택 로직
239- if use_simplified :
240- graph_builder = simplified_builder
241- graph_type = "단순화된"
242- elif use_enriched :
253+ if use_enriched :
243254 graph_builder = enriched_builder
244255 graph_type = "확장된"
245256 else :
@@ -248,16 +259,12 @@ def should_show(_key: str) -> bool:
248259
249260 st .session_state ["graph" ] = graph_builder .compile ()
250261 st .session_state ["use_enriched" ] = use_enriched
251- st .session_state ["use_simplified" ] = use_simplified
252262 st .info (f"Lang2SQL이 성공적으로 시작되었습니다. ({ graph_type } 워크플로우)" )
253263
254264# 새로고침 버튼 추가
255265if st .sidebar .button ("Lang2SQL 새로고침" ):
256266 # 그래프 선택 로직
257- if st .session_state .get ("use_simplified" ):
258- graph_builder = simplified_builder
259- graph_type = "단순화된"
260- elif st .session_state .get ("use_enriched" ):
267+ if st .session_state .get ("use_enriched" ):
261268 graph_builder = enriched_builder
262269 graph_type = "확장된"
263270 else :
0 commit comments