Three versions of an AI chatbot with increasing levels of functionality, from a simple implementation to full LaunchDarkly integration with metrics tracking.
- Direct AI provider integration (no LaunchDarkly)
- Automatic provider selection based on available API keys
- Simple, straightforward implementation
- LaunchDarkly integration for dynamic configuration
- User context-based provider/model selection
- Dynamic prompt and parameter updates
- No metrics tracking overhead
- Complete LaunchDarkly integration
- Dynamic configuration with targeting
- Comprehensive metrics tracking:
- Token usage (input/output/total)
- Response duration
- Success/error rates
- Provider-specific metrics
- Install dependencies:
pip install -r requirements.txt- Create a
.envfile 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 python simple_chatbot.py- Uses first available API key (Anthropic → OpenAI → Google)
- No configuration needed beyond API keys
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
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
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)
All versions provide the same chat interface:
- Type your message and press Enter to send
- Type
exit,quit, orqto end the session - Conversation history is maintained during the session
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."
}
]
}