Update interfaces/interface.py
Browse files- interfaces/interface.py +6 -13
interfaces/interface.py
CHANGED
|
@@ -5,35 +5,28 @@ from agents.agents_nodes import agent_node, format_output, tool_node
|
|
| 5 |
from utils.state_utils import AgentState
|
| 6 |
|
| 7 |
def create_interface():
|
| 8 |
-
|
| 9 |
graph = StateGraph(AgentState)
|
| 10 |
graph.add_node("agent", agent_node)
|
| 11 |
graph.add_node("tool", tool_node)
|
| 12 |
graph.add_node("format", format_output)
|
| 13 |
|
| 14 |
-
|
| 15 |
-
graph.
|
| 16 |
-
"agent",
|
| 17 |
-
lambda state: "tool" if state["messages"][-1].tool_calls else "format",
|
| 18 |
-
{"tool": "tool", "format": "format"}
|
| 19 |
-
)
|
| 20 |
graph.add_edge("tool", "format")
|
| 21 |
graph.add_edge("format", END)
|
| 22 |
-
|
| 23 |
-
|
| 24 |
|
| 25 |
app = graph.compile()
|
| 26 |
|
| 27 |
-
|
| 28 |
def process_query(query: str) -> dict:
|
| 29 |
try:
|
| 30 |
inputs = {"messages": [HumanMessage(content=query)]}
|
| 31 |
result = app.invoke(inputs)
|
| 32 |
-
return result
|
| 33 |
-
|
| 34 |
except Exception as e:
|
| 35 |
return {"error": f"Execution error: {str(e)}"}
|
| 36 |
|
|
|
|
| 37 |
with gr.Blocks(title="Time Value of Money Calculator") as interface:
|
| 38 |
gr.Markdown("## Time Value of Money Calculator")
|
| 39 |
gr.Markdown("Enter natural language queries about present/future value calculations")
|
|
@@ -52,4 +45,4 @@ def create_interface():
|
|
| 52 |
inputs=input_text,
|
| 53 |
outputs=output_json
|
| 54 |
)
|
| 55 |
-
return interface
|
|
|
|
| 5 |
from utils.state_utils import AgentState
|
| 6 |
|
| 7 |
def create_interface():
|
| 8 |
+
|
| 9 |
graph = StateGraph(AgentState)
|
| 10 |
graph.add_node("agent", agent_node)
|
| 11 |
graph.add_node("tool", tool_node)
|
| 12 |
graph.add_node("format", format_output)
|
| 13 |
|
| 14 |
+
graph.set_entry_point("agent")
|
| 15 |
+
graph.add_edge("agent", "tool")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
graph.add_edge("tool", "format")
|
| 17 |
graph.add_edge("format", END)
|
|
|
|
|
|
|
| 18 |
|
| 19 |
app = graph.compile()
|
| 20 |
|
|
|
|
| 21 |
def process_query(query: str) -> dict:
|
| 22 |
try:
|
| 23 |
inputs = {"messages": [HumanMessage(content=query)]}
|
| 24 |
result = app.invoke(inputs)
|
| 25 |
+
return messages_to_dict(result['messages'])[2]['data']['content']
|
|
|
|
| 26 |
except Exception as e:
|
| 27 |
return {"error": f"Execution error: {str(e)}"}
|
| 28 |
|
| 29 |
+
|
| 30 |
with gr.Blocks(title="Time Value of Money Calculator") as interface:
|
| 31 |
gr.Markdown("## Time Value of Money Calculator")
|
| 32 |
gr.Markdown("Enter natural language queries about present/future value calculations")
|
|
|
|
| 45 |
inputs=input_text,
|
| 46 |
outputs=output_json
|
| 47 |
)
|
| 48 |
+
return interface
|