Download the PHP package devdojo/ai without Composer
On this page you can find all versions of the php package devdojo/ai. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package ai
Short Description This is a package that simplifies communicating with AI services using PrismPHP
License MIT
Homepage https://github.com/devdojo/ai
Informations about the package ai
AI with PrismPHP
This package provides you with a global ai() method to easily get responses from your favorite AI provider. Here are a few examples:
Or capture the streamed response in a callback
Video Example
https://github.com/user-attachments/assets/69c90f9c-b003-4077-900b-c7f3d264f537
Installation
You can install the package via composer:
Usage
After you've installed the package, you'll want to add your AI Provider API Key. Out of the box DevDojo AI uses OpenAI, so you'll want to grab your OpenAI key and add it to your .env
After that, you are ready to use the ai method anywher in your app:
You can also capture the streamed response, by passing a callback as the second argument.
This makes it super easy to return streamed responses in your Livewire components. In fact, this package offers two Single-File Volt component examples.
Examples
You can publish a few examples by running:
This will publish two component examples to your project.
- basic-example.blade.php (a basic example of sending a message and getting a streamed response back)
- chat-example.blade.php (a chat example to show you how to pass an array of messages to create a conversation)
This will allow you to include those example components anywhere in your application.
You can easily test this out by utilizing the Livewire Starter Kit, Installing this package, Adding your API Key to .env, and then pasting the following into the welcome.blade.php file:
Make sure your asset running is watching via composer dev or npm run dev.
Now you will be able to see the basic and chat example fully functioning and communicating with your favorite AI service.
https://github.com/user-attachments/assets/69c90f9c-b003-4077-900b-c7f3d264f537
Configuration
If you would like to change the AI provider and the AI model, you can specify the following .env variables:
You can also publish the AI config file that will live at config/ai.php:
PrismPHP
This package doesn't really do much else besides providing you with an easy to use global ai() method. Most of the magic comes from PrismPHP, you may wish to abstract this into your own global ai() method. All providers that are available via Prism are also supported in this package.
Testing
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Tony Lea
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of ai with dependencies
illuminate/support Version ^10.0|^11.0|^12.0
prism-php/prism Version ^0.85