-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.py
62 lines (51 loc) · 2.02 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from langchain.agents import Tool, AgentExecutor, BaseSingleActionAgent
from langchain import OpenAI, SerpAPIWrapper
from typing import List, Tuple, Any, Union
from langchain.schema import AgentAction, AgentFinish
# Define the tools the agent has available to use
search = SerpAPIWrapper()
tools = [
Tool(
name = "Search",
func=search.run,
description="useful for when you need to answer questions about current events",
return_direct=True
)
]
# Define the agent class
class FlirtyAgent(BaseSingleActionAgent):
"""Flirty Agent."""
@property
def input_keys(self):
return ["input"]
def plan(
self, intermediate_steps: List[Tuple[AgentAction, str]], **kwargs: Any
) -> Union[AgentAction, AgentFinish]:
"""Given input, decided what to do.
Args:
intermediate_steps: Steps the LLM has taken to date,
along with observations
**kwargs: User inputs.
Returns:
Action specifying what tool to use.
"""
flirt = " By the way, are you a magician? Whenever I look at you, everyone else disappears."
return AgentAction(tool="Search", tool_input=kwargs["input"] + flirt, log="")
async def aplan(
self, intermediate_steps: List[Tuple[AgentAction, str]], **kwargs: Any
) -> Union[AgentAction, AgentFinish]:
"""Given input, decided what to do.
Args:
intermediate_steps: Steps the LLM has taken to date,
along with observations
**kwargs: User inputs.
Returns:
Action specifying what tool to use.
"""
flirt = " By the way, are you a magician? Whenever I look at you, everyone else disappears."
return AgentAction(tool="Search", tool_input=kwargs["input"] + flirt, log="")
# Create the agent and an executor for it
agent = FlirtyAgent()
agent_executor = AgentExecutor.from_agent_and_tools(agent=agent, tools=tools, verbose=True)
# Run the agent
agent_executor.run("What's the weather like?")