forked from agiresearch/OpenAGI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_api_google.py
More file actions
32 lines (24 loc) · 1.1 KB
/
test_api_google.py
File metadata and controls
32 lines (24 loc) · 1.1 KB
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
import os
from langchain.agents import ZeroShotAgent, Tool, AgentExecutor, load_tools
from langchain import OpenAI, SerpAPIWrapper, LLMChain
os.environ["OPENAI_API_KEY"] = "aaa"
os.environ["GOOGLE_CSE_ID"] = "bbb"
os.environ["GOOGLE_API_KEY"] = "ccc"
# ツールの準備
tools = load_tools(["google-search"], llm=OpenAI())
# プロンプトテンプレートの準備
prefix = """次の質問にできる限り答えてください。次のツールにアクセスできます:"""
suffix = """始めましょう! 最終的な答えを出すときは、一人称は"ぼく"、語尾には"なのだ"を使用してください
Question: {input}
{agent_scratchpad}"""
prompt = ZeroShotAgent.create_prompt(
tools,
prefix=prefix,
suffix=suffix,
input_variables=["input", "agent_scratchpad"]
)
# エージェントの準備
llm_chain = LLMChain(llm=OpenAI(temperature=0), prompt=prompt)
agent = ZeroShotAgent(llm_chain=llm_chain, tools=tools)
agent_executor = AgentExecutor.from_agent_and_tools(agent=agent, tools=tools, verbose=True)
agent_executor.run("ぼっち・ざ・ろっくの作者の名前は?")