Skip to content

add example using mistral with langchain #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
98 changes: 98 additions & 0 deletions examples/langchain/mistral-example/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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)
16 changes: 16 additions & 0 deletions examples/langchain/mistral-example/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[project]
name = "mistral-example"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"hyperpocket",
"hyperpocket-langchain",
"langchain>=0.3.15",
"langchain-mistralai>=0.2.4",
]

[tool.uv.sources]
hyperpocket-langchain = { path = "../../../libs/extensions/langchain", editable = true }
hyperpocket = { path = "../../../libs/hyperpocket", editable = true }
Loading
Loading