Spaces:
Sleeping
Sleeping
Update agent.py
Browse files
agent.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import os
|
| 2 |
from typing import TypedDict, List, Dict, Any, Optional
|
|
|
|
| 3 |
from langgraph.graph import StateGraph, START, END
|
| 4 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 5 |
from langchain_core.tools import tool
|
|
@@ -113,8 +114,8 @@ class BasicAgent:
|
|
| 113 |
"""
|
| 114 |
self.app = self.__graph_compile__()
|
| 115 |
tools = [web_search, visit_webpage, read_file, image_caption]
|
| 116 |
-
self.model = model.bind_tools(tools) # LLM with tools
|
| 117 |
-
|
| 118 |
print("BasicAgent initialized.")
|
| 119 |
|
| 120 |
def __call__(self, question: str) -> str:
|
|
@@ -124,7 +125,7 @@ class BasicAgent:
|
|
| 124 |
("human", f"Question: {question}")
|
| 125 |
]
|
| 126 |
response = self.model.invoke(prompt_msg)
|
| 127 |
-
fixed_answer = response.content
|
| 128 |
# fixed_answer = "This is a default answer."
|
| 129 |
print(f"Agent returning fixed answer: {fixed_answer}")
|
| 130 |
return fixed_answer
|
|
|
|
| 1 |
import os
|
| 2 |
from typing import TypedDict, List, Dict, Any, Optional
|
| 3 |
+
from langgraph.prebuilt import create_react_agent
|
| 4 |
from langgraph.graph import StateGraph, START, END
|
| 5 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 6 |
from langchain_core.tools import tool
|
|
|
|
| 114 |
"""
|
| 115 |
self.app = self.__graph_compile__()
|
| 116 |
tools = [web_search, visit_webpage, read_file, image_caption]
|
| 117 |
+
# self.model = model.bind_tools(tools) # LLM with tools
|
| 118 |
+
self.agent = create_react_agent(model, tools)
|
| 119 |
print("BasicAgent initialized.")
|
| 120 |
|
| 121 |
def __call__(self, question: str) -> str:
|
|
|
|
| 125 |
("human", f"Question: {question}")
|
| 126 |
]
|
| 127 |
response = self.model.invoke(prompt_msg)
|
| 128 |
+
fixed_answer = response['message'][-1].content
|
| 129 |
# fixed_answer = "This is a default answer."
|
| 130 |
print(f"Agent returning fixed answer: {fixed_answer}")
|
| 131 |
return fixed_answer
|