Google Trends 工具
Google Trends 工具允许你的智能代理使用 SerpApi 提供的 Google Trends API 来获取和分析搜索兴趣数据。 这有助于理解热门话题、地区搜索兴趣以及搜索关键词的历史受欢迎程度。
API 的详细信息请参见这里
SerpApi 会对查询进行缓存,因此首次查询会较慢,而后续相同的查询则会很快。 有时,相关查询可能无法正常工作,但时间趋势查询不会受影响。你可以在这里检查你的查询。
配置
要使用此工具,你需要配置对 SerpApi 提供的 Google Trends API 的访问权限。
从 SerpApi 获取 API 密钥
然后,将 API 密钥设置为 process.env.SERPAPI_API_KEY,或者在构造函数参数中以 apiKey 形式传入。
使用方法
:::提示 请参阅安装集成包的一般说明部分。 :::
- npm
- Yarn
- pnpm
npm install @langchain/openai @langchain/community @langchain/core
yarn add @langchain/openai @langchain/community @langchain/core
pnpm add @langchain/openai @langchain/community @langchain/core
import { SERPGoogleTrendsTool } from "@langchain/community/tools/google_trends";
export async function run() {
const tool = new SERPGoogleTrendsTool();
const res = await tool.invoke("Monster");
console.log(res);
}
API Reference:
- SERPGoogleTrendsTool from
@langchain/community/tools/google_trends
相关内容
Related
- Tool conceptual guide
- Tool how-to guides