-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathhello-langchain-5.py
32 lines (24 loc) · 987 Bytes
/
hello-langchain-5.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
from dotenv import load_dotenv
from langchain_openai import ChatOpenAI
from tools.system_time_tool import check_system_time
from react_template import get_react_prompt_template
from langchain_core.output_parsers import StrOutputParser
from langchain.tools.render import render_text_description
# load environment variables
load_dotenv()
# Choose the LLM to use
llm = ChatOpenAI(model="gpt-4")
# set my message
query = "What's the current time in New York (you are in London) just show the time in New York and not the date?"
# set the tools
tools = [check_system_time]
# Get the react prompt template
prompt_template = get_react_prompt_template()
# execute
output_parser = StrOutputParser()
chain = prompt_template | llm | output_parser
# get the tools list
tools_list=render_text_description(list(tools))
tool_names=", ".join([t.name for t in tools])
# print out the prompt
print(prompt_template.format(input=query, tools=tools_list, tool_names=tool_names, agent_scratchpad=""))