Start using AI in Laravel in under 5 minutes

Are you ready to supercharge your Laravel application with AI? In this guide, I'll walk you through installing and configuring the Sidekick package, enabling you to integrate popular AI models like OpenAI, Mistral, Claude, and Cohere. Best of all, you can be up and running in under 5 minutes!

Step 1: Install the Sidekick Package

First, navigate to your Laravel project directory and run the following command to install the Sidekick package:

composer require paparascaldev/sidekick

Step 2: Register the Service Provider

This is no longer needed since v0.2.8

Next, register the Sidekick service provider by adding it to your bootstrap/providers.php file:

\PapaRascalDev\Sidekick\SidekickServiceProvider::class,

Step 3: Configure the .env File

Now it's time to add your API keys to the .env file. You only need to provide keys for the AI providers you plan to use:

SIDEKICK_OPENAI_TOKEN={API_KEY_HERE} # Recommended
SIDEKICK_MISTRAL_TOKEN={API_KEY_HERE} # Optional
SIDEKICK_CLAUDE_TOKEN={API_KEY_HERE} # Optional
SIDEKICK_COHERE_TOKEN={API_KEY_HERE} # Optional

Where Can I Get an API Key?

If you haven't signed up for any AI services yet, you can register and get API keys at the following links:

Step 4: Run Migrations

Run the following migration command to set up the necessary database tables for Sidekick:

php artisan migrate

Step 5: Test the Plugin

After updating your .env file and running the migration, you're ready to start testing Sidekick's AI integration!

Step 6: Explore the Sidekick Playground (Optional)

Want to see Sidekick in action? You can install the Sidekick playground to explore some examples and test the AI features right in your browser. To do this, run:

php artisan sidekick:install

Once installed, you can access the playground by visiting:

/sidekick

Video Tutorial

Here is a video demonstration on the above post. Enjoy!

Now you're all set to bring AI power into your Laravel project!

Laravel PHP AI Development

Please log in or register to leave a comment.

Comments (0)