PHP Classes

PHP ChatGPT API Example Application to Learn How to Implement Chat System using Artificial Intelligence to Quickly Answer Your Site User's Questions - OpenAI Chat API PHP Completions Class package blog

Recommend this page to a friend!
  All package blogs All package blogs   OpenAI Chat API PHP Completions Class OpenAI Chat API PHP Completions Class   Blog OpenAI Chat API PHP Completions Class package blog   RSS 1.0 feed RSS 2.0 feed   Blog PHP ChatGPT API Examp...  
  Post a comment Post a comment   See comments See comments (6)   Trackbacks (0)  

Author:

Updated on: 2023-05-12

Posted on: 2023-05-11

Package: OpenAI Chat API PHP Completions Class

ChatGPT became a very famous artificial intelligence application due to its ability to provide a chat application that allows the users to interact with a robot in a way that feels like the ChatGPT users are talking with other humans.

This package provides a PHP application that works similarly to ChatGPT.

It uses the GPT API to benefit from the same artificial intelligence engine of OpenAI that ChatGPT uses.




Loaded Article

About the OpenAI Chat API PHP Completions Class Package

The package OpenAI Chat API PHP Completions Class is one of the few PHP packages that was considered notable recently because it does something that is worth paying attention.

The basic purpose is: Chat application like ChatGPT using OpenAI GPT API

Here follows in more detail what it does:

This package implements a chat application like ChatGPT using OpenAI GPT API.

It provides a class that can access the OpenAI GPT API to send requests to implement chat interactions.

The package also provides a Web application to let users chat with GPT artificial intelligence engine, similar to what is possible with the ChatGPT application.


Instructions for use:

1. Create an OpenAI account at https://beta.openai.com/

2. Create an API key at https://beta.openai.com/account/api-keys

3. Make a variable to store your API key in, let's say $apiKey

4. Create a new PHPOpenAIChat object, passing in your API key, like this:
$openAIChat = new PHPOpenAIChat($apiKey);

5. Send a message to the model and get a response like this:
$messages = []; # create a conversation
// set agent
$messages = $openAIChat->set_agent($messages, "You are an assistant cat that can speak english and is named Henry.");
// add prompt to messages conversation
$messages = $openAIChat->add_prompt_to_messages($messages, "What is your name?");
$response = $openAIChat->sendMessage($messages);
print_r($response); # show entire returned array
// print text
echo "<br />response text: " . $openAIChat->get_response_text($response) ."<br />";

6. You can also set the model to use (gpt-3.5-turbo or gpt-4), the max_tokens to use, the temperature to use, the frequency_penalty to use, and the presence_penalty to use.

7. You can also estimate the token count of the messages to send to the model, and subtracts from max_tokens.

8. You should be able to get the text from the response by using $response['choices'][0]['message']['content']

9. You can append the text from the response to the messages to send to the model

10. You can also use the add_prompt_to_messages() function to add a prompt to the current conversation

11. Then you can repeat the cycle again by sending the messages to the model and getting another response.

Conclusion

The OpenAI Chat API PHP Completions Class can be downloaded from download page or be installed using the PHP Composer tool following instructions in the Composer install instructions page.

This package was considered notable for implementing its benefits in a way that is worth noticing.

Notable PHP packages can be often considered innovative. If this package is also innovative, it can be nominated to the PHP Innovation Award and the author may win prizes and recognition for sharing innovative packages.

If you also developed your own notable or innovative packages consider sharing them, so you can also earn more visibility for your package as well nice prizes.

One nice prize that many PHP developers want and you may like is the PHP elePHPant mascot plush.




You need to be a registered user or login to post a comment

Login Immediately with your account on:

FacebookGmail
HotmailStackOverflow
GitHubYahoo


Comments:

1. Small problem here.. - Aron (2023-05-12 20:05)
You exceeded your current quota, please check your plan and bill... - 5 replies
Read the whole comment and replies




  Post a comment Post a comment   See comments See comments (6)   Trackbacks (0)  
  All package blogs All package blogs   OpenAI Chat API PHP Completions Class OpenAI Chat API PHP Completions Class   Blog OpenAI Chat API PHP Completions Class package blog   RSS 1.0 feed RSS 2.0 feed   Blog PHP ChatGPT API Examp...