-
Notifications
You must be signed in to change notification settings - Fork 0
/
langchain_google.py
45 lines (35 loc) · 941 Bytes
/
langchain_google.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
#!/usr/bin/python3
print("content-type: text/html")
print()
import cgi
data=cgi.FieldStorage()
promp=data.getvalue("name")
from langchain.llms import OpenAI
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain
from langchain.agents import load_tools
from langchain.agents import AgentType
from langchain.agents import initialize_agent
import os
myllm=OpenAI(
model="text-davinci-003",
openai_api_key="...",
temperature=0
)
mylw=PromptTemplate(
template="tell me two best{item} in {country}. ",
input_variables=["item","country"]
)
mychain=LLMChain(
llm=myllm,
prompt=mylw
)
os.environ['SERPAPI_API_KEY']="..."
myserptool=load_tools(tool_names=['serpapi'])
mygooglechain=initialize_agent(
llm=myllm,
tools=myserptool,
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
verbose=True
)
mygooglechain.run(promp)