Skip to content

Latest commit

 

History

History
139 lines (102 loc) · 3.66 KB

File metadata and controls

139 lines (102 loc) · 3.66 KB

AI/LLM Integration Setup

Overview

LiabilityIQ now includes AI-powered document summarization and analysis using OpenAI's GPT models. The system can work with or without AI - if AI is disabled or unavailable, it falls back to pattern matching.

Features Enabled by AI

  1. Document Summarization: AI generates concise, contextual summaries of each document
  2. Entity Extraction: AI extracts structured entities (names, dates, locations, etc.)
  3. Risk Analysis: AI identifies potential risks and issues
  4. Recommendations: AI generates actionable recommendations

Setup

Option 1: Using OpenAI API (Recommended)

  1. Get an API Key:

  2. Set Environment Variable:

    # Windows PowerShell
    $env:OPENAI_API_KEY="your-api-key-here"
    
    # Windows CMD
    set OPENAI_API_KEY=your-api-key-here
    
    # Linux/Mac
    export OPENAI_API_KEY="your-api-key-here"
  3. Enable AI in Config: Edit config/config.yaml:

    ai:
      enabled: true
      model: "gpt-4o-mini"  # or "gpt-4", "gpt-3.5-turbo"
  4. Install Dependencies:

    pip install openai>=1.0.0

Option 2: Disable AI (Use Pattern Matching)

Edit config/config.yaml:

ai:
  enabled: false

The system will automatically use pattern matching fallbacks.

Visual Indicators

When AI is enabled, you'll see:

  1. Processing Page: Shows animated AI processing steps

    • 🤖 AI icon with pulsing animation
    • Step-by-step progress indicators
    • AI-specific step highlighting (purple border)
  2. Dossier Header: Shows "🤖 AI-Powered" badge

  3. Console Output: Shows "✓ AI/LLM service initialized" on startup

Configuration Options

In config/config.yaml:

ai:
  enabled: true                    # Enable/disable AI
  provider: "openai"               # Provider (currently only OpenAI)
  model: "gpt-4o-mini"             # Model to use
  api_key_env: "OPENAI_API_KEY"    # Environment variable name
  use_ai_for_summarization: true   # Use AI for document summaries
  use_ai_for_entity_extraction: true  # Use AI for entity extraction
  use_ai_for_risk_analysis: true   # Use AI for risk analysis
  use_ai_for_recommendations: true # Use AI for recommendations

Cost Considerations

  • gpt-4o-mini: ~$0.15 per 1M input tokens, ~$0.60 per 1M output tokens
  • gpt-4: ~$30 per 1M input tokens, ~$60 per 1M output tokens

For MVP/demo purposes, gpt-4o-mini is recommended as it's cost-effective and provides good quality.

Fallback Behavior

If AI is unavailable or fails:

  • System automatically falls back to pattern matching
  • No errors are thrown
  • Processing continues normally
  • Warning messages are logged

Testing

  1. With AI Enabled:

    export OPENAI_API_KEY="your-key"
    python web_app.py

    Process a claim and watch the AI processing indicators.

  2. Without AI:

    # Edit config.yaml: ai.enabled = false
    python web_app.py

    System uses pattern matching (faster, no API costs).

Troubleshooting

"OPENAI_API_KEY not set"

  • Set the environment variable (see Setup above)
  • Or disable AI in config

"AI summarization failed"

  • Check your API key is valid
  • Check you have API credits
  • System will automatically fall back to pattern matching

Slow Processing

  • AI processing takes 5-15 seconds per document
  • Consider using gpt-4o-mini instead of gpt-4
  • Or disable AI for faster processing

Future Enhancements

  • Support for local models (Ollama, etc.)
  • Caching of AI responses
  • Batch processing optimization
  • Custom prompt templates
  • Multi-model support