A modern Streamlit-based financial trading assistant that uses Retrieval Augmented Generation (RAG) with LanceDB to provide intelligent stock analysis and trading insights. The application includes advanced AI models, Galileo observability, and comprehensive financial tooling.
- Intelligent Chat: Natural conversation with financial analysis capabilities
- Enhanced Tool Integration: Automatic tool execution for stock data and trading
- RAG-powered Analysis: Uses LanceDB for semantic search over financial data
- Multi-Model Support: OpenAI GPT models with intelligent capabilities
- Stock Trading Simulation: Purchase/sell functionality with realistic market data
- Galileo Observability: Comprehensive logging and monitoring
- Galileo Protect: AI safety and content filtering
- Modern UI: Clean, intuitive Streamlit interface with real-time chat
.
├── app.py # Main Streamlit application
├── galileo_api_helper.py # Helper functions for Galileo API
├── tools/ # Financial trading tools
│ ├── purchase_stocks.py # Stock purchase simulation
│ ├── sell_stocks.py # Stock sale simulation
│ ├── get_stock_price.py # Real-time stock price lookup
│ ├── get_ticker_symbol.py # Company to ticker symbol lookup
│ └── tool_definitions.py # Tool definitions and configurations
├── data/ # Data management
│ ├── __init__.py # Data package initialization
│ └── vectordb_setup.py # LanceDB setup and population functions
├── chat_lib/ # Shared utilities
│ └── galileo_logger.py # Galileo logging utilities
└── log_hallucination.py # Hallucination logging utility
- Clone the repository
- Install dependencies:
pip install -r requirements.txt- Set up environment variables in
.streamlit/secrets.toml:
# OpenAI Configuration
openai_api_key = "your_openai_api_key"
# Galileo Configuration
galileo_api_key = "your_galileo_api_key"
galileo_project = "your_galileo_project"
galileo_log_stream = "your_galileo_log_stream"
galileo_console_url = "your_galileo_console_url"
galileo_stage_agent_id = "your_stage_agent_id"
# Alpha Vantage API (for stock data)
alpha_vantage_api_key = "your_alpha_vantage_key"- LanceDB will be automatically populated with sample financial data on first run, or you can manually populate it:
cd finance-chat-streamlit
python -c "from data.vectordb_setup import check_and_populate_lancedb; check_and_populate_lancedb()"streamlit run app.pyThe application will be available at http://localhost:8501
The application supports multiple AI models:
- GPT-4o-mini: Fast, cost-effective responses (default)
- GPT-4o: Advanced reasoning and analysis
- GPT-4: High-performance model
- GPT-3.5-turbo: Legacy model support
The application provides:
- Interactive Chat Interface: Real-time financial analysis and trading insights
- Stock Trading Simulation: Purchase/sell stocks with realistic market data
- RAG-Powered Analysis: Context-aware responses using LanceDB
- Galileo Observability: Comprehensive monitoring and debugging
- AI Safety: Galileo Protect integration for content filtering
- Stock Purchase Simulation: Simulates buying stocks with specified ticker, quantity, and price
- Stock Sale Simulation: Simulates selling stocks with specified ticker, quantity, and price
- Ticker Symbol Lookup: Convert company names to stock tickers
- Stock Price Lookup: Get real-time stock prices using AlphaVantage API
- LanceDB Integration: Local vector database for semantic search
- Financial Context: Pre-loaded sample data for major stocks and market information
- Smart Retrieval: Context-aware responses based on relevant financial documents
- Automatic Setup: LanceDB is automatically configured and populated on startup
- Galileo Protect: Content filtering and AI safety measures
- Response Validation: Ensures appropriate and safe AI responses
The application uses Galileo for comprehensive monitoring:
- Chat Interactions: Log all user queries and AI responses
- Tool Usage: Track which trading tools are used and when
- RAG Performance: Monitor document retrieval and relevance
- AI Model Performance: Track response times and quality
- Error Tracking: Comprehensive error logging and debugging
- Session Management: Monitor user sessions and interactions
LanceDB is a local vector database that stores document embeddings for semantic search. It's faster and more cost-effective than cloud-based solutions.
The app automatically:
- Creates the data directory if it doesn't exist
- Sets up LanceDB with the correct schema
- Populates the database with sample financial data
- Handles schema validation and table recreation if needed
The LanceDB table uses a structured schema with:
- id: Unique document identifier
- text: Financial document content
- embedding: 1536-dimensional vector representation
- metadata: Structured fields including:
- company, ticker, sector, type
- index, topic (for market-wide documents)
The system automatically adds sample financial documents:
- Apple (AAPL): Q4 earnings, revenue data
- Microsoft (MSFT): Azure growth, AI initiatives
- Tesla (TSLA): Vehicle deliveries, energy storage
- NVIDIA (NVDA): AI chip market, data center growth
- Amazon (AMZN): Holiday quarter results, AWS performance
- Market Overview: S&P 500 performance, Federal Reserve policy
To add your own financial documents programmatically:
from data.vectordb_setup import add_document_to_lancedb
add_document_to_lancedb(
text="Your financial document text here",
metadata={"company": "Company Name", "type": "earnings"}
)- Galileo Log Stream: Configure logging stream name
- Ambiguous Tool Names: Enable/disable tool name obfuscation for testing
- Galileo Protect: Enable/disable AI safety measures
- Model Selection: Choose from available OpenAI models
- Top K: Number of relevant documents to retrieve (default: 10)
- Automatic Population: Sample data is automatically added on startup
- LanceDB Connection Errors: The app automatically creates the data directory and handles table setup
- Empty RAG Responses: Sample data is automatically populated on startup
- Galileo Connection Issues: Check API keys and project configuration
- Check the Galileo console for detailed logs
- Review the debug configuration in the sidebar
- Ensure all environment variables are properly set
- The app includes comprehensive error logging and automatic fallback mechanisms
- Modular Design: Separate modules for tools, data management, and utilities
- Error Handling: Comprehensive error handling with automatic fallbacks
- Logging: Detailed logging throughout the application
- Type Hints: Full type annotations for better code quality
- Create tool function in the
tools/directory - Add tool definition to
tools/tool_definitions.py - Import and register in
app.py - Update this README with new tool documentation