huangjia2019 / ai-agents

异步图书 大模型应用开发 动手做AI Agent
https://item.jd.com/14600442.html
159 stars 34 forks source link

SerrpAIPWrapper function #1

Open digitalmary opened 3 weeks ago

digitalmary commented 3 weeks ago

Hi, thanks a lot for the book. I tryed [02-demo-agent], the SerrpAIPWrapper function seems to be no longer usable through PythonREPL. Is that so? How should I deal with it?

huangjia2019 commented 3 weeks ago

I am still ok to run the code using that code.

# 导入 SerpAPIWrapper 即工具包
from langchain_community.utilities import SerpAPIWrapper
from langchain.agents.tools import Tool
# 实例化 SerpAPIWrapper
search = SerpAPIWrapper()
# 准备工具列表
tools = [
 Tool(
 name="Search",
 func=search.run,
 description=" 当大模型没有相关知识时,用于搜索知识 "
 ),
]

however, you can also try this:

# 设置工具
from langchain.agents import load_tools
tools = load_tools(["serpapi"])

Let me know if this helps, thanks.