Skip to main content

Polygon IO 工具包

本笔记本展示了如何使用代理与 Polygon IO 工具包进行交互。该工具包提供对 Polygon 股票市场数据 API 的访问。

示例用法

设置

%pip install --upgrade --quiet langchain-community > /dev/null

在此处获取您的 Polygon IO API 密钥 here,然后在下面设置它。 请注意,此示例中使用的工具需要“股票高级”订阅

import getpass
import os

os.environ["POLYGON_API_KEY"] = getpass.getpass()
········

设置 LangSmith 以获得最佳的可观察性也是有帮助的(但不是必需的)

# os.environ["LANGCHAIN_TRACING_V2"] = "true"
# os.environ["LANGCHAIN_API_KEY"] = getpass.getpass()

初始化代理

from langchain import hub
from langchain.agents import AgentExecutor, create_openai_functions_agent
from langchain_community.agent_toolkits.polygon.toolkit import PolygonToolkit
from langchain_community.utilities.polygon import PolygonAPIWrapper
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(temperature=0)

instructions = """You are an assistant."""
base_prompt = hub.pull("langchain-ai/openai-functions-template")
prompt = base_prompt.partial(instructions=instructions)
polygon = PolygonAPIWrapper()
toolkit = PolygonToolkit.from_polygon_api_wrapper(polygon)
agent = create_openai_functions_agent(llm, toolkit.get_tools(), prompt)
agent_executor = AgentExecutor(
agent=agent,
tools=toolkit.get_tools(),
verbose=True,
)

获取股票的最新报价

agent_executor.invoke({"input": "What is the latest stock price for AAPL?"})

此页面是否有帮助?


您还可以留下详细的反馈 在 GitHub 上