jcleee commited on
Commit
767889a
·
verified ·
1 Parent(s): c21837e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -29
app.py CHANGED
@@ -122,40 +122,40 @@ agent = CodeAgent(
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
- # Get all steps from the agent run
137
- steps = list(agent.run(question, stream=False))
138
-
139
- # Look through all tool calls to find final_answer
140
- for step in steps:
141
- if hasattr(step, "tool_calls") and step.tool_calls:
142
- for call in step.tool_calls:
143
- if call.name == "final_answer":
144
- answer = call.arguments.get("answer", None)
145
- if answer:
146
- return [str(answer)]
147
-
148
- # Fallback: try tool_output or .final_answer if FinalAnswerStep
149
- for step in reversed(steps):
150
- if hasattr(step, "tool_output") and step.tool_output:
151
- return [str(step.tool_output)]
152
- if hasattr(step, "final_answer") and step.final_answer:
153
- return [str(step.final_answer)]
154
-
155
- return ["null"]
156
  except Exception as e:
157
  return [f"Error: {e}"]
158
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
 
160
 
161
  demo = gr.Interface(fn=run_agent, inputs="text", outputs="text")
 
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
+ # # Get all steps from the agent run
137
+ # steps = list(agent.run(question, stream=False))
138
+
139
+ # # Look through all tool calls to find final_answer
140
+ # for step in steps:
141
+ # if hasattr(step, "tool_calls") and step.tool_calls:
142
+ # for call in step.tool_calls:
143
+ # if call.name == "final_answer":
144
+ # answer = call.arguments.get("answer", None)
145
+ # if answer:
146
+ # return [str(answer)]
147
+
148
+ # # Fallback: try tool_output or .final_answer if FinalAnswerStep
149
+ # for step in reversed(steps):
150
+ # if hasattr(step, "tool_output") and step.tool_output:
151
+ # return [str(step.tool_output)]
152
+ # if hasattr(step, "final_answer") and step.final_answer:
153
+ # return [str(step.final_answer)]
154
+
155
+ # return ["null"]
156
+ # except Exception as e:
157
+ # return [f"Error: {e}"]
158
+
159
 
160
 
161
  demo = gr.Interface(fn=run_agent, inputs="text", outputs="text")