Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,26 +17,26 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 17 |
|
| 18 |
# --- Basic Agent Definition ---
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
def assistant(state: AgentState):
|
| 25 |
return {
|
| 26 |
"messages": [chat_with_tools.invoke(state["messages"])],
|
| 27 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
class BasicAgent:
|
| 30 |
|
| 31 |
def __init__(self, llm_checkpoint):
|
| 32 |
-
llm = HuggingFaceEndpoint(repo_id=llm_checkpoint)
|
| 33 |
-
chat = ChatHuggingFace(llm=llm, verbose=True)
|
| 34 |
-
self.tools = [
|
| 35 |
-
search_tool
|
| 36 |
-
]
|
| 37 |
-
chat_with_tools = chat.bind_tools(self.tools)
|
| 38 |
self.graph = self._build_graph()
|
| 39 |
-
|
| 40 |
print("BasicAgent initialized.")
|
| 41 |
|
| 42 |
def __call__(self, question: str) -> str:
|
|
@@ -50,7 +50,7 @@ class BasicAgent:
|
|
| 50 |
def _build_graph(self):
|
| 51 |
graph = StateGraph(AgentState)
|
| 52 |
graph.add_node("assistant", assistant)
|
| 53 |
-
graph.add_node("tools", ToolNode(
|
| 54 |
graph.add_edge(START, "assistant")
|
| 55 |
graph.add_conditional_edges("assistant", tools_condition)
|
| 56 |
graph.add_edge("tools", "assistant")
|
|
|
|
| 17 |
|
| 18 |
# --- Basic Agent Definition ---
|
| 19 |
|
| 20 |
+
llm = HuggingFaceEndpoint(repo_id=llm_checkpoint)
|
| 21 |
+
chat = ChatHuggingFace(llm=llm, verbose=True)
|
| 22 |
+
tools = [
|
| 23 |
+
search_tool
|
| 24 |
+
]
|
| 25 |
+
chat_with_tools = chat.bind_tools(self.tools)
|
| 26 |
|
| 27 |
def assistant(state: AgentState):
|
| 28 |
return {
|
| 29 |
"messages": [chat_with_tools.invoke(state["messages"])],
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
# Generate the AgentState and Agent graph
|
| 33 |
+
class AgentState(TypedDict):
|
| 34 |
+
messages: Annotated[list[AnyMessage], add_messages]
|
| 35 |
|
| 36 |
class BasicAgent:
|
| 37 |
|
| 38 |
def __init__(self, llm_checkpoint):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
self.graph = self._build_graph()
|
|
|
|
| 40 |
print("BasicAgent initialized.")
|
| 41 |
|
| 42 |
def __call__(self, question: str) -> str:
|
|
|
|
| 50 |
def _build_graph(self):
|
| 51 |
graph = StateGraph(AgentState)
|
| 52 |
graph.add_node("assistant", assistant)
|
| 53 |
+
graph.add_node("tools", ToolNode(tools))
|
| 54 |
graph.add_edge(START, "assistant")
|
| 55 |
graph.add_conditional_edges("assistant", tools_condition)
|
| 56 |
graph.add_edge("tools", "assistant")
|