LaravelPackages.net
Acme Inc.
Toggle sidebar
sabir/chatgpt

A Laravel package for interacting with ChatGPT APIs.

65
0
1.0.0
About sabir/chatgpt

sabir/chatgpt is a Laravel package for a laravel package for interacting with chatgpt apis.. It currently has 0 GitHub stars and 65 downloads on Packagist (latest version 1.0.0). Install it with composer require sabir/chatgpt. Discover more Laravel packages by sabir or browse all Laravel packages to compare alternatives.

Last updated

To integrate the ChatGPT package with PHP and Laravel, please follow these steps:

Install the package: Install the package via Composer by running the following command in your project directory:

composer require sabir/chatgpt:dev-master Publish configuration file: Run the following command to publish the package's configuration file:

php artisan vendor:publish --tag=chatgpt-config --ansi --force This command will create a configuration file named chatgpt.php in your Laravel project's config directory.

Set API key and model: Open the .env file in your project's root folder and set the values for the following environment variables:

CHAT_API=YOUR_CHAT_API_KEY CHAT_MODEL=YOUR_CHAT_MODEL_ID Replace YOUR_CHAT_API_KEY with your OpenAI Chat API key and YOUR_CHAT_MODEL_ID with the model ID you want to use (e.g., "davinci", "curie", "babbage", or "ada").

Create an instance and call the chat method: In your Laravel code, you can now create an instance of the ChatGPT class and call the chat method to interact with the ChatGPT model. Here's an example:

use Sabir\ChatGPT\Facades\ChatGPT;

// ...

$s = new ChatGPT(); $response = $s->chat('hi, how are you?'); dd($response);

The chat method accepts three parameters:

message (required): The message or prompt to send to the ChatGPT model. type (optional): The API type to use for the chat. If left blank or set to "devinci", "curie", "babbage", or "ada", it will use the OpenAI models. You can extend this functionality to include other types if needed. options (optional): An array of additional options for the API request, such as temperature, max_tokens, top_p, etc. The chat method will return the response from the ChatGPT model.

Note: The provided code snippet is a simplified example. You may need to adjust it based on your project structure and requirements.

Ensure that you have properly configured the API key, model ID, and other settings according to your OpenAI account and desired behavior.

Comments