DEV Community

Cover image for Geeking Out Over Laravel Prism
Lance Munyao
Lance Munyao

Posted on

Geeking Out Over Laravel Prism

So, there I was, casually checking my inbox when a notification from Laravel News popped up. This one featured a new tool called Prism. Naturally, my curiosity levels spiked. I mean, c'mon, a package that merges Laravel with the power of LLMs? Yes, please!

As someone who's dabbled in chatbot development before, I was hooked from the moment I read that article. Of course, I had to dive deeper...

My Pre-Prism Approach to Chatbots:

Picture this:

I used to build UIs that acted as the front-end for a Flask.py backend, serving as a proxy. The flow went something like this:

  1. UI sends JSON to the Flask backend.
  2. Flask forwards it to OpenAI’s GPT models (team OpenAI from the start).
  3. Flask waits for the response from OpenAI.
  4. The UI then gets the response.

Sounds smooth? Not really. The delay was real. 😅 It worked, sure, but slow as hell. I tried optimizing the Flask functions, but no matter what I did, the wait time was still noticeable.


So, What’s Prism?

Prism Excitement

Prism is a Laravel package that makes integrating Large Language Models (LLMs) into your application a breeze. Minimalistic, elegant, and surprisingly powerful. The docs, albeit tailored for Anthropic, Ollama, and OpenAI, are so clear and direct that even a caffeine-deprived coder could follow them.


Why I’m Geeked Out Over Prism:

  1. Speed, glorious speed – No more waiting around like it's 2002.
  2. Clean, readable code – Because who doesn't love the smell of clean code in the morning?
  3. Seamless UI integration – Prism plays nice with views, making it super intuitive to mesh with interfaces.
  4. DIY Prism server setup – Prism lets you expose your custom AI models through a standardized API. It’s like having your own AI botnet... but for good. 😎

With the installation done, this is all you'd need to interact with your LLM! Cool right?

<?php

use Illuminate\Support\Facades\Route;
use EchoLabs\Prism\Prism;
use EchoLabs\Prism\ValueObjects\Messages\UserMessage;
use EchoLabs\Prism\ValueObjects\Messages\AssistantMessage;

Route::get('/test-prism', function () {
    $prism = Prism::text()
    ->using('openai', 'gpt-4o')
    ->withMessages([
        new UserMessage('Hello, who are you?'),
        new AssistantMessage('I am an AI assistant created by Anthropic. How can I help you today?'),
        new UserMessage('Can you tell me about the weather in Paris?'),
    ]);

    echo $prism()->text;   
});
Enter fullscreen mode Exit fullscreen mode

In short, Prism isn't just a new tool—it's a time-saver, a workflow optimizer, and dare I say, a game-changer for Laravel + AI enthusiasts.

Top comments (0)