jcleee commited on
Commit
939e99c
·
verified ·
1 Parent(s): 75f1191

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -2
app.py CHANGED
@@ -122,12 +122,27 @@ agent = CodeAgent(
122
 
123
  import gradio as gr
124
 
 
 
 
 
 
 
 
 
 
125
  def run_agent(question):
126
  try:
127
- result = agent(question)
128
- return [str(result)] # Must return a list with one string (like ["answer"])
 
 
 
 
 
129
  except Exception as e:
130
  return [f"Error: {e}"]
131
 
 
132
  demo = gr.Interface(fn=run_agent, inputs="text", outputs="text")
133
  demo.launch()
 
122
 
123
  import gradio as gr
124
 
125
+ ## OLD VERSION
126
+ # def run_agent(question):
127
+ # try:
128
+ # result = agent(question)
129
+ # return [str(result)] # Must return a list with one string (like ["answer"])
130
+ # except Exception as e:
131
+ # return [f"Error: {e}"]
132
+
133
+ # NEW VERSION
134
  def run_agent(question):
135
  try:
136
+ steps = list(agent.run(question))
137
+ for step in reversed(steps):
138
+ if hasattr(step, "tool_calls"):
139
+ for call in step.tool_calls:
140
+ if call.name == "final_answer":
141
+ return [str(call.arguments.get("answer", "null"))]
142
+ return ["null"] # fallback
143
  except Exception as e:
144
  return [f"Error: {e}"]
145
 
146
+
147
  demo = gr.Interface(fn=run_agent, inputs="text", outputs="text")
148
  demo.launch()