freddyaboulton HF staff commited on
Commit
c6fb257
1 Parent(s): 2833dc4

Create langchain_demo.py

Browse files
Files changed (1) hide show
  1. langchain_demo.py +22 -0
langchain_demo.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain import hub
2
+ from langchain.agents import AgentExecutor, create_openai_tools_agent, load_tools
3
+
4
+ from langchain_openai import ChatOpenAI
5
+
6
+ from dotenv import load_dotenv
7
+
8
+ load_dotenv()
9
+
10
+ model = ChatOpenAI(temperature=0, streaming=True)
11
+
12
+ tools = load_tools(["serpapi"])
13
+
14
+ # Get the prompt to use - you can modify this!
15
+ prompt = hub.pull("hwchase17/openai-tools-agent")
16
+ # print(prompt.messages) -- to see the prompt
17
+ agent = create_openai_tools_agent(
18
+ model.with_config({"tags": ["agent_llm"]}), tools, prompt
19
+ )
20
+ agent_executor = AgentExecutor(agent=agent, tools=tools).with_config(
21
+ {"run_name": "Agent"}
22
+ )