Skip to main content
Open In ColabOpen on GitHub

Google Finance

本笔记本介绍如何使用Google Finance工具从Google Finance页面获取信息

要获取SerpApi密钥,请在此注册:https://serpapi.com/users/sign_up

然后使用以下命令安装 google-search-results:

pip 安装 google-search-results

然后将环境变量 SERPAPI_API_KEY 设置为你的 SerpApi 密钥

或者将密钥作为参数传递给包装器 serp_api_key="your secret key"

使用工具

%pip install --upgrade --quiet  google-search-results langchain-community
import os

from langchain_community.tools.google_finance import GoogleFinanceQueryRun
from langchain_community.utilities.google_finance import GoogleFinanceAPIWrapper

os.environ["SERPAPI_API_KEY"] = ""
tool = GoogleFinanceQueryRun(api_wrapper=GoogleFinanceAPIWrapper())
tool.run("Google")

与Langchain一起使用

import os

from langchain.agents import AgentType, initialize_agent, load_tools
from langchain_openai import OpenAI

os.environ["OPENAI_API_KEY"] = ""
os.environ["SERP_API_KEY"] = ""
llm = OpenAI()
tools = load_tools(["google-scholar", "google-finance"], llm=llm)
agent = initialize_agent(
tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True
)
agent.run("what is google's stock")

这个页面有帮助吗?