Spaces:
Runtime error
Runtime error
Update agent.py
Browse files
agent.py
CHANGED
|
@@ -15,35 +15,10 @@ class ReActAgent:
|
|
| 15 |
Initializes the agent with default tools, OpenAI LLM, and an empty history.
|
| 16 |
"""
|
| 17 |
self.tools = [TavilySearchResults(max_results=1)]
|
| 18 |
-
self.prompt =
|
| 19 |
-
Answer the following questions as best you can, considering the conversation history:
|
| 20 |
-
|
| 21 |
-
{history}
|
| 22 |
-
|
| 23 |
-
You have access to the following tools:
|
| 24 |
-
|
| 25 |
-
{tools}
|
| 26 |
-
|
| 27 |
-
Use the following format:
|
| 28 |
-
|
| 29 |
-
Question: the input question you must answer
|
| 30 |
-
Thought: you should always think about what to do
|
| 31 |
-
Action: the action to take (use history first, then tools if needed)
|
| 32 |
-
Action Input: the input to the action
|
| 33 |
-
Observation: the result of the action
|
| 34 |
-
... (this Thought/Action/Action Input/Observation can repeat N times)
|
| 35 |
-
Thought: I now know the final answer
|
| 36 |
-
Final Answer: the final answer to the original input question
|
| 37 |
-
|
| 38 |
-
Begin!
|
| 39 |
-
|
| 40 |
-
Question: {input}
|
| 41 |
-
Thought:{agent_scratchpad}
|
| 42 |
-
|
| 43 |
-
'''
|
| 44 |
self.llm = OpenAI()
|
| 45 |
|
| 46 |
-
def create_agent(self
|
| 47 |
"""
|
| 48 |
Creates a ReAct agent based on the defined prompt, LLM, and history.
|
| 49 |
"""
|
|
@@ -54,8 +29,8 @@ class ReActAgent:
|
|
| 54 |
"""
|
| 55 |
Executes the agent with the provided question, verbosity option, and updates history.
|
| 56 |
"""
|
| 57 |
-
agent = self.create_agent(
|
| 58 |
agent_executor = AgentExecutor(agent=agent, tools=self.tools, verbose=verbose)
|
| 59 |
-
answer = agent_executor.invoke({"input": question
|
| 60 |
return answer
|
| 61 |
|
|
|
|
| 15 |
Initializes the agent with default tools, OpenAI LLM, and an empty history.
|
| 16 |
"""
|
| 17 |
self.tools = [TavilySearchResults(max_results=1)]
|
| 18 |
+
self.prompt = hub.pull("hwchase17/react")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
self.llm = OpenAI()
|
| 20 |
|
| 21 |
+
def create_agent(self):
|
| 22 |
"""
|
| 23 |
Creates a ReAct agent based on the defined prompt, LLM, and history.
|
| 24 |
"""
|
|
|
|
| 29 |
"""
|
| 30 |
Executes the agent with the provided question, verbosity option, and updates history.
|
| 31 |
"""
|
| 32 |
+
agent = self.create_agent()
|
| 33 |
agent_executor = AgentExecutor(agent=agent, tools=self.tools, verbose=verbose)
|
| 34 |
+
answer = agent_executor.invoke({"input": question})
|
| 35 |
return answer
|
| 36 |
|