This notebook goes over how to use the Google Finance Tool to get information from the Google Finance page.To get an SerpApi key key, sign up at: https://serpapi.com/users/sign_up.To use the tool with Langchain install following packages
Note: you may need to restart the kernel to use updated packages.
and use the create_react_agent functionality to initialize a ReAct agent. You will also need to set up your OPEN_API_KEY (visit https://platform.openai.com) in order to access OpenAI’s chat models.
from langchain.chat_models import init_chat_modelllm = init_chat_model("gpt-4o-mini", model_provider="openai")
Copy
Ask AI
from langchain_community.agent_toolkits.load_tools import load_toolstools = load_tools(["google-scholar", "google-finance"], llm=llm)
Copy
Ask AI
from langgraph.prebuilt import create_react_agentagent = create_react_agent(llm, tools)events = agent.stream( {"messages": [("user", "What is Google's stock?")]}, stream_mode="values",)for event in events: event["messages"][-1].pretty_print()
Copy
Ask AI
================================ Human Message =================================What is Google's stock?================================== Ai Message ==================================Tool Calls: google_finance (call_8m0txCtxNuQaAv9UlomPhSA1) Call ID: call_8m0txCtxNuQaAv9UlomPhSA1 Args: query: Google================================= Tool Message =================================Name: google_financeQuery: Googlestock: GOOGL:NASDAQprice: $159.96percentage: 0.94movement: Upus: price = 42210.57, movement = Downeurope: price = 23638.56, movement = Upasia: price = 38183.26, movement = Up================================== Ai Message ==================================Google's stock, listed as GOOGL on NASDAQ, is currently priced at $159.96, with a movement up by 0.94%.
Assistant
Responses are generated using AI and may contain mistakes.