Skip to main content

Part 2: Creating your first AI Config with two variations

Now, create an AI Config in LaunchDarkly with two variations to demonstrate how to dynamically control AI behavior. For detailed guidance on creating AI Configs, read the AI Configs Quickstart.

Step 2.1: Create an AI Config in Launch

Darkly To create an AI config:
  1. Log in to LaunchDarkly.
  2. Navigate to app.launchdarkly.com/settings/projects.
  3. Click Create project.
  4. Name it simple-chatbot.
Creating a new project in LaunchDarkly

Creating a new project in LaunchDarkly

  1. Click Create project.
  2. Click Project settings, then Environments.
  3. Click the three-dot overflow menu next to β€œProduction.”
  4. Copy the SDK key.
Copying the SDK key from project settings

Copying the SDK key from project settings

  1. Update your .env file with this key:
Then, create a new AI Config:
  1. In the left sidebar, open the AI section and click AI Configs.
  2. Click Create AI Config.
  3. Name it simple-config.
  4. Configure the default variation:
    • Variation Name: friendly
    • Model Provider: Anthropic, or your preferred provider
    • Model: claude-3-haiku-20240307
    • System Prompt:
  • Parameters:
    • temperature: 0.8 (more creative)
    • max_tokens: 500
Setting up the friendly variation in LaunchDarkly

Setting up the friendly variation in LaunchDarkly

  1. Save the AI Config.
Saving the default friendly variation

Saving the default friendly variation

Step 2.2: Add your AI Config key to your .env file

To copy and add your AI Config key:
  1. At the top of your AI Config page, copy the Config Key.
  2. Update your .env file with this key:

Step 2.3: Edit targeting

To edit the AI Config’s targeting:
  1. Click Targeting at the top.
  2. Click Edit.
  3. Select friendly from the dropdown menu.
  4. Click Review and save.
  5. Enter update in the Comment field and Production in the Confirm field.
  6. Click Save changes.
Changing the default variation to friendly

Changing the default variation to friendly

Now create a new file called simple_chatbot_with_targeting.py that adds persona selection capabilities and LaunchDarkly integration.

Step 2.4: Test the friendly variation

Run the chatbot:
Try asking: β€œWhat’s the best way to learn a new programming language?” The response is warm and casual, possibly with an emoji.

Step 2.5: Real-time configuration changes with no redeploy

LaunchDarkly AI Configs let you change AI behavior instantly without redeploying your application. This example changes the response language. Keep your chatbot running from Step 2.4 and follow these steps to update the system prompt to respond in Portuguese:
  1. In LaunchDarkly, navigate to your AI Config.
  2. Go to your simple-config.
  3. Click the Variations tab.
  4. Select the friendly variation.
  5. Change the system prompt to:
  • Click Save changes.
Updating instructions to respond in Portuguese

Updating instructions to respond in Portuguese

Now, test the change without restarting the chatbot. In your still-running chatbot, type a new message:
Notice how the chatbot’s behavior changed instantly without:
  • Restarting the application
  • Redeploying code
  • Changing any configuration files
  • Any downtime
This demonstrates how AI Configs support real-time experimentation and iteration. You can update prompts, adjust behaviors, or switch languages based on user feedback or business needs.