acecalisto3 commited on
Commit
2619fce
·
verified ·
1 Parent(s): 5aaa1c7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -9
app.py CHANGED
@@ -191,14 +191,31 @@ class Agent:
191
  # Main application functions
192
  async def run(message: str, history: List[Tuple[str, str]]) -> str:
193
  """Process user input and generate a response using the agent system."""
194
- agent = Agent(
195
- name="CodeFusion",
196
- role="AI Coding Assistant",
197
- tools=[CodeGenerationTool(), CodeExplanationTool(), DebuggingTool()]
198
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
199
  context = "\n".join([f"Human: {h[0]}\nAI: {h[1]}" for h in history])
200
  try:
201
- response = await agent.act(message, context)
202
  return response
203
  except Exception as e:
204
  logger.error(f"Error processing request: {e}")
@@ -207,9 +224,9 @@ async def run(message: str, history: List[Tuple[str, str]]) -> str:
207
  async def main():
208
  """Main function to run the Gradio interface."""
209
  examples = [
210
- ["What is the purpose of this AI agent?", "I am an AI coding assistant designed to help with various programming tasks."],
211
- ["Can you help me generate a Python function to calculate the factorial of a number?", "Certainly! Here's a Python function to calculate the factorial of a number:"],
212
- ["Explain the concept of recursion in programming.", "Recursion is a programming concept where a function calls itself to solve a problem by breaking it down into smaller, similar subproblems."],
213
  ]
214
 
215
  gr.ChatInterface(
 
191
  # Main application functions
192
  async def run(message: str, history: List[Tuple[str, str]]) -> str:
193
  """Process user input and generate a response using the agent system."""
194
+ # Create a trio of agents for sequential app building
195
+ agent_structure = [
196
+ Agent("CodeFusion_Structure", "App Structure Designer", [CodeGenerationTool()]),
197
+ Agent("CodeFusion_Logic", "App Logic Implementer", [CodeGenerationTool(), CodeExplanationTool()]),
198
+ Agent("CodeFusion_UI", "App UI Designer", [CodeGenerationTool(), CodeExplanationTool(), DebuggingTool()])
199
+ ]
200
+
201
+ # Initialize the current agent based on the user's request
202
+ current_agent_index = 0
203
+ for i, agent in enumerate(agent_structure):
204
+ if "structure" in message.lower():
205
+ current_agent_index = i
206
+ break
207
+ elif "logic" in message.lower():
208
+ current_agent_index = i
209
+ break
210
+ elif "ui" in message.lower():
211
+ current_agent_index = i
212
+ break
213
+
214
+ # Use the selected agent to process the message
215
+ current_agent = agent_structure[current_agent_index]
216
  context = "\n".join([f"Human: {h[0]}\nAI: {h[1]}" for h in history])
217
  try:
218
+ response = await current_agent.act(message, context)
219
  return response
220
  except Exception as e:
221
  logger.error(f"Error processing request: {e}")
 
224
  async def main():
225
  """Main function to run the Gradio interface."""
226
  examples = [
227
+ ["Can you help me structure an app to manage a to-do list?", "Sure, here's a basic structure for a to-do list app:"],
228
+ ["Now, implement the logic for adding and deleting tasks.", "OK, here's the logic for adding and deleting tasks:"],
229
+ ["Finally, design a simple UI for the app.", "Here's a simple UI design for the to-do list app:"],
230
  ]
231
 
232
  gr.ChatInterface(