-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreact.py
More file actions
28 lines (19 loc) · 688 Bytes
/
react.py
File metadata and controls
28 lines (19 loc) · 688 Bytes
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
from dotenv import load_dotenv
from langchain import hub
from langchain.agents import create_react_agent
from langchain_core.prompts import PromptTemplate
from langchain_core.tools import tool
from langchain_openai.chat_models import ChatOpenAI
from langchain_tavily import TavilySearch
load_dotenv()
react_prompt: PromptTemplate = hub.pull("hwchase17/react")
@tool
def triple(num: float) -> float:
"""
:param num: a number to triple
:return: the number tripled -> multiplied by 3
"""
return 3 * float(num)
tools = [TavilySearch(max_results=1), triple]
llm = ChatOpenAI(model="gpt-4o-mini")
react_agent_runnable = create_react_agent(llm, tools, react_prompt)