股票分析工具

一个使用Google的Gemini API、Model Context Protocol (MCP)和向量数据库分析Google表格中股票数据的Python项目。

  • by SG87
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 SG87/gemini_stock_analysis

使用说明

Gemini股票分析

一个Python项目,使用Google的Gemini API、模型上下文协议(MCP)和向量数据库来分析Google Sheets的股票数据。

特性

  • Google表格集成:从谷歌表格读取股票数据
  • API双子星:使用谷歌的Gemini AI进行分析和洞察
  • MCP集成:为结构化AI交互实现模型上下文协议
  • 向量数据库:使用ChromaDB存储和检索嵌入以进行语义搜索

先决条件

  • Python 3.12 (必填-本项目专门使用Python 3.12)
    • 检查您的版本: python3.12 --version
    • 看 设置.md 有关安装说明
  • 诗歌(用于依赖管理)
  • Google云证书(适用于Google Sheets API)
  • Gemini API密钥

安装

  1. 如果您还没有安装Poetry:
curl -sSL https://install.python-poetry.org | python3 -
  1. 配置Poetry以使用Python 3.12:
poetry env use python3.12
# Verify: poetry run python --version
  1. 安装依赖项:
poetry install
  1. 设置环境变量:

请查看SETUP.md,以配置以下变量进行输入 .env

配置

创建一个 .env 包含以下变量的文件:

GEMINI_API_KEY=your_gemini_api_key_here
GOOGLE_SHEETS_ID=your_google_sheet_id_here
GOOGLE_CREDENTIALS_PATH=path/to/credentials.json
CHROMA_DB_PATH=./chroma_db

用法

在运行之前,请验证是否正在使用Python 3.12:

poetry run python check_python.py

然后运行应用程序:

poetry run gemini-stock-analysis

或者激活虚拟环境:

poetry shell
python -m gemini_stock_analysis.main

项目结构

src/
├── __init__.py
├── main.py                 # Main application entry point
├── config.py               # Configuration management
├── sheets/
│   ├── __init__.py
│   └── reader.py          # Google Sheets integration
├── gemini/
│   ├── __init__.py
│   └── client.py          # Gemini API client
├── mcp/
│   ├── __init__.py
│   └── handler.py         # MCP protocol handler
└── vector_db/
    ├── __init__.py
    └── store.py           # Vector database operations

发展

运行测试:

poetry run pytest

格式代码:

poetry run black .
poetry run ruff check --fix .

许可证

麻省理工学院