-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.py
98 lines (88 loc) · 3.11 KB
/
main.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
from langchain.agents import AgentExecutor, create_tool_calling_agent
from langchain.memory import ConversationBufferMemory
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
from langchain_mistralai import ChatMistralAI
from hyperpocket.config import secret
from hyperpocket.tool import from_git
from hyperpocket_langchain import PocketLangchain
def agent(pocket: PocketLangchain):
tools = pocket.get_tools()
llm = ChatMistralAI(model="mistral-large-latest", api_key=secret["MISTRAL_API_KEY"])
prompt = ChatPromptTemplate.from_messages(
[
(
"system",
"You are a tool calling assistant. You can help the user by calling proper tools",
),
("placeholder", "{chat_history}"),
("user", "{input}"),
MessagesPlaceholder(variable_name="agent_scratchpad"),
]
)
memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
agent = create_tool_calling_agent(llm, tools, prompt)
agent_executor = AgentExecutor(
agent=agent,
tools=tools,
memory=memory,
verbose=True,
handle_parsing_errors=True,
)
print("\n\n\n")
print("Hello, this is langchain slack agent.")
while True:
print("user(q to quit) : ", end="")
user_input = input()
if user_input == "q":
print("Good bye!")
break
response = agent_executor.invoke({"input": user_input})
print("slack agent : ", response["output"])
print()
if __name__ == "__main__":
with PocketLangchain(
tools=[
from_git(
"https://github.com/vessl-ai/hyperawesometools",
"main",
"managed-tools/slack/get-message",
),
from_git(
"https://github.com/vessl-ai/hyperawesometools",
"main",
"managed-tools/slack/post-message",
),
from_git(
"https://github.com/vessl-ai/hyperawesometools",
"main",
"managed-tools/linear/get-issues",
),
from_git(
"https://github.com/vessl-ai/hyperawesometools",
"main",
"managed-tools/google/get-calendar-events",
),
from_git(
"https://github.com/vessl-ai/hyperawesometools",
"main",
"managed-tools/google/get-calendar-list",
),
from_git(
"https://github.com/vessl-ai/hyperawesometools",
"main",
"managed-tools/google/insert-calendar-events",
),
from_git(
"https://github.com/vessl-ai/hyperawesometools",
"main",
"managed-tools/github/pr-list",
),
from_git(
"https://github.com/vessl-ai/hyperawesometools",
"main",
"managed-tools/github/read-pull-request",
),
],
# force_update=True,
) as pocket:
agent(pocket)