Download the PHP package capevace/laravel-gpt without Composer
On this page you can find all versions of the php package capevace/laravel-gpt. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download capevace/laravel-gpt
More information about capevace/laravel-gpt
Files in capevace/laravel-gpt
Package laravel-gpt
Short Description A Laravel package for interacting with OpenAI's GPT-3.
License MIT
Homepage https://github.com/capevace/laravel-gpt
Informations about the package laravel-gpt
Installation
You can install the package via composer:
Configuration
You will need an API key for the OpenAI GPT-3 API. Once you have obtained an API key, you can configure it in your .env file by adding the following line:
You could also publish the config file directly, but this really probably isn't necessary:
Usage
The Capevace\GPT\GPTService
class provides methods for making requests to the GPT-3 API. You can inject it into controllers or use the Facade to access the container.
GPT::generate(\<prompt>, [...options])
The generate
method returns a GPTResponse
object that contains the response from the GPT-3 API. If no text is returned (empty string), the method will throw an error.
generate
takes the following arguments:
prompt
(required): the prompt to send to the GPT-3 APImodel
: the GPT-3 model to use (defaults to text-davinci-003)temperature
: a value between 0 and 1 that determines how "creative" the response will be (defaults to 0.83)maxTokens
: the maximum number of tokens (i.e., words) to return in the response (defaults to 1200)stop
: a string that, when encountered in the response, will cause the response to end (defaults to null)frequencyPenalty
: a value between 0 and 1 that determines how much the model will penalize frequent words (defaults to 0.11)presencePenalty
: a value between 0 and 1 that determines how much the model will penalize words that don't appear in the prompt (defaults to 0.03)
Example
Handling responses
The generate
method returns a GPTResponse
object that contains the response from the GPT-3 API.
It has two methods:
$response->first()
(string): returns the first text suggested by GPT-3$response->all()
(array): returns a list of all the text choices suggested by GPT-3
Example
Error handling
If an error occurs while making a request to the GPT-3 API, the generate()
method will throw a Capevace\GPT\Support\GPTException
exception.
laravel-gpt
will also throw an error, if a response does not contain any text (empty string).
Example
Changelog
Please see CHANGELOG for more information on what has changed recently.
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-gpt with dependencies
illuminate/contracts Version ^9.0
orhanerday/open-ai Version ^3.2
spatie/laravel-package-tools Version ^1.13.0