SergeyO7 commited on
Commit
ce04a23
·
verified ·
1 Parent(s): 68b9556

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -17
app.py CHANGED
@@ -18,26 +18,27 @@ hub_stats_tool = HubStatsTool()
18
  # Load the guest dataset and initialize the guest info tool
19
  guest_info_tool = load_guest_dataset()
20
 
21
- # Create Alfred with all the tools
22
- alfred = CodeAgent(
23
- tools=[guest_info_tool, weather_info_tool, hub_stats_tool, search_tool],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  model=model,
25
  add_base_tools=True, # Add any additional base tools
26
  planning_interval=3 # Enable planning every 3 steps
27
  )
28
 
29
- # Wrapper function to handle agent responses and format for GradioUI
30
- def process_agent_response(user_input):
31
- # Run the agent with reset=False to maintain conversation memory
32
- response = alfred.run(user_input, reset=False)
33
-
34
- # Convert response to a string if it’s a dictionary
35
- if isinstance(response, dict):
36
- response_str = "\n".join([f"{key}: {value}" for key, value in response.items()])
37
- else:
38
- response_str = str(response)
39
-
40
- return response_str
41
-
42
  # Launch the GradioUI interface
43
- GradioUI(alfred, process_function=process_agent_response).launch()
 
18
  # Load the guest dataset and initialize the guest info tool
19
  guest_info_tool = load_guest_dataset()
20
 
21
+ # Custom agent class to format responses
22
+ class FormattedCodeAgent(CodeAgent):
23
+ def run(self, prompt, reset=True, **kwargs):
24
+ # Call the parent class's run method
25
+ response = super().run(prompt, reset=reset, **kwargs)
26
+
27
+ # Convert response to a string if it’s a dictionary
28
+ if isinstance(response, dict):
29
+ response_str = "\n".join([f"{key}: {value}" for key, value in response.items()])
30
+ else:
31
+ response_str = str(response)
32
+
33
+ return response_str
34
+
35
+ # Create Alfred with formatted responses
36
+ alfred = FormattedCodeAgent(
37
+ tools=[guest_info_tool, weather_info_tool, hub_stats_tool, search_tool],
38
  model=model,
39
  add_base_tools=True, # Add any additional base tools
40
  planning_interval=3 # Enable planning every 3 steps
41
  )
42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  # Launch the GradioUI interface
44
+ GradioUI(alfred).launch()