Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -121,7 +121,7 @@ def excel_tool(state: AgentState) -> AgentState:
|
|
121 |
|
122 |
# ------------- final answer -------------
|
123 |
|
124 |
-
def
|
125 |
wrap = SystemMessage(
|
126 |
content="Using everything so far, reply ONLY with {'final_answer':'β¦'}. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string."
|
127 |
)
|
@@ -141,7 +141,7 @@ for name, fn in [
|
|
141 |
("wiki_tool", wiki_tool),
|
142 |
("ocr_tool", ocr_tool),
|
143 |
("audio_tool", audio_tool),
|
144 |
-
("
|
145 |
]:
|
146 |
graph.add_node(name, fn)
|
147 |
|
@@ -153,8 +153,9 @@ def dispatch(state: AgentState) -> str:
|
|
153 |
"wiki": "wiki_tool",
|
154 |
"ocr": "ocr_tool",
|
155 |
"audio": "audio_tool",
|
156 |
-
"
|
157 |
-
|
|
|
158 |
|
159 |
graph.add_conditional_edges(
|
160 |
"tool_selector",
|
@@ -164,7 +165,7 @@ graph.add_conditional_edges(
|
|
164 |
"ocr_tool": "ocr_tool",
|
165 |
"audio_tool": "audio_tool",
|
166 |
"excel_tool": "excel_tool",
|
167 |
-
"
|
168 |
},
|
169 |
)
|
170 |
|
@@ -173,13 +174,13 @@ for tool_name in ("wiki_tool", "ocr_tool", "audio_tool", "excel_tool"):
|
|
173 |
graph.add_edge(tool_name, "tool_selector")
|
174 |
|
175 |
# final_answer β END
|
176 |
-
graph.add_edge("
|
177 |
|
178 |
compiled_graph = graph.compile()
|
179 |
|
180 |
# βββββββββββββββββββββββββββ Public API ββββββββββββββββββββββββββββββββ
|
181 |
|
182 |
-
def answer(question: str,
|
183 |
state = AgentState(user_question=question, task_id=task_id)
|
184 |
state.add(SystemMessage(content="You are a helpful assistant."))
|
185 |
state.add(HumanMessage(content=question))
|
@@ -210,7 +211,7 @@ class BasicAgent:
|
|
210 |
|
211 |
print(f"Agent received question: {question}")
|
212 |
print()
|
213 |
-
return
|
214 |
# return fixed_answer
|
215 |
|
216 |
|
|
|
121 |
|
122 |
# ------------- final answer -------------
|
123 |
|
124 |
+
def final_node(state: AgentState) -> AgentState:
|
125 |
wrap = SystemMessage(
|
126 |
content="Using everything so far, reply ONLY with {'final_answer':'β¦'}. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string."
|
127 |
)
|
|
|
141 |
("wiki_tool", wiki_tool),
|
142 |
("ocr_tool", ocr_tool),
|
143 |
("audio_tool", audio_tool),
|
144 |
+
("final_node", final_node),
|
145 |
]:
|
146 |
graph.add_node(name, fn)
|
147 |
|
|
|
153 |
"wiki": "wiki_tool",
|
154 |
"ocr": "ocr_tool",
|
155 |
"audio": "audio_tool",
|
156 |
+
"excel": "excel_tool",
|
157 |
+
"final": "final_node",
|
158 |
+
}.get(state.next_action, "final_node")
|
159 |
|
160 |
graph.add_conditional_edges(
|
161 |
"tool_selector",
|
|
|
165 |
"ocr_tool": "ocr_tool",
|
166 |
"audio_tool": "audio_tool",
|
167 |
"excel_tool": "excel_tool",
|
168 |
+
"final_node": "final_node",
|
169 |
},
|
170 |
)
|
171 |
|
|
|
174 |
graph.add_edge(tool_name, "tool_selector")
|
175 |
|
176 |
# final_answer β END
|
177 |
+
graph.add_edge("final_node", END)
|
178 |
|
179 |
compiled_graph = graph.compile()
|
180 |
|
181 |
# βββββββββββββββββββββββββββ Public API ββββββββββββββββββββββββββββββββ
|
182 |
|
183 |
+
def answer(question: str, task_id: Optional[str] = None) -> str:
|
184 |
state = AgentState(user_question=question, task_id=task_id)
|
185 |
state.add(SystemMessage(content="You are a helpful assistant."))
|
186 |
state.add(HumanMessage(content=question))
|
|
|
211 |
|
212 |
print(f"Agent received question: {question}")
|
213 |
print()
|
214 |
+
return answer(question, task_id)
|
215 |
# return fixed_answer
|
216 |
|
217 |
|