Spaces:
Sleeping
Sleeping
graph test
Browse files
app.py
CHANGED
|
@@ -68,13 +68,15 @@ class BasicAgent:
|
|
| 68 |
self.graph.add_node("final_answer", self.final_answer)
|
| 69 |
|
| 70 |
self.graph.add_edge(START, "log_question")
|
| 71 |
-
self.graph.add_edge("log_question", "try_answer")
|
| 72 |
|
| 73 |
# Add conditional edges
|
| 74 |
self.graph.add_conditional_edges(
|
| 75 |
-
"
|
| 76 |
self.try_answer,
|
| 77 |
-
{
|
|
|
|
|
|
|
|
|
|
| 78 |
)
|
| 79 |
|
| 80 |
self.graph.add_edge("final_answer", END)
|
|
@@ -91,17 +93,19 @@ class BasicAgent:
|
|
| 91 |
)
|
| 92 |
return str(res)
|
| 93 |
|
| 94 |
-
def log_question(self, state: AnswerState) ->
|
| 95 |
-
print(f"Agent received question
|
|
|
|
| 96 |
|
| 97 |
def final_answer(self, state: AnswerState) -> str:
|
| 98 |
print(f"Agent returning answer: {state['answer']}")
|
| 99 |
return state["answer"] if state["answer"] else "I don't know"
|
| 100 |
|
| 101 |
def try_answer(self, state: AnswerState) -> str:
|
| 102 |
-
|
| 103 |
messages = [HumanMessage(content=PROMPT.format(question=state["question"]))]
|
| 104 |
response = self.model.invoke(messages)
|
|
|
|
|
|
|
| 105 |
txt = response.text().split("FINAL ANSWER:")
|
| 106 |
print(f"Agent returning answer: {txt}")
|
| 107 |
answer = txt[-1].strip() if len(txt) > 1 else "I don't know."
|
|
|
|
| 68 |
self.graph.add_node("final_answer", self.final_answer)
|
| 69 |
|
| 70 |
self.graph.add_edge(START, "log_question")
|
|
|
|
| 71 |
|
| 72 |
# Add conditional edges
|
| 73 |
self.graph.add_conditional_edges(
|
| 74 |
+
"log_question",
|
| 75 |
self.try_answer,
|
| 76 |
+
{
|
| 77 |
+
"FINAL_ANSWER": "final_answer",
|
| 78 |
+
"SOME_TOOL": "final_answer",
|
| 79 |
+
},
|
| 80 |
)
|
| 81 |
|
| 82 |
self.graph.add_edge("final_answer", END)
|
|
|
|
| 93 |
)
|
| 94 |
return str(res)
|
| 95 |
|
| 96 |
+
def log_question(self, state: AnswerState) -> Dict[str, Any]:
|
| 97 |
+
print(f"Agent received question: {state['question']}...")
|
| 98 |
+
return {}
|
| 99 |
|
| 100 |
def final_answer(self, state: AnswerState) -> str:
|
| 101 |
print(f"Agent returning answer: {state['answer']}")
|
| 102 |
return state["answer"] if state["answer"] else "I don't know"
|
| 103 |
|
| 104 |
def try_answer(self, state: AnswerState) -> str:
|
|
|
|
| 105 |
messages = [HumanMessage(content=PROMPT.format(question=state["question"]))]
|
| 106 |
response = self.model.invoke(messages)
|
| 107 |
+
print(f"Agent response: {response.content}")
|
| 108 |
+
|
| 109 |
txt = response.text().split("FINAL ANSWER:")
|
| 110 |
print(f"Agent returning answer: {txt}")
|
| 111 |
answer = txt[-1].strip() if len(txt) > 1 else "I don't know."
|