2323from crab .benchmarks .template import template_benchmark_config
2424from camel .types import ModelType , ModelPlatformType
2525
26-
26+ # TODO: Add new benchmark template
2727def start_benchmark (benchmark : Benchmark , agent : SingleAgentPolicy ):
2828 for step in range (20 ):
2929 print ("=" * 40 )
3030 print (f"Start agent step { step } :" )
3131 observation = benchmark .observe ()["template_env" ]
3232 print (f"Current environment observation: { observation } " )
33+
34+ try :
35+ rag_content = agent .model_backend .get_relevant_content (str (observation ))
36+ print (colored ("\n Relevant RAG content:" , "magenta" ))
37+ if rag_content :
38+ for idx , content in enumerate (rag_content , 1 ):
39+ print (colored (f"\n Document { idx } :" , "magenta" ))
40+ if isinstance (content , dict ):
41+ print (colored (f"Source: { content .get ('content path' , 'Unknown' )} " , "yellow" ))
42+ print (colored (f"Content: { content .get ('text' , '' )[:500 ]} ..." , "white" ))
43+ else :
44+ print (colored (f"Content: { str (content )[:500 ]} ..." , "white" ))
45+ else :
46+ print (colored ("No relevant content found" , "yellow" ))
47+ except Exception as e :
48+ print (colored (f"Error retrieving RAG content: { str (e )} " , "red" ))
49+
3350 response = agent .chat (
3451 {
3552 "template_env" : [
3653 (f"Current environment observation: { observation } " , 0 ),
3754 ]
3855 }
3956 )
40- print (colored (f"Agent take action: { response } " , "blue" ))
57+ print (colored (f"\n Agent take action: { response } " , "blue" ))
4158
4259 for action in response :
4360 response = benchmark .step (
@@ -74,7 +91,6 @@ def prepare_vim_docs():
7491 response = requests .get (base_url )
7592 soup = BeautifulSoup (response .text , 'html.parser' )
7693
77- # Process the main page first
7894 main_content = soup .get_text (separator = '\n ' , strip = True )
7995 with open (os .path .join (content_dir , "main.txt" ), 'w' , encoding = 'utf-8' ) as f :
8096 f .write (f"Source: { base_url } \n \n { main_content } " )
@@ -91,14 +107,12 @@ def prepare_vim_docs():
91107 try :
92108 print (colored (f"Processing page { idx } /{ total_links } : { href } " , "yellow" ))
93109
94- # Fetch and process page
95110 page_response = requests .get (full_url )
96111 page_soup = BeautifulSoup (page_response .text , 'html.parser' )
97112 for tag in page_soup (['script' , 'style' ]):
98113 tag .decompose ()
99114 content = page_soup .get_text (separator = '\n ' , strip = True )
100115
101- # Save content
102116 filename = os .path .join (content_dir , f"{ href .replace ('/' , '_' )} .txt" )
103117 with open (filename , 'w' , encoding = 'utf-8' ) as f :
104118 f .write (f"Source: { full_url } \n \n { content } " )
@@ -115,7 +129,6 @@ def prepare_vim_docs():
115129if __name__ == "__main__" :
116130 print (colored ("=== Starting RAG-enhanced benchmark ===" , "cyan" ))
117131
118- # Initialize benchmark and environment
119132 print (colored ("\n Initializing benchmark environment..." , "yellow" ))
120133 benchmark = create_benchmark (template_benchmark_config )
121134 task , action_space = benchmark .start_task ("0" )
0 commit comments