Skip to content

launchdarkly-labs/simple-chatbot

Repository files navigation

AI Chatbot Suite

Three versions of an AI chatbot with increasing levels of functionality, from a simple implementation to full LaunchDarkly integration with metrics tracking.

📁 Available Versions

1. simple_chatbot.py - Basic Version

  • Direct AI provider integration (no LaunchDarkly)
  • Automatic provider selection based on available API keys
  • Simple, straightforward implementation

2. simple_chatbot_with_targeting.py - Targeting Only

  • LaunchDarkly integration for dynamic configuration
  • User context-based provider/model selection
  • Dynamic prompt and parameter updates
  • No metrics tracking overhead

3. simple_chatbot_with_targeting_and_tracking.py - Full Features

  • Complete LaunchDarkly integration
  • Dynamic configuration with targeting
  • Comprehensive metrics tracking:
    • Token usage (input/output/total)
    • Response duration
    • Success/error rates
    • Provider-specific metrics

🚀 Quick Start

Prerequisites

  1. Install dependencies:
pip install -r requirements.txt
  1. Create a .env file with your API keys:
# At least one AI provider key required:
ANTHROPIC_API_KEY=your-anthropic-key
OPENAI_API_KEY=your-openai-key
GEMINI_API_KEY=your-google-gemini-key

# For LaunchDarkly features (targeting & tracking versions):
LD_SDK_KEY=your-launchdarkly-sdk-key
LAUNCHDARKLY_AGENT_CONFIG_KEY=your-config-key 

🎮 Running Each Version

Basic Chatbot (No LaunchDarkly)

python simple_chatbot.py
  • Uses first available API key (Anthropic → OpenAI → Google)
  • No configuration needed beyond API keys

Chatbot with Targeting

python simple_chatbot_with_targeting.py

# Run with persona selection menu
python simple_chatbot_with_targeting.py --personas

# Test without LaunchDarkly (fallback mode)
LD_SDK_KEY="" python simple_chatbot_with_targeting.py
  • Requires LaunchDarkly SDK key for full functionality
  • Falls back to default configuration if LaunchDarkly unavailable
  • Persona mode allows switching between different user contexts

Chatbot with Full Features (Targeting + Tracking)

python simple_chatbot_with_targeting_and_tracking.py

# Run with persona selection menu
python simple_chatbot_with_targeting_and_tracking.py --personas

# Test without LaunchDarkly (fallback mode)
LD_SDK_KEY="" python simple_chatbot_with_targeting_and_tracking.py
  • Full LaunchDarkly integration with metrics
  • Tracks token usage, response times, and success rates
  • Metrics visible in LaunchDarkly dashboard

🎯 Supported AI Providers

All versions support the same three providers:

  • Anthropic Claude (claude-3-haiku-20240307)
  • OpenAI GPT (chatgpt-4o-latest)
  • Google Gemini (gemini-2.5-flash-lite)

💬 Chat Interface

All versions provide the same chat interface:

  • Type your message and press Enter to send
  • Type exit, quit, or q to end the session
  • Conversation history is maintained during the session

📈 LaunchDarkly Configuration

For the targeting and tracking versions, you can configure:

  • Provider selection - Route different users to different AI providers
  • Model selection - Choose specific models per user context
  • System prompts - Customize instructions dynamically
  • Parameters - Adjust temperature, max_tokens, etc.
  • Feature flags - Enable/disable AI features

Example LaunchDarkly AI Config:

{
  "provider": {
    "name": "anthropic"
  },
  "model": {
    "name": "claude-3-haiku-20240307",
    "parameters": {
      "temperature": 0.7,
      "max_tokens": 500
    }
  },
  "messages": [
    {
      "role": "system",
      "content": "You are a helpful AI assistant."
    }
  ]
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages