Quick and Easy OpenAI GPT-3 Chatbots with PHP

We have been very impressed with the power and ease of use of OpenAI GPT-3 AI chat and how it can easily create a chatbot that provides relevant answers with very little training. For a live example of this click on the chat button on our corporate website: www.eacomm.com.

OpenAI powered GPT-3 Chatbot developed by EACOMM Corporation

Creating a Simple PHP interface for OpenAI GPT engines

To show you just how powerful OpenAI’s new chat is, we asked it how to create an OpenAI chatbot using the PHP programming language. Below is its answer:

To create a chatbot using OpenAI’s API in PHP, you will need to do the following:

  1. Sign up for an OpenAI API key at https://beta.openai.com/signup.
  2. Install the Guzzle HTTP library for PHP, which will be used to make HTTP requests to the OpenAI API. You can do this by running the following command:
composer require guzzlehttp/guzzle
  1. Use the Guzzle library to send a POST request to the OpenAI API with your text input and receive a response containing the chatbot’s output.

Here is some example code that demonstrates how to do this:


require 'vendor/autoload.php';

$apiKey = 'YOUR_API_KEY';
$prompt = 'What is the weather like today?';

$client = new GuzzleHttp\Client();
$response = $client->post('https://api.openai.com/v1/models/text-davinci-002/completions', [
    'headers' => [
        'Content-Type' => 'application/json',
        'Authorization' => "Bearer $apiKey"
    'json' => [
        'prompt' => $prompt,
        'max_tokens' => 2048,
        'temperature' => 0.5,
        'top_p' => 1,
        'frequency_penalty' => 0,
        'presence_penalty' => 0

$responseJson = json_decode((string) $response->getBody());
$chatbotResponse = $responseJson->choices[0]->text;

echo $chatbotResponse;

This code will send a request to the OpenAI API with the text “What is the weather like today?” and print the chatbot’s response to the console.

From here, it would be very easy to expand this code and customize it for your AI chat requirements.

Training your Chatbotbot

What makes OpenAI GPT easy to use for natural language processing applications is how simple it is to train. Basically, GPT looks at a user’s input or “prompt” and then checks its very comprehensive database of languages to predict what text should come next and this is its answer or response to the prompt. It’s like asking someone to complete the phrase “To be, or not to be” and the correct response would be “That is the question.” Hence training GPT for your requirements is as simple as providing it with some initial prompts and it will predict already how you want the AI to behave. The more detail you give as an initial prompt, the more focused it will become with its answers.

For further assistance and information in developing chatbots and other AI-powered technologies, contact EACOMM Corporation at info@eacomm.com.