2222 extract_loopid_func_name ,
2323 is_valid_session ,
2424)
25+ from rdagent .utils .agent .tpl import T
2526from rdagent .utils .repo .diff import generate_diff_from_dict
2627
2728if "show_stdout" not in state :
@@ -44,7 +45,7 @@ def convert_defaultdict_to_dict(d):
4445 return d
4546
4647
47- # @st.cache_data(persist=True)
48+ @st .cache_data (persist = True )
4849def load_data (log_path : Path ):
4950 data = defaultdict (lambda : defaultdict (dict ))
5051 llm_data = defaultdict (lambda : defaultdict (lambda : defaultdict (list )))
@@ -60,8 +61,6 @@ def load_data(log_path: Path):
6061 if ei is not None :
6162 ei = int (ei )
6263 if "debug_" in msg .tag :
63- if "debug_tpl" in msg .tag and "filter_" in msg .content ["uri" ]:
64- continue
6564 if ei is not None :
6665 llm_data [li ][fn ][ei ].append (
6766 {
@@ -201,9 +200,9 @@ def workspace_win(workspace, cmp_workspace=None, cmp_name="last code."):
201200def show_text (text , lang = None ):
202201 """显示文本代码块"""
203202 if lang :
204- st .code (text , language = lang , wrap_lines = True )
203+ st .code (text , language = lang , wrap_lines = True , line_numbers = True )
205204 elif "\n " in text :
206- st .code (text , language = "python" , wrap_lines = True )
205+ st .code (text , language = "python" , wrap_lines = True , line_numbers = True )
207206 else :
208207 st .code (text , language = "html" , wrap_lines = True )
209208
@@ -220,6 +219,8 @@ def llm_log_win(llm_d: list):
220219 for d in llm_d :
221220 if "debug_tpl" in d ["tag" ]:
222221 uri = d ["obj" ]["uri" ]
222+ if "filter_redundant_text" in uri :
223+ continue
223224 tpl = d ["obj" ]["template" ]
224225 cxt = d ["obj" ]["context" ]
225226 rd = d ["obj" ]["rendered" ]
@@ -240,32 +241,19 @@ def llm_log_win(llm_d: list):
240241 with t1 :
241242 try :
242243 rdict = json .loads (resp )
243- if "code" in rdict :
244- code = rdict ["code" ]
245- st .markdown (":red[**Code in response dict:**]" )
246- st .code (code , language = "python" , wrap_lines = True , line_numbers = True )
247- rdict .pop ("code" )
248- elif "spec" in rdict :
249- spec = rdict ["spec" ]
250- st .markdown (":red[**Spec in response dict:**]" )
251- st .markdown (spec )
252- rdict .pop ("spec" )
253- else :
254- showed_keys = []
255- for k , v in rdict .items ():
256- if k .endswith (".py" ):
257- st .markdown (f":red[**{ k } **]" )
258- st .code (v , language = "python" , wrap_lines = True , line_numbers = True )
259- showed_keys .append (k )
260- for k in showed_keys :
261- rdict .pop (k )
262- st .write (":red[**Other parts (except for the code or spec) in response dict:**]" )
244+ showed_keys = []
245+ for k , v in rdict .items ():
246+ if k .endswith (".py" ) or k .endswith (".md" ):
247+ st .markdown (f":red[**{ k } **]" )
248+ st .code (v , language = "python" , wrap_lines = True , line_numbers = True )
249+ showed_keys .append (k )
250+ for k in showed_keys :
251+ rdict .pop (k )
252+ if len (showed_keys ) > 0 :
253+ st .write (":red[**Other parts (except for the code or spec) in response dict:**]" )
263254 st .json (rdict )
264255 except :
265- try :
266- st .json (resp )
267- except :
268- show_text (resp )
256+ show_text (resp )
269257 with t2 :
270258 show_text (user )
271259 with t3 :
@@ -466,18 +454,37 @@ def replace_ep_path(p: Path):
466454 return p
467455
468456
457+ def get_llm_call_stats (llm_data : dict ) -> tuple [int , int ]:
458+ total_llm_call = 0
459+ total_filter_call = 0
460+ filter_sys_prompt = T ("rdagent.utils.prompts:filter_redundant_text.system" ).r ()
461+ for li , loop_d in llm_data .items ():
462+ for fn , loop_fn_d in loop_d .items ():
463+ for k , v in loop_fn_d .items ():
464+ for d in v :
465+ if "debug_llm" in d ["tag" ]:
466+ total_llm_call += 1
467+ if filter_sys_prompt == d ["obj" ]["system" ]:
468+ total_filter_call += 1
469+ return total_llm_call , total_filter_call
470+
471+
469472def summarize_win ():
470473 st .header ("Summary" , divider = "rainbow" )
471474 with st .container (border = True ):
472475 min_id , max_id = get_state_data_range (state .data )
473- info0 , info1 , info2 , info3 = st .columns ([2 , 1 , 1 , 1 ])
476+ info0 , info1 , info2 , info3 , info4 , info5 = st .columns ([1 , 1 , 1 , 1 , 1 , 1 ])
474477 show_trace_dag = info0 .toggle ("Show trace DAG" , key = "show_trace_dag" )
475- with info1 .popover ("LITELLM_SETTINGS" , icon = "⚙️" ):
476- st .write (state .data .get ("SETTINGS" , {}).get ("LITELLM_SETTINGS" , "No settings found." ))
477- with info2 .popover ("RD_AGENT_SETTINGS" , icon = "⚙️" ):
478- st .write (state .data .get ("SETTINGS" , {}).get ("RD_AGENT_SETTINGS" , "No settings found." ))
479- with info3 .popover ("RDLOOP_SETTINGS" , icon = "⚙️" ):
480- st .write (state .data .get ("SETTINGS" , {}).get ("RDLOOP_SETTINGS" , "No settings found." ))
478+ with info1 .popover ("LITELLM" , icon = "⚙️" ):
479+ st .write (state .data .get ("settings" , {}).get ("LITELLM_SETTINGS" , "No settings found." ))
480+ with info2 .popover ("RD_AGENT" , icon = "⚙️" ):
481+ st .write (state .data .get ("settings" , {}).get ("RD_AGENT_SETTINGS" , "No settings found." ))
482+ with info3 .popover ("RDLOOP" , icon = "⚙️" ):
483+ st .write (state .data .get ("settings" , {}).get ("RDLOOP_SETTINGS" , "No settings found." ))
484+
485+ llm_call , llm_filter_call = get_llm_call_stats (state .llm_data )
486+ info4 .metric ("LLM Calls" , llm_call )
487+ info5 .metric ("LLM Filter Calls" , f"{ llm_filter_call } ({ round (llm_filter_call / llm_call * 100 , 2 )} %)" )
481488 if show_trace_dag :
482489 st .markdown ("### Trace DAG" )
483490 final_trace_loop_id = max_id
0 commit comments