Skip to content

Latest commit

 

History

History
96 lines (78 loc) · 3.43 KB

File metadata and controls

96 lines (78 loc) · 3.43 KB

AI Query Examples Enhancement - Summary of Changes

Overview

Enhanced the AIAlertInterpreter class with comprehensive query examples and improved code quality.

Changes Made

1. Enhanced Query Examples (backend/app/core/ai.py)

  • Added 27 comprehensive query examples covering all supported intents
  • Examples demonstrate proper intent classification for various user queries
  • Added examples for edge cases and error handling

New Examples Include:

  • ✅ Price checks (HDFC, TCS, INFY)
  • ✅ Stock analysis requests (charts, technical analysis, volume trends)
  • ✅ Portfolio operations (add, sell, view)
  • ✅ Alert creation
  • ✅ Market information queries (concepts, explanations)
  • ✅ Fundamentals checking
  • ✅ Screener redirection
  • ✅ Investment advice rejection
  • ✅ Non-stock query rejection
  • ✅ Alias conversion (RIL → RELIANCE)
  • ✅ Context handling
  • ✅ Future prediction rejection
  • ✅ Stock recommendation rejection

2. Code Quality Improvements

  • ✅ Improved PEP-8 compliance by wrapping long lines (>120 characters)
  • ✅ Enhanced readability of intent listings
  • ✅ Better formatting of critical rules

3. Comprehensive Test Suite (backend/tests/test_ai_query_examples.py)

  • ✅ Created 27 unit tests, one for each query example
  • ✅ All tests use mocking to avoid real API calls
  • ✅ Tests validate correct intent classification
  • ✅ Tests verify proper JSON response structure
  • ✅ All 27 tests pass successfully

Files Modified

  1. backend/app/core/ai.py - Enhanced with query examples and formatting improvements
  2. backend/tests/test_ai_query_examples.py - New comprehensive test file (27 tests)

Test Results

============================== 27 passed in 0.14s ==============================

All new tests pass successfully, and existing AI-related tests continue to pass.

Benefits

  1. Improved AI Accuracy: Clear examples help the LLM classify intents more accurately
  2. Better Documentation: Query examples serve as living documentation
  3. Enhanced Test Coverage: Comprehensive tests ensure reliability
  4. Better Code Quality: Improved PEP-8 compliance and readability
  5. Edge Case Handling: Examples cover aliases, context, and rejections

Usage

The enhanced AI interpreter will now more accurately classify user queries like:

  • "What is HDFC price?" → CHECK_PRICE
  • "Analyze TCS" → ANALYZE_STOCK
  • "Should I buy Reliance?" → REJECTED
  • "What is RIL price?" → CHECK_PRICE (with alias conversion to RELIANCE)

Next Steps

  • Consider integrating these tests into CI/CD pipeline
  • Monitor AI accuracy in production with the new examples
  • Add more examples as new use cases emerge

Security Updates - Summary of Changes (February 4, 2026)

Overview

Strengthened secret handling and commit-time checks to reduce the risk of credential leaks.

Changes Made

  • Removed hardcoded DB credential defaults from backend scripts; scripts now fail fast if DB env vars are missing.
  • Added pre-commit secret scanning configuration.
  • Documented pre-commit usage and .env handling in README.md, SECURITY.md, and AGENTS.md.

How to Verify

pre-commit run --all-files

Files Modified

  • backend/app/scripts/fetch_daily_data.py
  • backend/app/scripts/fetch_stock_data.py
  • backend/app/scripts/fetch_nse_stocks.py
  • backend/app/scripts/setup_stock_tables.py
  • backend/app/scripts/populate_stocks.py
  • .pre-commit-config.yaml
  • README.md
  • SECURITY.md
  • AGENTS.md