Download the PHP package evolvoltd/laravel-openai-assistants without Composer
On this page you can find all versions of the php package evolvoltd/laravel-openai-assistants. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download evolvoltd/laravel-openai-assistants
More information about evolvoltd/laravel-openai-assistants
Files in evolvoltd/laravel-openai-assistants
Package laravel-openai-assistants
Short Description Method to send messages to an OpenAI Assistant of your choice.
License MIT
Informations about the package laravel-openai-assistants
laravel-openai-assistants
Get Started
First, install by using Composer
Then, make sure to set your .env variables
Note that this package uses queues. Queues need to be configured. The queue being used is 'default' by default. You can set the .env variable below to change this.
You can also set a maximum retry count. The default is 60. You can set the .env variable below to change this
Usage
The key part of this package is the ask function
This function will add a message to an assistant's thread, run the thread and dispatch a job to check on the run's status and retrieve the response when the run is completed.
The first parameter 'message' requires you to pass in the message you want to send to the assistant.
The second parameter 'parser' requires you to create and pass in a class that implements interface ParseGPTResponse
ParseGPTResponse Interface
This interface has three functions:
public function parseResponse();
This function allows you to set up the functionality to parse the response from the assistant according to your requirements. Example below:
public function executeFunctions());
This function allows you to set up your assistant's predefined functions for when it requests data from them. An example is displayed below. Note that the $name is entirely based on the functions you assigned to your assistant. The output is hardcoded in this example but could return any data of your choice.
public function statusUpdate();
This function allows you to set up your own way to store the status and data of the run for future reference. An example is displayed below. Note that in this example, GptQuery is a model of a database table. You will need to create your own database table and model to use this function.
Multiple Queues/Assistants
You can also pass in optional variables when using the ask function to specify the queue and assistant for the specific message sent. This allows you to use multiple queues and/or assistants in your application. An example is below:
Here, $assistantId allows you to pass in the assistant you want to use in this request, and $queueName allows you to pass in the name of the queue you want to use in this request. The ask function checks if these variables are provided. It uses the provided variable if available, otherwise it uses the value from the config.