Skip to main content
Glama
Shak2000

Yahoo Finance MCP for LLaMA 3.2 3B

by Shak2000

雅虎财经模型上下文协议 (MCP),适用于 LLaMA 3.2 3B

此代码库包含一个模型上下文协议 (MCP) 实现,它将雅虎财经 API 与 LLaMA 3.2 3B 集成。MCP 允许模型检索实时财务数据、股票信息和市场新闻,同时保留 LLaMA 的所有常规功能。

特征

  • 在 LLaMA 3.2 3B 中直接获取实时股票价格

  • 检索详细的公司信息(部门、行业、市值等)

  • 获取具有可自定义时间段和间隔的历史股票数据

  • 获取最新市场新闻头条

  • 无缝增强 LLaMA 的功能,且不干扰非财务查询

Related MCP server: Yahoo Finance MCP Server

要求

  • Python 3.8+

  • Ollama - 用于本地运行 LLaMA 3.2 3B

  • LLaMA 3.2 3B 型号拉入 Ollama

  • Python 包:

    • 奥拉马

    • yfinance

    • 请求

    • 熊猫

安装

  1. 从https://ollama.ai/安装 Ollama

  2. 使用 Ollama 拉取 LLaMA 3.2 3B 模型:

    ollama pull llama3.2:3b
  3. 克隆此存储库:

    git clone <repository-url>
    cd mcp_yahoo_finance
  4. 安装所需的 Python 依赖项:

    pip install -r requirements.txt

用法

使用 Ollama 集成运行 MCP

要通过 Ollama 将 Yahoo Finance MCP 与 LLaMA 3.2 3B 结合使用:

python mcp_ollama_integration.py

这将启动一个交互式会话,您可以在其中:

  • 提出财务问题,这些问题将通过雅虎财经数据得到丰富

  • 询问任何其他问题,这些问题通常会由 LLaMA 3.2 3B 处理

示例查询

财务查询(通过雅虎财经数据增强)

  • “苹果股票的当前价格是多少?”

  • “跟我讲讲特斯拉这家公司吧”

  • “微软的股票在过去一个月表现如何?”

  • “最新的市场新闻标题是什么?”

  • “亚马逊的 52 周最高价是多少?”

  • “Nvidia 从事哪个行业?”

  • “标准普尔 500 指数今年的表现如何?”

非财务查询(通常由 LLaMA 处理)

  • “法国的首都是哪里?”

  • “解释量子计算”

  • “写一首关于秋天的诗”

  • “勾股定理是什么?”

使用不同的LLaMA模型

您可以使用--model参数指定不同的模型:

python mcp_ollama_integration.py --model llama3.2:8b

工作原理

  1. MCP 分析每个用户查询以确定其是否与财务相关

  2. 对于财务查询,它:

    • 确定要调用的相关财务功能(价格、信息、历史、新闻)

    • 通过 MCP 调用 Yahoo Finance API

    • 格式化实时数据并将其作为上下文提供给 LLaMA 3.2 3B

    • LLaMA 3.2 3B 结合财务数据提供自然的响应

  3. 对于非财务查询,它会直接将其传递给 LLaMA 3.2 3B,无需修改

这种方法无缝增强了 LLaMA 的实时财务数据功能,同时保留了其所有原有的功能。

高级用法

直接 API 函数

如果您想在代码中直接使用 Yahoo Finance MCP 函数:

from yahoo_finance_mcp import YahooFinanceMCP

# Initialize the MCP
mcp = YahooFinanceMCP()

# Get stock price
price_data = mcp.execute_function("get_stock_price", {"symbol": "AAPL"})

# Get company information
company_data = mcp.execute_function("get_stock_info", {"symbol": "TSLA"})

# Get historical data
history_data = mcp.execute_function("get_stock_history", {"symbol": "MSFT", "period": "1mo"})

# Get market news
news_data = mcp.execute_function("get_market_news", {"limit": 5})

故障排除

  • “连接 Ollama 时出错” :请确保 Ollama 已安装并正在运行

  • 未找到公司:请尝试使用官方股票代码代替公司名称

  • 未找到 LLaMA 3.2 3B 模型:运行ollama pull llama3.2:3b下载模型

致谢

该项目使用yfinance库检索雅虎财经数据,并使用Ollama在本地运行 LLaMA 3.2 3B。

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    D
    maintenance
    Provides real-time financial data from Yahoo Finance to Large Language Models through the Model Context Protocol, enabling AI models to access stock prices, historical data, and company information.
    1
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    Provides real-time stock quotes, historical price data, financial news, and multi-stock comparisons using Yahoo Finance data. Enables users to access comprehensive financial market information through natural language queries.
    157 npm
    MIT
  • A
    license
    Not graded
    quality
    Not graded
    maintenance
    Provides real-time financial data from Yahoo Finance, enabling stock price lookups, historical data analysis, company information retrieval, and multi-stock comparisons through natural language queries.
    -
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables LLMs to retrieve stock market data and financial information from Yahoo Finance using the yfinance Python library. Supports querying stock prices, historical data, and other financial metrics through natural language.
    MIT