<?xml version="1.0" encoding="UTF-8" ?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <link href="https://rockin.ai/blog/research/?sAtom=1" rel="self" type="application/atom+xml" />
    <author>
        <name>Rockin.AI</name>
    </author>
    <title>Blog/Atom feed</title>
    <id>https://rockin.ai/blog/research/?sRss=1</id>
    <updated>2026-05-06T12:57:00+02:00</updated>
    
        <entry>
            <title type="text">OpenAI Fine-Tuning GPT Example</title>
            <id>https://rockin.ai/blog/research/openai-fine-tuning-gpt-example</id>
            <link href="https://rockin.ai/blog/research/openai-fine-tuning-gpt-example"/>
            <summary type="html">
                <![CDATA[
                
                                            We build a new model based on GPT, which is capable of making suggestions for mistyped email addresses.
                                        ]]>
            </summary>
            <content type="html">
                <![CDATA[
                 OpenAI has developed a new way to create AI models (called &quot;fine-tunes&quot; or &quot;GPTs&quot;), which is much easier than creating models from scratch with PyTorch or TensorFlow.&amp;nbsp;Fine-tuning works by providing us with a complete GPT LLM as the starting point, which by itself is extraordinarily difficult to replicate, and then allowing us to train it on a dataset. The best fine-tuned GPT models tend to work with  natural language or oriented around generating content . 
 In this tutorial, we will go though an example, covering all of the steps and details of creating a fine-tuned model. The task for the model will be to fix mistyped or misspelled email addresses. While it is easy to recognize a misformatted email address with plain regex, it is not so easy to suggest a fix, and we will harness the full power of GPT to help. 
 All of the&amp;nbsp; code and training data are shared below, so you can reproduce the results. At the end, we will also test the model in different ways to validate that it actually learned from our training data. 
 As a sneak peek, this model achieved a  90% accuracy rate  of finding mistyped email addresses, and also fixing them. 
 &amp;nbsp; 
 How Do I Fine-Tune My GPT Model? 
 The steps to fine-tuning a GPT model are the following: 
 
  Create an OpenAI account  and get an API key ( steps covered separately ) 
  Develop a training data set , which will be used to train an existing OpenAI GPT model 
  Create  a &quot;fine-tune&quot; (or GPT), based on the training data, with specific OpenAI API calls 
  Validate  the newly created model against a second validation data set 
 
 &amp;nbsp; 
 After validating your model, you will know how good it is at the specific task. 
 In case a model is performing poorly, we should remember two points.&amp;nbsp; First, we are training a model that is an LLM under the hood. An LLM will probably not be good at playing chess - but it will excel at any task involving language or text.&amp;nbsp; 
 Second, the training data set might be completely wrong or imbalanced. Actually, having a balanced data set is critical in achieving good results! This means having an equal amount of cases for each possible outcome we want. 
 &amp;nbsp; 
 OpenAI Fine-Tune Simple API Client 
 Below is a simple API client written in PHP, which has all of the functions necessary to upload our training data, create a fine tuning model, and also to run prompts on the newly created model.&amp;nbsp; 
 By default it will train GPT-3.5-turbo, however the list of possible models to train is constantly evolving with the newest models such as GPT-4 and more.&amp;nbsp; 
  
&amp;lt;?php
class OpenAIFineTuneSimpleClient {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private static $open_ai_key = &#039;&amp;lt;your openai api key&amp;gt;&#039;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private static $open_ai_url = &#039;https://api.openai.com/v1&#039;; //current version of the API endpoint
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/**
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * Uploads a file to OpenAI (normally a training file for fine tuning an existing model).
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; */ 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public static function uploadFile($filePath, $purpose=&#039;fine-tune&#039;) { 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$message = [];
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$message[&#039;file&#039;] = new CURLFile($filePath);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$message[&#039;purpose&#039;] = $purpose;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$result = self::_sendMessage(&#039;/files&#039;, $message, &#039;post&#039;, &#039;multipart/form-data&#039;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return $result;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/**
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * Create a new fine-tuned model, based on an existing model, using an uploaded training file.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; */
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public static function createFineTune($trainingFile, $model = &#039;gpt-3.5-turbo-1106&#039;, $validationFile=&#039;&#039;) { 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$message = new stdClass();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$message -&amp;gt; training_file = $trainingFile;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$message -&amp;gt; model = $model;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if($validationFile) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$message -&amp;gt; validation_file = $validationFile;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$result = self::_sendMessage(&#039;/fine_tuning/jobs&#039;, json_encode($message));
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return $result;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/**
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * Get a list of all existing fine-tunes for my account.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; */
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public static function getFineTunes() { 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$result = self::_sendMessage(&#039;/fine_tuning/jobs&#039;, &#039;&#039;, &#039;get&#039;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return $result;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/**
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * Doc: https://platform.openai.com/docs/api-reference/chat/create
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * @param array $messages (each item must have &quot;role&quot; and &quot;content&quot; elements, for )
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * @param int $maxTokens maximum tokens for the response in ChatGPT (1000 is the limit for gpt-3.5-turbo)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * @param string $model valid options are &quot;gpt-3.5-turbo&quot;, &quot;gpt-4&quot;, and in the future probably &quot;gpt-5&quot;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * @param int $responseVariants how many response to come up with (normally we just want one)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * @param float $frequencyPenalty between -2.0 and 2.0, penalize new tokens based on their existing frequency in the answer
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * @param int $presencePenalty between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the conversation so far, increasing the AI&#039;s chances to write on new topics.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * @param int $temperature default is 1, between 0 and 2, higher value makes the model more random in its discussion (going on tangents).
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * @param string $user if you have distinct app users, you can send a user ID here, and OpenAI will look to prevent common abuses or attacks
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; */
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public static function chat($messages = [], $maxTokens=100, $model=&#039;gpt-3.5-turbo&#039;, $responseVariants=1, $frequencyPenalty=0, $presencePenalty=0, $temperature=1, $user=&#039;&#039;) { 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//create message to post
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$message = new stdClass();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$message -&amp;gt; messages = $messages;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$message -&amp;gt; model = $model;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$message -&amp;gt; n = $responseVariants;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$message -&amp;gt; frequency_penalty = $frequencyPenalty;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$message -&amp;gt; presence_penalty = $presencePenalty;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$message -&amp;gt; temperature = $temperature;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if($user) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$message -&amp;gt; user = $user;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$result = self::_sendMessage(&#039;/chat/completions&#039;, json_encode($message));
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return $result;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private static function _sendMessage($endpoint, $data = &#039;&#039;, $method = &#039;post&#039;, $contentType = &#039;application/json&#039;) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$apiEndpoint = self::$open_ai_url.$endpoint;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$curl = curl_init();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if($method == &#039;post&#039;) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$params = array(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_URL =&amp;gt; $apiEndpoint,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_SSL_VERIFYHOST =&amp;gt; false,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_SSL_VERIFYPEER =&amp;gt; false,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_RETURNTRANSFER =&amp;gt; true,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_MAXREDIRS =&amp;gt; 10,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_TIMEOUT =&amp;gt; 90,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_HTTP_VERSION =&amp;gt; CURL_HTTP_VERSION_1_1,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_CUSTOMREQUEST =&amp;gt; &quot;POST&quot;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_NOBODY =&amp;gt; false, 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_HTTPHEADER =&amp;gt; array(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  &quot;content-type: &quot;.$contentType,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  &quot;accept: application/json&quot;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  &quot;authorization: Bearer &quot;.self::$open_ai_key
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;curl_setopt_array($curl, $params);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;} else if($method == &#039;get&#039;) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$params = array(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_URL =&amp;gt;  $apiEndpoint . ($data!=&#039;&#039;?(&#039;?&#039;.$data):&#039;&#039;),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_SSL_VERIFYHOST =&amp;gt; false,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_SSL_VERIFYPEER =&amp;gt; false,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_RETURNTRANSFER =&amp;gt; true,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_MAXREDIRS =&amp;gt; 10,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_TIMEOUT =&amp;gt; 90,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_HTTP_VERSION =&amp;gt; CURL_HTTP_VERSION_1_1,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_CUSTOMREQUEST =&amp;gt; &quot;GET&quot;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_NOBODY =&amp;gt; false, 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_HTTPHEADER =&amp;gt; array(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  &quot;content-type: &quot;.$contentType,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  &quot;accept: application/json&quot;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  &quot;authorization: Bearer &quot;.self::$open_ai_key
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;curl_setopt_array($curl, $params);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$response = curl_exec($curl);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;curl_close($curl);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$data = json_decode($response, true);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if(!is_array($data)) return array();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return $data;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
}
 
 
 &amp;nbsp; 
 Our Training Data Set 
 We have come up with a list of 50 cases (all using fake email addresses). 
 25 of them are perfectly good email addresses and 25 are obviously bad in some way. The training data belongs in a file called &quot;  train.jsonl  &quot;, and each line is a single data item.&amp;nbsp; 
 In each case, we provide three points of information: 
 
 Give the system a context for what it should be doing 
 A sample user input 
 A sample output based on the input 
 
 Please be aware that OpenAI has a policy moderating user inputs. So, it is important to  filter out inappropriate texts before sending them to the OpenAI API . 
  
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;hello.world@hotmail.com&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;hello.world@hotmail.com&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;helloworld@hotmail.com&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;helloworld@hotmail.com&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;johndoe@yahoo.ca&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;johndoe@yahoo.ca&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;johny_999@gmail.com&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;johny_999@gmail.com&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;t.w@car.com&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;t.w@car.com&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;support@rockin.ai&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;support@rockin.ai&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;yt@youtube.com&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;yt@youtube.com&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;postmaster@yahoo.com&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;postmaster@yahoo.com&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;press@facebook.com&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;press@facebook.com&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;wiki@wikipedia.org&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;wiki@wikipedia.org&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;mike@instagram.com&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;mike@instagram.com&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;quote@one.com&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;quote@one.com&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;mail@google.ca&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;mail@google.ca&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;code@stackoverflow.com&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;code@stackoverflow.com&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;test74430@gmail.com&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;test74430@gmail.com&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;user.r222224@yahoo.com&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;user.r222224@yahoo.com&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;patjohnson@aol.com&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;patjohnson@aol.com&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;sallywork@mail.com&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;sallywork@mail.com&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;mywork333@aol.com&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;mywork333@aol.com&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;pj@gmail.com&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;pj@gmail.com&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;sillycat666@gmail.com&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;sillycat666@gmail.com&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;techsupport@toyota.jp&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;techsupport@toyota.jp&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;dev@honda.com&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;dev@honda.com&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;trips@booking.com&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;trips@booking.com&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;article@news.com&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;article@news.com&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;u34582765639aol.com&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;u34582765639@aol.com&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;kfnnwufnjte@gmil.com&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;kfnnwufnjte@gmail.com&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;fnance@nyse.com&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;finance@nyse.com&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;sue.waters@google.ir&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;sue.waters@google.ie&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;mike.johnspn@gmail.com&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;mike.johnson@gmail.com&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;yahoo@yaho.com&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;yahoo@yahoo.com&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;sallyhome@mil.cm&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;sallyhome@mail.com&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;yorwork@aol.com&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;yourwork@aol.com&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;hi..there@gmail&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;hi.there@gmail.com&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;john doe@aol.com&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;johndoe@aol.com&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;pat@gmailcom&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;pat@gmail.com&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;sales@rockin.i&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;sales@rockin.ai&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;sam@aol.om&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;sam@aol.com&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;johny@hmail.com&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;johny@gmail.com&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;bookin@booking.com&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;booking@booking.com&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;web3gmailcom&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;web3@gmail.com&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;pstmaster@hello.com&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;postmaster@hello.com&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;mkejames@yaho.com&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;mikejames@yahoo.com&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;hithere#mail.com&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;hithere@mail.com&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;mymail!gmail,ca&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;mymail@gmail.com&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;juunkgmailom&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;junk@gmail.com&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;jjohn@gmmail.com&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;john@gmail.com&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;rchel@news.com&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;rachel@news.com&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;o.miler@aol.ca&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;o.miller@aol.ca&quot;}]}
{&quot;messages&quot;: [{&quot;role&quot;: &quot;system&quot;, &quot;content&quot;: &quot;You help to ensure an email address is correct. Email address correction. Fix email format. Fix obvious email mistype.&quot;}, {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: &quot;nicemail@ahoo..com&quot;}, {&quot;role&quot;: &quot;assistant&quot;, &quot;content&quot;: &quot;nicemail@yahoo.com&quot;}]}
 
 
 &amp;nbsp; 
 &amp;nbsp; 
 How Many Examples Are Needed For Fine-Tuning OpenAI? 
 When training GPT, or any AI model really, the more data we have the better. If we had to develop a production-ready model then we would likely use at tens of thousands at least.&amp;nbsp; 
 One of the main challenges of working with AI is not actually creating the model, but gathering the training data. This remains to be a major hurdle for any AI project. 
 Please remember to split the training data into two groups: one for training and a second one for validation of the model.&amp;nbsp; Also, within each group, there should be a roughly equal number of cases for each kind of result we are looking for.&amp;nbsp; For example, if we wanted to train vision system to recognize digits, it would make little sense to only train it on pictures of &quot;6&quot;.&amp;nbsp; It would never learn how to handle all of the other digits.&amp;nbsp; 
 Likewise, in our exercise we train the model based on exactly 25 valid email addresses, and 25 invalid ones.&amp;nbsp; We will also validate it against another group of 25 valid and invalid cases. 
 &amp;nbsp; 
 Training the GPT Model 
 Once we have a working OpenAI API client, and training data, the actual training part is easy. Below is all of the code needed to get this part done: 
  
&amp;lt;?php
include_once(&#039;OpenAIFineTuneSimpleClient.php&#039;);

$trainingDataFile = __DIR__.&#039;/train.jsonl&#039;;

//upload file to OpenAI APIs
$fileData = OpenAIFineTuneSimpleClient::uploadFile($trainingDataFile);
$fileId = $fileData[&#039;id&#039;];

//create fine-tune based on uploaded file
$fineTune = OpenAIFineTuneSimpleClient::createFineTune($fileId);

//list our current existing fine-tunes
$fineTunes = OpenAIFineTuneSimpleClient::getFileTunes();
 
 
 If we print the list of fine tunes, we will get something like the response below, which will just say that our fine-tune is queued for training: 
  
(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[object] =&amp;gt; list
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[data] =&amp;gt; Array
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[0] =&amp;gt; Array
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[object] =&amp;gt; fine_tuning.job
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[id] =&amp;gt; ftjob-sWfFKYBvGuxESHG5NGfUtaIB
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[model] =&amp;gt; gpt-3.5-turbo-1106
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[created_at] =&amp;gt; 1699403239
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[finished_at] =&amp;gt; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[fine_tuned_model] =&amp;gt; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[organization_id] =&amp;gt; org-JTVHhgoYtb2mHLDispep2oQB
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[result_files] =&amp;gt; Array
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;)

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [status] =&amp;gt; queued 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[validation_file] =&amp;gt; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[training_file] =&amp;gt; file-Lf7BL8hTqwkWrCNTsbjs9Yr3
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[hyperparameters] =&amp;gt; Array
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[n_epochs] =&amp;gt; 3
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[batch_size] =&amp;gt; 1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[learning_rate_multiplier] =&amp;gt; 2
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;)

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[trained_tokens] =&amp;gt; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[error] =&amp;gt; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;)

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;)

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[has_more] =&amp;gt; 
)
 
 
 Notice the default hyperparameters (epochs, batch size and learning rate) - these are all very familiar from the PyTorch world! We can also change these settings, but for most cases the default will be a good start. 
 &amp;nbsp; 
 How Long Did It Take To Create A Fine-Tuned GPT Model? 
 Sometimes, training a new model goes quickly, and sometimes not.&amp;nbsp; This depends on how busy the OpenAI servers are at the moment, and how much training data we have. In our case this took 4 hours. After the four hours passed, there was an email notification from OpenAI, and also if we fetch the fine-tunes again, we can see that our model is ready for use! 
   
 &amp;nbsp; 
  
(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[object] =&amp;gt; list
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[data] =&amp;gt; Array
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[0] =&amp;gt; Array
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[object] =&amp;gt; fine_tuning.job
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[id] =&amp;gt; ftjob-sWfFKYBvGuxESHG5NGfUtaIB
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[model] =&amp;gt; gpt-3.5-turbo-1106
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[created_at] =&amp;gt; 1699403239
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[finished_at] =&amp;gt; 1699421550
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [fine_tuned_model] =&amp;gt; ft:gpt-3.5-turbo-1106:personal::8IVSxqAx 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[organization_id] =&amp;gt; org-JTVHhgoYtb2mHLDispep2oQB
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[result_files] =&amp;gt; Array
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[0] =&amp;gt; file-HUiHkG9h4iKFQz1Su2ntwV3p
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;)

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [status] =&amp;gt; succeeded 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[validation_file] =&amp;gt; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[training_file] =&amp;gt; file-Lf7BL8hTqwkWrCNTsbjs9Yr3
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[hyperparameters] =&amp;gt; Array
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[n_epochs] =&amp;gt; 3
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[batch_size] =&amp;gt; 1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[learning_rate_multiplier] =&amp;gt; 2
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;)

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [trained_tokens] =&amp;gt; 7086 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[error] =&amp;gt; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;)

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;)

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[has_more] =&amp;gt; 
) 
 
 
 The most important detail of the above is that the training process succeeded. Also, we have a new fine-tuned model ID, and we also know how many tokens in total were consumed for training.&amp;nbsp; Some people have issues here because they think the training data is limited to 2048 tokens - but this is not true! 
 Each training case is limited (gpt-3.5-turbo is 2048, and gpt-4 can support up to 128k tokens) - but we can use any number of cases we want. So, we can have thousands of small training cases, which should give the model deep learning capabilities. 
 &amp;nbsp; 
 Validating The Fine-Tuned GPT 
 When validating a fine-tuned GPT, it is important to not use any of the same cases we used for training. We expect the model to learn these, but we want to try new cases! 
 We created a test script, using a completely different set of data. Let&#039;s see how our model performs: 
  
&amp;lt;!--?php 
include_once(&#039;OpenAIFineTuneSimpleClient.php&#039;);

$model=&#039;ft:gpt-3.5-turbo-1106:personal::8IVSxqAx&#039;;

$input = [
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//correct emails (AI no suggested change expected)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;eric.jones@google.com&#039; =&amp;gt; &#039;eric.jones@google.com&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;jones.eric@gmail.com&#039; =&amp;gt; &#039;jones.eric@gmail.com&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;finetune777@mail.com&#039; =&amp;gt; &#039;finetune777@mail.com&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;himom@yahoo.com&#039; =&amp;gt; &#039;himom@yahoo.com&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;abelincoln@aol.com&#039; =&amp;gt; &#039;abelincoln@aol.com&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;g.washington@google.com&#039; =&amp;gt; &#039;g.washington@google.com&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;george.w@gmail.com&#039; =&amp;gt; &#039;george.w@gmail.com&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;george_w@mail.com&#039; =&amp;gt; &#039;george_w@mail.com&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;elvis_theking@yahoo.com&#039; =&amp;gt; &#039;elvis_theking@yahoo.com&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;rocknroll@aol.com&#039; =&amp;gt; &#039;rocknroll@aol.com&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;ticketsales@google.com&#039; =&amp;gt; &#039;ticketsales@google.com&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;pieceofcake1991@gmail.com&#039; =&amp;gt; &#039;pieceofcake1991@gmail.com&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;iam.theone@mail.com&#039; =&amp;gt; &#039;iam.theone@mail.com&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;starfamous@yahoo.com&#039; =&amp;gt; &#039;starfamous@yahoo.com&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;john_richards@aol.com&#039; =&amp;gt; &#039;john_richards@aol.com&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;ceo@google.com&#039; =&amp;gt; &#039;ceo@google.com&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;cio@gmail.com&#039; =&amp;gt; &#039;cio@gmail.com&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;canadatest@mail.ca&#039; =&amp;gt; &#039;canadatest@mail.ca&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;test@yahoo.de&#039; =&amp;gt; &#039;test@yahoo.de&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;test88923@aol.fr&#039; =&amp;gt; &#039;test88923@aol.fr&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;mailme.here@google.com&#039; =&amp;gt; &#039;mailme.here@google.com&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;m.j@gmail.com&#039; =&amp;gt; &#039;m.j@gmail.com&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;ironman@mail.com&#039; =&amp;gt; &#039;ironman@mail.com&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;mr.johnson@yahoo.com&#039; =&amp;gt; &#039;mr.johnson@yahoo.com&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;no7way2@aol.com&#039; =&amp;gt; &#039;no7way2@aol.com&#039;,

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//emails with typos (AI suggested change expected)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;jj@google.cm&#039; =&amp;gt; &#039;jj@google.com&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;workgmail..com&#039; =&amp;gt; &#039;work@gmail.com&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;.hr@mail.com&#039; =&amp;gt; &#039;hr@mail.com&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;suppor@yahoo.com&#039; =&amp;gt; &#039;support@yahoo.com&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;srvice@aol.com&#039; =&amp;gt; &#039;service@aol.com&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;woork4832943@google.com&#039; =&amp;gt; &#039;work4832943@google.com&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;bornlastcenury20@gmail.com&#039; =&amp;gt; &#039;bornlastcentury20@gmail.com&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;jake@ma3il.ccom&#039; =&amp;gt; &#039;jake@mail.com&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;jeff@amazn.com&#039; =&amp;gt; &#039;jeff@amazon.com&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;pony1234567aol.com&#039; =&amp;gt; &#039;pony1234567@aol.com&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;fidget_spinner@goggle.com&#039; =&amp;gt; &#039;fidget_spinner@google.com&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;ht..@gmail.com&#039; =&amp;gt; &#039;ht@gmail.com&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;joe@@mail.com&#039; =&amp;gt; &#039;joe@mail.com&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;care##yahoo/com&#039; =&amp;gt; &#039;care@yahoo.com&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;missing@nsdaq.om&#039; =&amp;gt; &#039;missing@nsdaq.com&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;way1975@google.co&#039; =&amp;gt; &#039;way1975@google.com&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;t.biggs^gmailcom&#039; =&amp;gt; &#039;t.biggs@gmail.com&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;vacationsmail.com&#039; =&amp;gt; &#039;vacationsmail.com&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;the dude@yahoo.com&#039; =&amp;gt; &#039;thedude@yahoo.com&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;g*o*o*d@aol.com&#039; =&amp;gt; &#039;good@aol.com&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;piceofcake@google.com&#039; =&amp;gt; &#039;pieceofcake@google.com&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;www555@gmailom&#039; =&amp;gt; &#039;www555@gmail.com&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;parse...dots@mail.com&#039; =&amp;gt; &#039;parse.dots@mail.com&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;true@yahoo.vcom&#039; =&amp;gt; &#039;true@yahoo.com&#039;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;thebestaolcom&#039; =&amp;gt; &#039;thebest@aol.com&#039;,
];

$failCount = 0;

foreach($input as $inputEmail =&amp;gt; $expectedOutputEmail) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$messages = [
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&quot;role&quot; =&amp;gt; &quot;user&quot;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&quot;content&quot; =&amp;gt; $inputEmail
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;];
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$gptOutput = OpenAIFineTuneSimpleClient::chat($messages, 100, $model); 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$aiSuggestedEmail = $gptOutput[&#039;choices&#039;][0][&#039;message&#039;][&#039;content&#039;];
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if(strcasecmp($expectedOutputEmail, $aiSuggestedEmail) != 0) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$failCount++;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;echo &#039;Failed Test: (input: &#039;.$inputEmail.&#039;) (expected: &#039;.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$expectedOutputEmail.&#039;) (result: &#039;.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$aiSuggestedEmail.&#039;)&amp;lt;br?&amp;gt;&#039;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
}

$totalTests = count($input);

echo &#039;Total Tests: &#039;.$totalTests.&#039; &#039;;
echo &#039;Failed Tests: &#039;.$failCount.&#039; &#039;;
echo &#039;Model Accuracy: &#039;.(($totalTests - $failCount) / $totalTests * 100).&#039;% &#039;;
 
 
 And below is the result of our tests.&amp;nbsp; 
 We managed to achieve a model with  90% accuracy , and the performance is very good at just&amp;nbsp; 0.2368 seconds per test ! 
 Looking at the failed tests, we believe this is an issue of our data set being too small for the job, but the results are surpisingly good already. 
   
 &amp;nbsp; 
  &amp;nbsp;  
 How Much Did It Cost To Fine-Tune GPT? 
 During our training stage, we used up around 8k tokens. We also ran many tests (even repeating some of them to make sure the results were reliable). The total cost was roughly $1.50, which is a great deal considering we got to experiment with one of the most advanced AI models, and used some of the best infrastructure in the world. We ran our code from local dev systems, which have no cost. 
  Hint:  since the dollar cost of producing a single fine-tune is so low, it&#039;s possible to generate several variations of the same model based on slightly different training datasets, and then use the one that has the best validation test results. 
 &amp;nbsp; 
 Testing Our Model In OpenAI Playground 
 OpenAI has a  playground , where we can accomplish most of the above tasks by an application. It was nice to see that our new model was made available in this application, and we did some testing of our own model vs. GPT-3.5-Turbo. 
 &amp;nbsp; 
   
  Fine-tuned GPT model successfuly fixing a mistyped email address&amp;nbsp;  
 &amp;nbsp; 
   
   Normal non-tuned &amp;nbsp;GPT model failing to fix the same email address  
 &amp;nbsp; 
  &amp;nbsp;  
 Conclusion 
 We are very happy with the opportunity to train some of the most powerful AI models available. From our short test, we could definitely see the benefit of using GPT fine-tunes in certain cases where a generative AI would excel. We managed to create a new model, which is capable of doing a good job at recognizing mistyped email addresses. 
 In the future, it would be interesting to have some kind of a download option on the model, and run it by ourselves. While the whole experience was impressive, we have to note that OpenAI will forever own the model we created, and charge us every time we want to use it. 
 If you are interested in other ideas for training GPT models, we have a separate article about  cleaning up real-world data with AI &amp;nbsp;and another  example for using embeddings to compare and search texts . 
 &amp;nbsp; 
                ]]>
            </content>

                            <updated>2023-11-07T00:00:00+01:00</updated>
                    </entry>

    
    
        <entry>
            <title type="text">OpenAI API Performance</title>
            <id>https://rockin.ai/blog/research/openai-api-performance</id>
            <link href="https://rockin.ai/blog/research/openai-api-performance"/>
            <summary type="html">
                <![CDATA[
                
                                            We performance tested all of the OpenAI APIs, and made statistics, so you don&#039;t have to make the same tests.
                                        ]]>
            </summary>
            <content type="html">
                <![CDATA[
                 OpenAI has created a large API library, which is being used by millions of developers and companies around the world. We ran performance tests for every available OpenAI API - all the way from chat to image generation and fine tuning own models. The following is a comprehensive report of all of our findings, and also suggestions for improvements in case your application is suffering from slow requests to OpenAI, ChatGPT, DALL-E, and all the rest. 
 &amp;nbsp; 
 Complete OpenAI API Performance Benchmarks 
 Below is our complete summary of the benchmarks we performed on the OpenAI APIs. In all cases, we use the following base URL:  https://api.openai.com/v1  
 For each test, we ran a set of 10 calls, and took note of the average response times,  using PostMan  to make all of the connections and calls. 
 When testing APIs like images or chat, we made sure to create several different inputs to try an capture variability in performance. We can safely state that the OpenAI team is very nicely using parallel threads, and therefore there isn&#039;t much difference between generating one image or three. 
 &amp;nbsp; 
 
 
  API  API Function  Type  Endpoint  Time ms (avg)  Model Used For Tests  Response Size  
 
 Models 
 List Models 
 GET 
 /models 
 318 
 &amp;nbsp; 
 &amp;nbsp; 
 
 
 Models 
 Retrieve Model 
 GET 
 /models/babbage 
 198 
 &amp;nbsp; 
 &amp;nbsp; 
 
 
 Completions (text) 
 Create Completion 
 POST 
 /completions 
 636 
 gpt-3.5-turbo-instruct 
 &amp;nbsp; 
 
 
 Chat (text) 
 Chat Completion 
 POST 
 /chat/completions 
 22,484 
 gpt-3.5-turbo 
 250 tokens 
 
 
 Chat (text) 
 Chat Completion 
 POST 
 /chat/completions 
 31,431 
 gpt-3.5-turbo 
 1000 tokens 
 
 
 Chat (text) 
 Chat Completion 
 POST 
 /chat/completions 
 14,457 
 gpt-4 
 250 tokens 
 
 
 Chat (text) 
 Chat Completion 
 POST 
 /chat/completions 
 18,974 
 gpt-4 
 1000 tokens 
 
 
 Images 
 Create Image 
 POST 
 /images/generations 
 7,882 
 dall-e-2 
 1 image 1024x1024px 
 
 
 Images 
 Create Image 
 POST 
 /images/generations 
 8,594 
 dall-e-2 
 2 images 1024x1024px 
 
 
 Images 
 Create Image 
 POST 
 /images/generations 
 8,833 
 dall-e-2 
 3 images 1024x1024px 
 
 
 Images 
 Create Image 
 POST 
 /images/generations 
 7,126 
 dall-e-2 
 1 image 512x512px 
 
 
 Images 
 Create Image 
 POST 
 /images/generations 
 7,391 
 dall-e-2 
 2 images 512x512px 
 
 
 Images 
 Create Image 
 POST 
 /images/generations 
 7,617 
 dall-e-2 
 3 images 512x512px 
 
 
 Images 
 Create Image 
 POST 
 /images/generations 
 6,569 
 dall-e-2 
 1 image 256x256px 
 
 
 Images 
 Create Image 
 POST 
 /images/generations 
 6,775 
 dall-e-2 
 2 images 256x256px 
 
 
 Images 
 Create Image 
 POST 
 /images/generations 
 7,003 
 dall-e-2 
 3 images 256x256px 
 
 
 Images 
 Create Image 
 POST 
 /images/generations 
 12,795 
 dall-e-3 
 1 image 1024x1024px 
 
 
 Images 
 Create Image 
 POST 
 /images/generations 
 16,962 
 dall-e-3 
 1 image 1024x1792px 
 
 
 Images 
 Create Image 
 POST 
 /images/generations 
 15,977 
 dall-e-3 
 1 image 1792x1024px 
 
 
 Images 
 Create Image Edit 
 POST 
 /images/edits 
 12,546 
 &amp;nbsp; 
 1 image 1024x1024px 
 
 
 Images 
 Create Image Edit 
 POST 
 /images/edits 
 13,441 
 &amp;nbsp; 
 2 images 1024x1024px 
 
 
 Images 
 Create Image Edit 
 POST 
 /images/edits 
 13,587 
 &amp;nbsp; 
 3 images 1024x1024px 
 
 
 Images 
 Create Image Edit 
 POST 
 /images/edits 
 9,901 
 &amp;nbsp; 
 1 image 512x512px 
 
 
 Images 
 Create Image Edit 
 POST 
 /images/edits 
 10,622 
 &amp;nbsp; 
 2 images 512x512px 
 
 
 Images 
 Create Image Edit 
 POST 
 /images/edits 
 10,978 
 &amp;nbsp; 
 3 images 512x512px 
 
 
 Images 
 Create Image Edit 
 POST 
 /images/edits 
 9,150 
 &amp;nbsp; 
 1 image 256x256px 
 
 
 Images 
 Create Image Edit 
 POST 
 /images/edits 
 9,093 
 &amp;nbsp; 
 2 images 256x256px 
 
 
 Images 
 Create Image Edit 
 POST 
 /images/edits 
 9,438 
 &amp;nbsp; 
 3 images 256x256px 
 
 
 Images 
 Create Image Variation 
 POST 
 /images/variations 
 9,885 
 &amp;nbsp; 
 1 image 1024x1024px 
 
 
 Images 
 Create Image Variation 
 POST 
 /images/variations 
 10,231 
 &amp;nbsp; 
 2 images 1024x1024px 
 
 
 Images 
 Create Image Variation 
 POST 
 /images/variations 
 10,654 
 &amp;nbsp; 
 3 images 1024x1024px 
 
 
 Images 
 Create Image Variation 
 POST 
 /images/variations 
 8,139 
 &amp;nbsp; 
 1 image 512x512px 
 
 
 Images 
 Create Image Variation 
 POST 
 /images/variations 
 8,456 
 &amp;nbsp; 
 2 images 512x512px 
 
 
 Images 
 Create Image Variation 
 POST 
 /images/variations 
 8,861 
 &amp;nbsp; 
 3 images 512x512px 
 
 
 Images 
 Create Image Variation 
 POST 
 /images/variations 
 7,302 
 &amp;nbsp; 
 1 image 256x256px 
 
 
 Images 
 Create Image Variation 
 POST 
 /images/variations 
 7,564 
 &amp;nbsp; 
 2 images 256x256px 
 
 
 Images 
 Create Image Variation 
 POST 
 /images/variations 
 7,847 
 &amp;nbsp; 
 3 images 256x256px 
 
 
 Speech To Text 
 Create Transcription 
 POST 
 /audio/transcriptions 
 4,011 
 whisper-1 (60s audio mp3 192kbps) 
 &amp;nbsp; 
 
 
 Speech To Text 
 Create Transcription 
 POST 
 /audio/transcriptions 
 1,295 
 whisper-1 (10s audio mp3 192kbps) 
 &amp;nbsp; 
 
 
 Embeddings 
 Create Embedding 
 POST 
 /embeddings 
 205 
 text-embedding-ada-002 
 30-100 tokens 
 
 
 Files 
 Upload File 
 POST 
 /files 
 711 
 10kb JSONL file 
 &amp;nbsp; 
 
 
 Files 
 Get Files 
 GET 
 /files 
 185 
 &amp;nbsp; 
 list of files 
 
 
 Files 
 Get Files 
 GET 
 /files/:file_id 
 106 
 &amp;nbsp; 
 single file description 
 
 
 Files 
 Get File Contents 
 GET 
 /files/:file_id/content 
 578 
 10kb JSONL file 
 single file content 
 
 
 Fine-Tunes 
 Create Fine Tune 
 POST 
 /fine-tunes 
 247 
 davinci 
 &amp;nbsp; 
 
 
 Fine-Tunes 
 List Fine Tunes 
 GET 
 /fine-tunes 
 231 
 &amp;nbsp; 
 &amp;nbsp; 
 
 
 Fine-Tunes 
 Retrieve Fine Tune 
 GET 
 /fine-tunes/:fine_tune_id 
 141 
 &amp;nbsp; 
 &amp;nbsp; 
 
 
 Fine-Tunes 
 Cancel Fine Tune 
 POST 
 /fine-tunes/:fine_tune_id/cancel 
 198 
 &amp;nbsp; 
 &amp;nbsp; 
 
 
 Fine-Tunes 
 List Fine Tune Events 
 GET 
 /fine-tunes/:fine_tune_id/events 
 128 
 &amp;nbsp; 
 &amp;nbsp; 
 
 
 Fine-Tunes 
 Delete Fine Tuned Model 
 DEL 
 /models/:model 
 139 
 &amp;nbsp; 
 &amp;nbsp; 
 
 
 Fine-Tunes 
 Use Fine Tuned Model 
 POST 
 /completions 
 655 
 similar to normal /completions call 
 &amp;nbsp; 
 
 
 Moderations 
 Check Moderation 
 POST 
 /moderations 
 331 
 text-moderation 
 10-500 tokens 
 
 
 Engines 
 List Engines 
 GET 
 /engines 
 175 
 &amp;nbsp; 
 &amp;nbsp; 
 
 
 Engines 
 Retrieve Engine 
 GET 
 /engines/:engineId 
 134 
 &amp;nbsp; 
 &amp;nbsp; 
 
 
 
  OpenAI API Average Response Times For Different Inputs and Models  
 &amp;nbsp;&amp;nbsp; 
 How To Use The Above Performance Tests 
 When developing an application, it is often the case that there is slow performance in some specific area, and the dev team would need to start profiling and logging to see exactly what&#039;s happening. With the above performance metrics, hopefully this task will be easier, giving the application developers the chance to compare observed speeds with another team. 
 For example, if a certain API response is taking a long time, it is nice to see if anyone else has the same issue. 
 &amp;nbsp; 
 How The Benchmarks Can Change 
 We noticed that over time, OpenAI APIs are becoming faster. This is most likely due to additional hardware being commissioned to run the services, and an improving infrastructure overall.&amp;nbsp; 
 Likewise, the exact opposite can happen in case the APIs experience a spike in requests, such as when a new product is released or big news comes out. 
 &amp;nbsp; 
 Why Is the OpenAI Chat API Slow? 
 The worst performing OpenAI API is definitely the chat completion with the conversation object. This API comes has an  average response time of 22 seconds  - which is a lot!&amp;nbsp; 
 We believe the main reason for this is, the conversation object has to go through a lot of processing just to prepare the LLM context, which has to be referenced on every newly generated token. Chances are, the OpenAI team does not have much chance to improve on this, aside for getting faster machines. 
 &amp;nbsp; 
 How Can We Improve Our ChatGPT API Call Performance? 
 There are really only two options available to improve performance on the client side: 
 
 Use buffering - this will also give the same effect like ChatGPT has, to give the result one word or token at a time 
 Use the alternative API (base_url /completions ) which only works on a single question/answer basis 
 
 &amp;nbsp; 
 The second option is a hidden gem, which may save many applications out there! We have a  tutorial devoted to creating a fine-tuned model , and using this endpoint we got the GPT API to respond in under 0.25 seconds per request. 
 First, it works very fast (0.6sec per request on average).&amp;nbsp;&amp;nbsp;Secondly, the results are quite good. Not as good as the complete model with the full conversation - but still very respectable. 
 We also ran some tests of just the completions endpoint and compared the results to the chat completions endpoint, and given the performance difference we will have a serious look at changing some of our applications. 
 &amp;nbsp; 
 Image Generation Performance Benchmarks 
 On average, with the OpenAI API, we can roughly expect the following performance speeds for images: 
 
 Generating a new image from text:  ~7.5 sec  
 Generating a new image, from an existing image:  ~8.7 sec  
 Filling an image cutout:  ~10.9 sec  
 
 &amp;nbsp; 
 Depending on the output image size, performance will vary slightly, but not by a lot. So, we recommend to just work with the 1024x1024 pixel image sizes at all times.&amp;nbsp; 
 To get the best possible performance out of the API, stick to generating just one image and in the smaller possible resolution necessary (there are three options: 256x256px, 512x512px and 1024x1024px). 
 As a sidenote, we can make some assumptions about how the APIs work to create images.&amp;nbsp; There is one main Image Generation AI, which takes a prompt and a canvas, and fills it with content. The other two capabilities of filling cutouts and generating variations are just preparsing the input into this AI. This is only a guess, as the actual algorithms are kept in secret. 
 &amp;nbsp; 
 OpenAI API Unexpected Server Error 
 While performing tests, we can across an unexpected error, and here is what it looks like: 
   
 &amp;nbsp; 
 We accidentally sent an optional parameter with an empty value into the API. Hopefully this helps both the developers to catch this case, and also the OpenAI team to better handle such cases. 
 &amp;nbsp; 
 Which OpenAI APIs Are The Best Performers? 
 We firmly believe the best APIs are these:  fine tuning  and  text completion .&amp;nbsp; 
 These APIs specifically perform very well, under 1 second per call, and given the work done by these functions, this level of performance was actually pleasant surprise!&amp;nbsp; 
 With these APIs, we can train custom models, and run them at amazing speeds - even faster than the main ChatGPT LLM. 
 &amp;nbsp; 
 What Is The Single Best OpenAI API? 
 We believe the  Moderations API  is highly underrated, and will eventually be used by all applications that use AI. It takes a single text input, and tells us if the text violates any terms of service for being unsafe for the user. Besides doing a good task, it also runs very fast and just around 0.3 sec per request. 
 &amp;nbsp; 
 Conclusion 
 OpenAI APIs are overall performing very well given the tasks at hand. It is no easy matter to generate new content on the fly, while making sure it is valuable and safe at the same time! 
 If you think you are ready for developing some OpenAI plugins,  join the OpenAI developer waitlist, and make some plugins for ChatGPT . 
                ]]>
            </content>

                            <updated>2023-11-04T00:00:00+01:00</updated>
                    </entry>

    
    
        <entry>
            <title type="text">ChatGPT Developer Waitlist</title>
            <id>https://rockin.ai/blog/research/chatgpt-developer-waitlist</id>
            <link href="https://rockin.ai/blog/research/chatgpt-developer-waitlist"/>
            <summary type="html">
                <![CDATA[
                
                                            Take the steps necessary to become a ChatGPT plugin developer.
                                        ]]>
            </summary>
            <content type="html">
                <![CDATA[
                 OpenAI has opened the doors for 3rd party developers like us to join their platform and start making plugins. The whole concept and process is similar to Apple&#039;s App Store, where likewise the whole world was invited to create apps for their devices. This has a lot of potential to grow in popularity and make the first adopters well off. 
 There are a few prerequisites to join the plugin store developer waitlist. First you will need to have a ChatGPT Plus subscription. Then, during signup you will have to describe what it is you intend to build. This last step is actually important because it is quite possible to be turned down because the plugin idea is not very good. 
 &amp;nbsp; 
 Check If You Already Have Developer Access 
 Things may change in the future, and all subscribes could be given access. (Currently everyone has to register on the waitlist).&amp;nbsp; 
 Below are the steps to see if you already have plugin developer access to GPT-4.&amp;nbsp; 
 If you do not see the  Plugins  button in GPT-4, go to your settings (at the bottom) and enable Beta features for your account.&amp;nbsp; Enabling Plugins is just one toggle.&amp;nbsp; 
 &amp;nbsp; 
   
 &amp;nbsp; 
 Next, open the plugin store... 
   
 &amp;nbsp; 
 And check if you have a button to upload a plugin. If there is no button like this, then you have no developer access and you have to register on the waitlist. However, if you can already upload a plugin, that means you can already build and test your own customer plugins! 
   
 &amp;nbsp; 
 Register On The Plugin Store Developer Waitlist 
 In order to register for the developer waitlist you have to be a resident of  one of the supported countries  by OpenAI. Next open the  ChatGPT developer waitlist registration page  and fill out the details. Most of the fields are straight forward, but there are a couple of questions about what it is you intend to build. Make sure you have a specific use case your first plugin will cover, and explain this in your request. Having a positive mindset and specific goals will go a long way for the review process of your application. 
 &amp;nbsp; 
   
 &amp;nbsp; 
 Once you have filled out the form, click &quot; Join waitlist &quot; and make sure you got a  thank you  message. That&#039;s it, you are done! 
   
 &amp;nbsp; 
 Lastly, you should be receiving a message like the one below in your email inbox, confirming that you have registered. This message should arrive a few minutes after making your submission. Below is what this message looks like.&amp;nbsp; 
   
 &amp;nbsp; 
 How Long Will It Take To Approve My Application? 
 From our research, it currently takes about two months to join the plugin developer group. The main reason is, this is a public page and they are likely receiving tens of thousands every day. Each application has to go through some minimal checks, and this takes time. In the future this may be automated and would therefore go faster. 
 While you wait, you may check out our  tutorial on connecting to GPT-4 , also  to DALL-E  and don&#039;t forget about  content moderation . 
 &amp;nbsp; 
 How many plugins are there on ChatGPT? 
 At the time of this writing (Nov-23) there are only 1,040 plugins in total on the ChatGPT plugin store. If you are reading this in the future, feel free to comment how many there are now - it will be interesting for sure. 
 &amp;nbsp; 
 Conclusion 
 We believe this is an incredible opportunity that no developer should miss. A whole new platform has emerged, with millions of users and growing. The OpenAI team is allowing us to join the growth, and build some exciting new tools together. Good fortunes to everyone who accepts this challenge and builds new plugins. 
 To start you off, here are some plugin ideas that can potentially be created: 
 
 If you company already has digital services, these can be offered on ChatGPT 
 New themes for the user interface (remains to be seen) 
 Highly specialized use cases, such as event planning, etc 
 Games (remains to be seen) 
 Etc. only limited by imagination 
 
 &amp;nbsp; 
                ]]>
            </content>

                            <updated>2023-11-02T00:00:00+01:00</updated>
                    </entry>

    
    
        <entry>
            <title type="text">GPT-4 How to Upload a PDF</title>
            <id>https://rockin.ai/blog/research/gpt-4-how-to-upload-a-pdf</id>
            <link href="https://rockin.ai/blog/research/gpt-4-how-to-upload-a-pdf"/>
            <summary type="html">
                <![CDATA[
                
                                            Simple tutorial for how to upload PDF files to OpenAI&#039;s Chat GPT-4, and work with those files.
                                        ]]>
            </summary>
            <content type="html">
                <![CDATA[
                 The PDF upload feature is only available in the paid version of GPT-4 (aka ChatGPT Plus). There is no capability to upload a PDF in ChatGPT3.5 on the OpenAI web application.  The quickest steps to upload a PDF to GPT-4 are the following: 
 
 Go to your user settings 
 Enable Beta features (specifically advanced data analysis) 
 Switch GPT-4 to Advanced Data Analysis mode 
 Upload your PDF directly into the prompt and ask questions 
 
 In the article below, we will go through all of the steps, with supporting screenshots. It is worth noting that uploading PDFs directly to ChatGPT is only available in the paid version, and this feature is not available in the free version. 
 &amp;nbsp; 
 How to Enable Beta Features in GPT-4 
 In order to enable beta features in GPT-4, first click on the three dots (...) next to your user account name, and then open the settings. 
   
 &amp;nbsp; 
 Once the settings come up, open the &quot; Beta features &quot; menu, and enable the &quot; Advanced data analysis &quot; option. It will also be very useful to enable the Plugins option, so that you can use 3rd party plugins in the system (more on that later). 
   
 &amp;nbsp; 
 How to Switch GPT-4 to Advanced Data Analysis Mode 
 ChatGPT&#039;s advanced data analysis is capable of receiving any file format, and then doing any work on it. It is really quite something to see first hand, once you have access to it. The tool will show all of the work done (from a coding perspective), and make logical conclusions based on the parsed data, and the prompt from the user. 
 Mouse over the GPT-4 tab, and in the flyout select &quot; Advanced Data Analysis &quot;.&amp;nbsp; 
   
 &amp;nbsp; 
 How to Upload PDF to GPT-4 
 After switching to the advanced data analysis mode of GPT-4, you can now simply drag and drop PDF files right into the prompt! In the example screenshot below, you&#039;ll see us uploading a sample resume directly to GPT-4 without using any plugin or sending our data to an external website.&amp;nbsp; 
 Additional questions or instructions can be entered just below the dropped PDF file. Some  common prompts for a PDF  file are: 
 
 Summarize the attached PDF ( see also ChatGPT text capabilities ) 
 Find key points in the attached PDF 
 List important dates in the plan 
 Find [given subject] in the text 
 etc 
 
   
 &amp;nbsp; 
 And below, we can see that GPT-4 did indeed correctly parse the file, and made a short summary of the contents. This process will take a few seconds, and along the way there will be notifications of the work done. This work is impressive by itself, because GPT is writing Python code on the fly to deal with the question at hand. 
   
 &amp;nbsp; 
 Conclusion 
 Uploading PDF files is a new capability in the paid version of GPT-4, which comes with a subscription to ChatGPT Plus. This subscription costs just $20 per month, and given how powerful it is, is it definitely worth the investment. 
 Some of the older ways of handling PDF in ChatGPT are now becoming obsolete. For example, there were many popular plugins made by indie developers and startups, to do just this one simple task. And now, with these new features coming out, OpenAI is improving the user experience on their own. 
 Besides uploading PDFs, the application will also accept Excel files, CSV files and even PowerPoint. The LLM appears to be getting smarter too, as it makes good assumptions of relating different data together.&amp;nbsp; For example  in one of our tests , after uploading an Excel sheet of tasks, it was able to find out which ones were done vs. not done, and came up with supporting statistics. 
                ]]>
            </content>

                            <updated>2023-10-31T00:00:00+01:00</updated>
                    </entry>

    
    
        <entry>
            <title type="text">Use ChatGPT In PHP, With GPT-4 Examples</title>
            <id>https://rockin.ai/blog/research/use-chatgpt-in-php-with-gpt-4-examples</id>
            <link href="https://rockin.ai/blog/research/use-chatgpt-in-php-with-gpt-4-examples"/>
            <summary type="html">
                <![CDATA[
                
                                            How to connect to ChatGPT from PHP, with a simple client implementation and examples.
                                        ]]>
            </summary>
            <content type="html">
                <![CDATA[
                 Let&#039;s connect to ChatGPT from PHP, and see what the possibilities really are. Below, we will dive right into the topic. We will try to keep everything as easy to understand as possible, and keep the details separate from the &quot;just get it done&quot; approach. 
 To start off, you will need an OpenAI account and a payment method assigned to it. This is needed because this API is not free for use, and costs a little bit of money ($0.002 per 1000 tokens to be exact - more on this later). 
 &amp;nbsp; 
 Get your OpenAI API Key 
 Below are the steps to get your OpenAI API key as screenshots.&amp;nbsp; This is the  OpenAI page  where you have to go for this.&amp;nbsp; 
 &amp;nbsp; 
   
 &amp;nbsp; 
 Click on &quot;Create new secret key&quot;, and give your key a name.&amp;nbsp; This can really be anything.&amp;nbsp; 
   
 &amp;nbsp; 
 Now, copy your key and store it in a safe place. BTW, all OpenAI API keys start with &quot;sk-&quot;, which stands for &quot;secret key&quot;.&amp;nbsp; 
   
 &amp;nbsp; 
 Simple PHP Client For ChatGPT 
 Below is an implementation for a very simple PHP client, which you can use to make a connection to ChatGPT.&amp;nbsp; 
 In case you are wondering - is the whole of ChatGPT really just one API endpoint?  Yes, it is.  
  
&amp;lt;?php
class ChatGPTSimpleClient {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//get your api key here: https://platform.openai.com/account/api-keys
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private static $open_ai_key = &#039;your-openai-chatgpt-api-key-goes-here&#039;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private static $open_ai_url = &#039;https://api.openai.com/v1&#039;; //current version of the API endpoint
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;/**
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * Doc: https://platform.openai.com/docs/api-reference/chat/create
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * @param array $messages (each item must have &quot;role&quot; and &quot;content&quot; elements, this is the whole conversation)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * @param int $maxTokens maximum tokens for the response in ChatGPT (1000 is the limit for gpt-3.5-turbo)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * @param string $model valid options are &quot;gpt-3.5-turbo&quot;, &quot;gpt-4&quot;, and in the future probably &quot;gpt-5&quot;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * @param int $responseVariants how many response to come up with (normally we just want one)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * @param float $frequencyPenalty between -2.0 and 2.0, penalize new tokens based on their existing frequency in the answer
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * @param int $presencePenalty between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the conversation so far, increasing the AI&#039;s chances to write on new topics.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * @param int $temperature default is 1, between 0 and 2, higher value makes the model more random in its discussion (going on tangents).
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * @param string $user if you have distinct app users, you can send a user ID here, and OpenAI will look to prevent common abuses or attacks
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; */
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public static function chat($messages = [], $maxTokens=2000, $model=&#039;gpt-4&#039;, $responseVariants=1, $frequencyPenalty=0, $presencePenalty=0, $temperature=1, $user=&#039;&#039;) { 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//create message to post
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$message = new stdClass();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$message -&amp;gt; messages = $messages;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$message -&amp;gt; model = $model;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$message -&amp;gt; n = $responseVariants;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$message -&amp;gt; frequency_penalty = $frequencyPenalty;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$message -&amp;gt; presence_penalty = $presencePenalty;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$message -&amp;gt; temperature = $temperature;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if($user) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$message -&amp;gt; user = $user;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$result = self::_sendMessage(&#039;/chat/completions&#039;, json_encode($message));
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return $result;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private static function _sendMessage($endpoint, $data = &#039;&#039;, $method = &#039;post&#039;) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$apiEndpoint = self::$open_ai_url.$endpoint;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$curl = curl_init();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if($method == &#039;post&#039;) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$params = array(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_URL =&amp;gt; $apiEndpoint,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_SSL_VERIFYHOST =&amp;gt; false,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_SSL_VERIFYPEER =&amp;gt; false,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_RETURNTRANSFER =&amp;gt; true,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_MAXREDIRS =&amp;gt; 10,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_TIMEOUT =&amp;gt; 90,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_HTTP_VERSION =&amp;gt; CURL_HTTP_VERSION_1_1,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_CUSTOMREQUEST =&amp;gt; &quot;POST&quot;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_NOBODY =&amp;gt; false, 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_HTTPHEADER =&amp;gt; array(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  &quot;content-type: application/json&quot;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  &quot;accept: application/json&quot;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  &quot;authorization: Bearer &quot;.self::$open_ai_key
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;curl_setopt_array($curl, $params);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;} else if($method == &#039;get&#039;) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$params = array(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_URL =&amp;gt;  $apiEndpoint . ($data!=&#039;&#039;?(&#039;?&#039;.$data):&#039;&#039;),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_SSL_VERIFYHOST =&amp;gt; false,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_SSL_VERIFYPEER =&amp;gt; false,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_RETURNTRANSFER =&amp;gt; true,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_MAXREDIRS =&amp;gt; 10,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_TIMEOUT =&amp;gt; 90,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_HTTP_VERSION =&amp;gt; CURL_HTTP_VERSION_1_1,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_CUSTOMREQUEST =&amp;gt; &quot;GET&quot;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_NOBODY =&amp;gt; false, 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_HTTPHEADER =&amp;gt; array(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  &quot;content-type: application/json&quot;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  &quot;accept: application/json&quot;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  &quot;authorization: Bearer &quot;.self::$open_ai_key
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;curl_setopt_array($curl, $params);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$response = curl_exec($curl);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;curl_close($curl);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$data = json_decode($response, true);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if(!is_array($data)) return array();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return $data;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
}
 
 
 &amp;nbsp; 
 Sending an Example Message to ChatGPT 
 We will immediately follow up on the simple client, with a simple use of it:&amp;nbsp; 
  
&amp;lt;?php
include_once(&#039;./ChatGPTSimpleClient.php&#039;);

$response = ChatGPTSimpleClient::chat([
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//OPTIONAL - explain to ChatGPT, what is its role in this conversation
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&quot;role&quot; =&amp;gt; &quot;system&quot;, 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&quot;content&quot; =&amp;gt;  &quot;You help companies add AI to their internal processes.&quot;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;],
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//OPTIONAL - Give the conversation a &quot;starting point&quot;, pretend like the user asked a question already
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[ 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&quot;role&quot; =&amp;gt; &quot;user&quot;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&quot;content&quot; =&amp;gt; &quot;How can AI help my company?&quot;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;],
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//OPTIONAL - Give what would have been a great answer from ChatGPT... (this lets the LLM learn the context a bit)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[ 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&quot;role&quot; =&amp;gt; &quot;assistant&quot;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&quot;content&quot; =&amp;gt; &quot;AI products such as ChatGPT, are able to act like virtual assistant, and support every employee with useful tips and information.&quot;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;],
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//REQUIRED - The latest &quot;prompt&quot; to ChatGPT, this is what we really want the AI to answer
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//NOTE - without the previous context (company AI processes), this question below would have little meaning.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[ 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&quot;role&quot; =&amp;gt; &quot;user&quot;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&quot;content&quot; =&amp;gt; &quot;Which common tasks can you help with?&quot;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;]
]);

print_r($response);
 
 
 In the above, please note that we have a few optional items in the converstation object, which are all there to provide ChatGPT the context. Without this, asking a question like &quot;which common tasks can you help with?&quot; will most likely result in a nonsensical answer. 
 And let&#039;s have a look at the response from ChatGPT below (notice how it is really using the whole conversation, and not just the last question from the user): 
  
Array
(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[id] =&amp;gt; chatcmpl-8Gw5NvrwW7rvrT1vop7fWbigvkoFp
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[object] =&amp;gt; chat.completion
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[created] =&amp;gt; 1699047221
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[model] =&amp;gt; gpt-4-0613
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[choices] =&amp;gt; Array
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[0] =&amp;gt; Array
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[index] =&amp;gt; 0
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[message] =&amp;gt; Array
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[role] =&amp;gt; assistant
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[content] =&amp;gt; AI can help automate a wide range of tasks, such as:

1. Customer Service: AI can help with automating responses to common customer inquiries, allowing your customer service representatives to focus on more complex issues.

2. Data Analysis: AI algorithms can process and analyze massive amounts of data far more efficiently than humans can. They can identify trends and patterns that can help in decision-making.

3. Sales and Marketing: AI can help segment your customer base, personalize communication, predict future trends, and even automate parts of the sales process.

4. HR and Recruitment: AI can help sift through resumes, perform background checks, schedule interviews, and even analyze facial expressions and voice tones during interviews to assess candidate fit.

5. Operations: AI can help with inventory management, supply chain optimization, facilities management, and more.

6. Finance: AI can automate many financial tasks such as invoicing, payroll, tax preparation, etc.

7. IT management: AI can help in identifying and rectifying IT issues, managing IT infrastructure, etc. 

In addition, AI can learn from its previous interactions, constantly improving its performance and accuracy over time.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;)

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[finish_reason] =&amp;gt; stop
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;)

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;)

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[usage] =&amp;gt; Array
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[prompt_tokens] =&amp;gt; 70
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[completion_tokens] =&amp;gt; 228
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[total_tokens] =&amp;gt; 298
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;)

)

 
 
 &amp;nbsp; 
 How Fast Does The ChatGPT API Respond? 
 Surprisingly, the ChatGPT API is not fast at all. The above example takes a whopping  22 seconds  to run, and all of this time is spent waiting for the response. The performance is improving with newer versions, but we really wish this improvement was faster.&amp;nbsp; 
 There is an opportunity for buffering the response, but this is far from ideal. If you plan on developing APPs, there will have to be clever solutions to keep the user entertained while they wait. 
 &amp;nbsp; 
 How Much Did The Above ChatGPT Request Cost? 
 In the response, at the bottom we can see we used 70 tokens for the prompt, 228 tokens were used for the answer and the total was 298. 
 The total cost for this one request was  298 / 1000 * 0.002 = $0.000596 . 
 In other words, it will take 1678 such requests to reach a bill of $1.&amp;nbsp; This is not too bad actually, but please take care to not run into an infinite loop and leave it running for a while. 
 &amp;nbsp; 
 What Are ChatGPT Tokens and What Are The Limits? 
 We have this  article devoted to describing tokens and limits , but in short, a ChatGPT token is a 4-character string.&amp;nbsp; The definition gets much more nuanced - but this is a generally acepted rule of thumb.&amp;nbsp; 
 In theory, GPT-4 is limited to 2000 tokens per request and response, however in practice this limit is often much lower at just 1000.&amp;nbsp; 
 &amp;nbsp; 
 Explaining the ChatGPT Conversation Object 
 This object is really a list of questions and answers, with a different role per item.&amp;nbsp; The three main roles are:&amp;nbsp; 
 
 system: Any conversation contects or prerequisites go here 
 assistant: this is ChatGPT, basically the AI trying to help the user 
 user: the end user asking questions 
 
 &amp;nbsp; 
 Notice in the above example, we used the &quot;system&quot; role to explain to ChatGPT that its current role is to help companies use AI. Some other examples might be: 
 
 You analyze sales data at companies 
 You help companies achieve marketing goals 
 etc 
 
 &amp;nbsp; 
 Next, the &quot;content&quot; of each conversation item, is including just a plain text description or prompt or response. 
  Here is what&#039;s important:  the conversation object includes the the whole conversation as a chain.&amp;nbsp; It gives ChatGPT the full context to use for the next answer.&amp;nbsp; Once the answer comes, you as the developer can add the answer to the chain, and add the next user question at the end, thereby continuing the conversation. As the conversation continues, the conversation object will grow, and your follow-up questions will become more expensive. Eventually, once the conversation object reaches a certain length (~2k tokens for GPT-4), you will get an error from the API. 
 &amp;nbsp;&amp;nbsp; 
 Most Useful Parameters To Know About 
 For us, the following were the most useful parameters to change so far: 
 
  model :&amp;nbsp;&quot; gpt-3.5-turbo &quot;, &quot; gpt-4 &quot;, and in the future probably &quot; gpt-5 &quot;. 
  maxTokens : this is the maximum tokens we want for the answer from ChatGPT. 2000 will let the LLM be verbose, and smaller numbers will force it to be more concise. 
  user : in case your app has users, it&#039;s a good idea to send a user Hash here - and OpenAI may block abusers of the API on your behalf. (think DDOS attackers, or inappropriate prompts) 
 
 &amp;nbsp; 
 All of the other parameters are in alright to just leave as default.&amp;nbsp; But you are free to change them too, and see how ChatGPT changes its behavior. 
 &amp;nbsp; 
 Conclusion 
 At this point, the above tutorial should have provided you with enough details to get you started on a connection from PHP to ChatGPT. We tried to keep the code short and non-abstracted. If you made it this far, you will likely want to  sign up to the OpenAI Developer Waitlist  to create some plugins for the ecosystem. Here is also a  tutorial for using vector embeddings to search texts  (it&#039;s a good one). 
 Feel free to drop a comment or question below. 
 &amp;nbsp; 
                ]]>
            </content>

                            <updated>2023-10-29T00:00:00+02:00</updated>
                    </entry>

    
    
        <entry>
            <title type="text">ChatGPT Getting Worse? Only Temporarily</title>
            <id>https://rockin.ai/blog/research/chatgpt-getting-worse-only-temporarily</id>
            <link href="https://rockin.ai/blog/research/chatgpt-getting-worse-only-temporarily"/>
            <summary type="html">
                <![CDATA[
                
                                            While ChatGPT&#039;s text generation capabilities are increasingly human-like, there&#039;s evidence to suggest that the model&#039;s accuracy is deteriorating over time. This is likely due to longer term improvements and tests being done.
                                        ]]>
            </summary>
            <content type="html">
                <![CDATA[
                 A pair of recent studies have raised concerns about OpenAI&#039;s ChatGPT large language model programs. While these models have gained popularity for their text generation capabilities, which are often indistinguishable from human responses, there is evidence suggesting a decline in their accuracy over time. What&#039;s particularly worrying is that researchers are struggling to pinpoint the cause of this deterioration. 
 &amp;nbsp; 
 ChatGPT &quot;Drift&quot; 
 A joint effort by researchers from Stanford and UC Berkeley published a study noting the noticeable changes in ChatGPT&#039;s behavior over time, and they&#039;re somewhat perplexed about the reasons behind this decline. To assess the consistency of ChatGPT&#039;s underlying GPT-3.5 and GPT-4 models, the team investigated its propensity to &quot;drift,&quot; meaning it provided answers of varying quality and accuracy, as well as its ability to follow given commands. The researchers asked both ChatGPT-3.5 and -4 to solve mathematical problems, address sensitive or risky questions, engage in visual reasoning based on  prompts , and generate computer code. 
 &amp;nbsp; 
 Losing Previous Capabilities 
 Their findings revealed that the behavior of the same LLM service can change significantly in a relatively short time, emphasizing the need for ongoing monitoring of LLM quality. For example, in March 2023, GPT-4 could identify prime numbers with nearly 98% accuracy, but by June, its accuracy had dropped to less than 3% for the same task. On the other hand, GPT-3.5 had improved its performance in identifying prime numbers between March and June 2023. When it came to generating computer code, both versions demonstrated a decline in their abilities during the same period. 
 These discrepancies could have real-world consequences soon. A recent paper published in the JMIR Medical Education journal by NYU researchers indicated that ChatGPT&#039;s responses to healthcare-related queries are nearly indistinguishable from those of human medical professionals in terms of tone and phrasing. Participants in the study had limited ability to differentiate between responses from human healthcare providers and those generated by OpenAI&#039;s large language model. This comes at a time when concerns about AI&#039;s handling of medical data privacy and its tendency to provide inaccurate information are on the rise. 
 &amp;nbsp; 
 Declining Performance 
 Academics are not the only ones noticing ChatGPT&#039;s declining performance. Business Insider reported ongoing discussions on OpenAI&#039;s developer forum regarding the model&#039;s progress, or lack thereof. Some users expressed disappointment, highlighting the need for an official response from OpenAI. 
 &amp;nbsp; 
 Being Closed Source 
 OpenAI&#039;s research and development activities for its large language models are notoriously shielded from external review, a practice that has faced criticism from industry experts and users. Matei Zaharia, one of the co-authors of a ChatGPT quality review paper and an associate professor of computer science at UC Berkeley, suggested on Twitter that the decline in quality might be due to limitations in reinforcement learning from human feedback (RLHF) and fine-tuning, or it could be attributed to bugs in the system. 
 &amp;nbsp; 
 Conclusion 
 While ChatGPT may perform well on basic Turing Test benchmarks, its inconsistent quality raises significant concerns for the public. These concerns persist as these models continue to proliferate and integrate into everyday life, with limited barriers to their widespread adoption. This is most likely all due to the LLM still being in its infant stage, and countinuing to learn. 
 It is also important to remember that user expectations have grown tremendously, and the model is now expected to provide the most helpful and relevant responses to anything but perfect prompts. OpenAI will learn and adapt their products for the changing market. 
                ]]>
            </content>

                            <updated>2023-10-15T00:00:00+02:00</updated>
                    </entry>

    
    
        <entry>
            <title type="text">Simple PHP API Client for DALL-E: Creating Images from Prompts</title>
            <id>https://rockin.ai/blog/research/simple-php-api-client-for-dall-e-creating-images-from-prompts</id>
            <link href="https://rockin.ai/blog/research/simple-php-api-client-for-dall-e-creating-images-from-prompts"/>
            <summary type="html">
                <![CDATA[
                
                                            Discover how to create a PHP API client for DALL-E, OpenAI&#039;s generative model that can produce images from textual prompts. This is a small, light weight client that just gets the job done.
                                        ]]>
            </summary>
            <content type="html">
                <![CDATA[
                 In the world of AI, creating art and imagery with generative models has become an exciting reality. DALL-E, developed by OpenAI, is one such groundbreaking model that can generate images from  textual prompts . In this article, we&#039;ll walk you through the process of building a straightforward PHP API client to connect to DALL-E, allowing you to harness its creative potential by generating images based on your prompts. To get started, you&#039;ll need an OpenAI API key as part of your OpenAI user account. 
 You can also just copy the simple PHP client class below, which will give you a head start on creating a quick proof of concept for image generation. 
 &amp;nbsp; 
 Setting Up Your OpenAI Account 
 Before we dive into building the PHP API client for DALL-E, you&#039;ll need to make sure you have an  OpenAI account and an API key . If you don&#039;t already have one, you can sign up for an  OpenAI account  and obtain your API key from the OpenAI Developer platform ( we cover this in more detail separately ). 
 &amp;nbsp; 
 Once you have your API key, you&#039;re ready to start using your PHP client. 
 &amp;nbsp; 
  
class DallEClient {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private static $open_ai_key = &#039;your_open_ai_api_key_goes_here&#039;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private static $open_ai_url = &#039;https://api.openai.com/v1&#039;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public static function generateImages($prompt, $n = 1, $size = &#039;1024x1024&#039;, $response_format = &#039;url&#039;, $model=&#039;dall-e-3&#039;, $user = &#039;&#039;) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//doc: https://platform.openai.com/docs/api-reference/images/create
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//create message to post
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$message = new stdClass();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$message -&amp;gt; prompt = $prompt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$message -&amp;gt; n = $n;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$message -&amp;gt; size = $size;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$message -&amp;gt; response_format = $response_format;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$message -&amp;gt; model = $model;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if($user) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$message -&amp;gt; user = $user;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$result = self::_sendMessage(&#039;/images/generations&#039;, json_encode($message));
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return $result;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private static function _sendMessage($endpoint, $data = &#039;&#039;, $method = &#039;post&#039;) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$apiEndpoint = self::$open_ai_url.$endpoint;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$curl = curl_init();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if($method == &#039;post&#039;) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$params = array(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_URL =&amp;gt; $apiEndpoint,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_SSL_VERIFYHOST =&amp;gt; false,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_SSL_VERIFYPEER =&amp;gt; false,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_RETURNTRANSFER =&amp;gt; true,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_MAXREDIRS =&amp;gt; 10,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_TIMEOUT =&amp;gt; 90,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_HTTP_VERSION =&amp;gt; CURL_HTTP_VERSION_1_1,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_CUSTOMREQUEST =&amp;gt; &quot;POST&quot;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_NOBODY =&amp;gt; false, 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_HTTPHEADER =&amp;gt; array(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  &quot;content-type: application/json&quot;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  &quot;accept: application/json&quot;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  &quot;authorization: Bearer &quot;.self::$open_ai_key
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;curl_setopt_array($curl, $params);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;} else if($method == &#039;get&#039;) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$params = array(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_URL =&amp;gt;  $apiEndpoint . ($data!=&#039;&#039;?(&#039;?&#039;.$data):&#039;&#039;),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_SSL_VERIFYHOST =&amp;gt; false,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_SSL_VERIFYPEER =&amp;gt; false,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_RETURNTRANSFER =&amp;gt; true,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_MAXREDIRS =&amp;gt; 10,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_TIMEOUT =&amp;gt; 90,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_HTTP_VERSION =&amp;gt; CURL_HTTP_VERSION_1_1,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_CUSTOMREQUEST =&amp;gt; &quot;GET&quot;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_NOBODY =&amp;gt; false, 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CURLOPT_HTTPHEADER =&amp;gt; array(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  //&quot;cache-control: no-cache&quot;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  &quot;content-type: application/json&quot;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  &quot;accept: application/json&quot;,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  &quot;authorization: Bearer &quot;.self::$open_ai_key
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;curl_setopt_array($curl, $params);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$response = curl_exec($curl);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;curl_close($curl);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$data = json_decode($response, true);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if(!is_array($data)) return array();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return $data;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
}
 
 
 &amp;nbsp; 
 Customizing Your DALL-E Client 
 You can further customize your DALL-E API client to meet your specific needs.&amp;nbsp; 
 For example, you can adjust the prompt to generate images with different concepts and scenes. Some examples of   prompt modifiers  &amp;nbsp;that work are: 
 
 black and white 
 outdoors 
 neon lighting 
 monochromatic 
 
 &amp;nbsp; 
 You can just add the above as plain text to your prompt, and DALL-E will abide.&amp;nbsp; 
 For best results, the model DALL-E-3 should be used, however currently it only support at most 1 image generation at a time. 
 &amp;nbsp; 
 Conclusion 
 With your simple PHP API client for DALL-E, you have the power to create images from your prompts, unlocking a world of creative possibilities. As DALL-E and similar generative AI models continue to evolve, the potential for generating art, visuals, and even concepts is limitless. By connecting to the OpenAI API, you can explore the exciting world of AI-generated imagery and use it in a variety of applications, from art and design to content creation and more.&amp;nbsp; 
 One more important tip, is to  moderate your text prompts  before sending them to OpenAI - this is one step developers often forget. 
                ]]>
            </content>

                            <updated>2023-09-30T00:00:00+02:00</updated>
                    </entry>

    
    
        <entry>
            <title type="text">ChatGPT Characters and Words Limits</title>
            <id>https://rockin.ai/blog/research/chatgpt-characters-and-words-limits</id>
            <link href="https://rockin.ai/blog/research/chatgpt-characters-and-words-limits"/>
            <summary type="html">
                <![CDATA[
                
                                            ChatGPT prompt and output limits, and how to navigate them. Many tips provided here to help with development.
                                        ]]>
            </summary>
            <content type="html">
                <![CDATA[
                 ChatGPT limits both the input (prompt) and output texts, to at most 4096 characters. All texts are split into &quot; tokens &quot;, which are on average 4 characters long. Then, based on the number of tokens (both input and output), your OpenAI account will be charged a flat fee of $0.002 (0.2 cents) per 1000 tokens when using GPT-3.5. The newer model &quot;GPT-4 Turbo&quot; has a different price of $0.01/1K input tokens and $0.03/1K output tokens. 
 For example, let&#039;s say we have the following text: &quot; My cat eats food like a boss &quot;.&amp;nbsp; This is counted as  7&amp;nbsp;tokens ; it just so happens that each word is at most 4 letters long. In contrast, the following text is 5 tokens long, bause it uses longer words: &quot; Rabbits are fluffy &quot;. 
 The main issue with this model is, you never really know in advance what is the exact number of tokens being passed back and forth. In the article below we&#039;ll go over some ways to make estimates and get a feel for how much the cost will be, and we will also provide some helpful tips along the way. 
 &amp;nbsp; 
 What is The Maximum Character Limit For The Input? 
 The character limit on ChatGPT 3.5 is 4096. For GPT-4 the limit is 8192, however this is only theoretical, and in practice it will still usually be 4096. Developers report that this is still an issue for the OpenAI API.&amp;nbsp; 
 Below is a table of the official character and token limits for ChatGPT, and also practical limits being reported by real world developers. It is important to remember, both limits are applied to requests and outputs (character and token limit).&amp;nbsp; 
 
 
  Version  Official Character Limit (input and output)  Official Token Limit (input and output)  Practical Character Limit (input and output)  Practical Token Limit (input and output)  
 
 ChatGPT-3.5 
 4096 
 1024 
 4096 
 1024 
 
 
 GPT-4 
 8192 
 2048 
 ~4096 
 ~1024 
 
 
 GPT-4-Turbo 
 512000 
 128000 
 tbd 
 tbd 
 
 
 
 The reason for GPT-4 having this limit in practice is usually it will cut short of producing much more text. This may change in the future as the model improves.&amp;nbsp; 
 &amp;nbsp;&amp;nbsp; 
 Estimating The Number of Tokens 
 OpenAI provides  this online tool  to estimate how many &quot;tokens&quot; a given text contains.&amp;nbsp; 
 Developers often need to make an estimate locally before sending any request to OpenAI, and below is an estimator written in PHP. Please use it with caution, as it is only  providing an estimate , which will differ from what will be counted in the real API - but from our tests it comes  very close . 
  
function estimateTokens($text) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$compactText = preg_replace(&#039;/\s+/&#039;, &#039; &#039;, $text);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$textLength = strlen($compactText);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if(strlen($text) == 1) return 1; //corner case
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$totalTokens = 0;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$curWordLength = 0;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$curType = 0;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for($x=0; $x &amp;lt; $textLength - 1; $x++) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$curChar = $compactText[$x];
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$nextChar = $compactText[$x+1];
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$curType = getCharType($curChar);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$nextType = getCharType($nextChar);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if($curType == 1 || $curType != $nextType) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if($curType == 4) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$totalTokens += (int)($curWordLength / 6.1);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;} else {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$totalTokens += (int)($curWordLength / 4.0);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if($curType != 4 &amp;amp;&amp;amp; $curWordLength % 4 &amp;gt; 0) $totalTokens++;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if($nextType == 4) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$curWordLength = 0;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;} else {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$curWordLength = 1;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;} else if($curType == $nextType) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$curWordLength++;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;} else echo &#039;#&#039;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$totalTokens += (int)($curWordLength / 4.0);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if($curType != 4 &amp;amp;&amp;amp; $curWordLength % 4 &amp;gt; 0) $totalTokens++;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return $totalTokens;
}

function getCharType($char) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if($char == &#039; &#039;) { //is space
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return 1;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;} else if($char &amp;gt;= &#039;0&#039; &amp;amp;&amp;amp; $char &amp;lt;= &#039;9&#039;) { //is digit
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return 2;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;} else if(($char &amp;gt;= &#039;!&#039; &amp;amp;&amp;amp; $char &amp;lt;= &#039;/&#039;) || 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;($char &amp;gt;= &#039;:&#039; &amp;amp;&amp;amp; $char &amp;lt;= &#039;@&#039;) || 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;($char &amp;gt;= &#039;[&#039; &amp;amp;&amp;amp; $char &amp;lt;= &#039;`&#039;) || 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;($char &amp;gt;= &#039;{&#039; &amp;amp;&amp;amp; $char &amp;lt;= &#039;~&#039;)) { //is punctuation
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return 3;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;} 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//assume just a normal character
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return 4;
}
 
 
 &amp;nbsp; 
 Many developers just use a short-hand rule of thumb, which is  count the number of characters and divide this by 4.  
 &amp;nbsp; 
 Reducing How Many Tokens You Use 
 The LLM is verry good at handling texts (as in words).&amp;nbsp; However, we found that it treats digits and punctuation as separate tokens. If you can afford to, try removing too much punctuation, numbers, etc.&amp;nbsp; Here are some examples that may surprise you: 
 
 
  Text  Tokens  
 
 Hello world 
 2 
 
 
 Hello, world. 
 4 
 
 
 GPT-3.5 and GPT-4 
 11 
 
 
 A quick brown fox 
 4 
 
 
 
 The point should be clear: if possible avoid filler words or words with no contextual meaning if you want to minimize costs.&amp;nbsp;&amp;nbsp; 
 To reduce the size of the output, you may add a command (in plain text) to the prompt such as  &quot;Keep the output as short as possible&quot;,  or something that makes sense for your application. See below for an example: 
   
 &amp;nbsp; 
 &amp;nbsp; 
 How To Use More Characters Than The Allowed Limit? 
 While we cannot really change the output maximum size, there is an opportunity to give ChatGPT more than just what is allowed.&amp;nbsp; That&#039;s because this limit is only  per request  - but we can use multiple requests! People will often break the input into several requests, and make sure the conversation is maintained. This way, ChatGPT will have some previous texts to refer to.&amp;nbsp; There are limits even to this approach however, as the model will start to forget older data and only use the most recent information. 
 Have a look at our  ChatGPT API tutorial  which comes with code examples and responses. 
 &amp;nbsp; 
 Set Your API Usage Limits 
 Not many companies have this feature, but OpenAI does! If you go to the page (https://platform.openai.com/account/billing/limits), there are some options to basically kill the API connection, in case it gets out of control ( think accidental infinite loop ). Setting some limits are a smart move, and could save you some unnecessary expenses when you&#039;re  starting out or just prototyping in the ChatGPT API . 
   
 &amp;nbsp; 
 Conclusion 
 ChatGPT has limits on both the input and output, which are the same for a given version (3.5 or 4). GPT-4 promises to deliver twice the tokens, however this is often not seen in practice and thus far not very reliable. This should improve in the future as the models learn more over time. If you think you are ready,  join the OpenAI developer waitlist, and make some plugins for ChatGPT . 
                ]]>
            </content>

                            <updated>2023-09-10T00:00:00+02:00</updated>
                    </entry>

    
    
        <entry>
            <title type="text">ChatGPT Text Rephrasing Capabilities</title>
            <id>https://rockin.ai/blog/research/chatgpt-text-rephrasing-capabilities</id>
            <link href="https://rockin.ai/blog/research/chatgpt-text-rephrasing-capabilities"/>
            <summary type="html">
                <![CDATA[
                
                                            Rephrasing text in ChatGPT is a straightforward process. First, provide the original text you want to rephrase. Then, specify your desired level of transformation, whether you want a slight paraphrase or a more significant rewording. ChatGPT will generate an alternative versio...
                                        ]]>
            </summary>
            <content type="html">
                <![CDATA[
                 Using ChatGPT to transform a given text is basically the first use-case of the tool, and it changed the world forever. It&#039;s a lot like having a calculator - where we can &quot;just get the answer&quot; after some keystrokes. Below we explore the different ways to rephrase or paraphrase texts, with concrete examples. 
 The basic steps to accomplish text rephrasing go as follows: 
 
 Provide the text to rephrase or paraphrase 
 State the length of text to output (paragraph, sentence, article, etc) 
 Add a tone to the writing style 
 
 &amp;nbsp; 
   
 &amp;nbsp; 
 Generating Longer Texts 
 Let&#039;s ask ChatGPT to use its generative AI powers to create a marketing email. In the example below, we ask it to use &quot;marketing&quot; tone in an &quot;email&quot; output format. We also give it some more information about our product.&amp;nbsp; In general, other marketing materials can be used here.&amp;nbsp;&amp;nbsp; 
 About ChatGPT specifically, please remember that it will limit itself to approximately 500 words of output. See our complete technical guide to&amp;nbsp; ChatGPT text limits . 
    
Given the article title &quot;Our product is the best in the market&quot; and the product description &quot;With our product, you can automate and scale your business to the moon.&quot;, write a 3 paragraph sales email to people who are unsure about our company.
&amp;gt;
&amp;gt;
Subject: Unlock Your Business Potential with the Best Product in the Market
&amp;nbsp;
Dear [Recipient&#039;s Name],
&amp;nbsp;
We hope this email finds you well. If you&#039;ve ever had doubts about the efficacy of our product, we want to assure you that &quot;Our product is the best in the market,&quot; is more than just a statement—it&#039;s a testament to the transformative power of what we offer.
&amp;nbsp;
In today&#039;s dynamic business landscape, finding a solution that not only works but excels is paramount. Our product has been meticulously crafted to empower you with the tools you need to automate and scale your business to unprecedented heights. Imagine a future where your business soars to the moon, leaving your competitors in the dust. Our product is the rocket fuel to make that vision a reality.
&amp;nbsp;
But don&#039;t just take our word for it. We invite you to discover for yourself why countless businesses have chosen us to be their growth partner. Let us provide you with a personalized demonstration to showcase how our product can revolutionize your operations and elevate your success. Your journey to business excellence starts with a single click.
&amp;nbsp;
Don&#039;t miss the opportunity to join the ranks of successful entrepreneurs who have harnessed the potential of our product. We&#039;re here to answer any questions you may have and guide you on this exciting journey. It&#039;s time to turn your business dreams into reality.
&amp;nbsp;
Warm regards,
&amp;nbsp;
[Your Name]
[Your Title]
[Your Company]
[Contact Information]
 
 
 &amp;nbsp; 
 Generating Shorter Texts 
 One of the biggest issues in marketing is to take a concept or message, and put it into as few words as possible while still retaining all of the context. Marketing people are always searching for a synonym of this or common saying for that.&amp;nbsp; 
 LLMs in general are very good at this, and ChatGPT produces some awesome results: 
   
 In the above image, we asked ChatGPT to generate a short marketing message (setting the tone), and while the result is many not perfect, it can be used for further inspairation to craft the final text. 
 Up next, we&#039;ll create some video titles, which are again maybe not perfect but a good start: 
   
Create 5 short titles for youtube, with slight clickbait, about how our product (called WidgetX) is very good and many people are using it, and we are growing rapidly.
&amp;gt;
&quot;WidgetX: The Incredible Product Everyone&#039;s Obsessed With!&quot;
&quot;Discover Why WidgetX Is Taking Over - Get Yours Now!&quot;
&quot;WidgetX Unleashed: The Secret Behind Our Explosive Growth!&quot;
&quot;WidgetX: The Hottest Trend of 2023 - What You Need to Know!&quot;
&quot;Join the WidgetX Revolution - See Why Millions Can&#039;t Resist!&quot;
 
 
 &amp;nbsp; 
 Adding Tones in Writing Style 
 Some common tones and writing styles that work are the following (and there are probably many more!): 
 
 Marketing message or email 
 Tweet for posting on X 
 Video or article title 
 Scholarly text (for sounding smart) 
 Resume cover letter written in professional style 
 
 &amp;nbsp; 
 So far, from our tests, ChatGPT has almost always got the tone correct. If not, then with some finetuning or asking it to regenerate could yield better results. 
 &amp;nbsp; 
 Grabbing the Key Ideas 
 Another common text shortening prompts is to ask the LLM to examine the provided text, and give back the basic ideas or concepts expressed within.&amp;nbsp; 
 Up next, we&#039;ll create some video titles, which are again maybe not perfect but a good start: 
   
Summarize the key points of the following text,  into short bullet points : &quot;In today&#039;s dynamic business landscape, finding a solution that not only works but excels is paramount. Our product has been meticulously crafted to empower you with the tools you need to automate and scale your business to unprecedented heights. Imagine a future where your business soars to the moon, leaving your competitors in the dust. Our product is the rocket fuel to make that vision a reality.
 
But don&#039;t just take our word for it. We invite you to discover for yourself why countless businesses have chosen us to be their growth partner. Let us provide you with a personalized demonstration to showcase how our product can revolutionize your operations and elevate your success. Your journey to business excellence starts with a single click.
 
Don&#039;t miss the opportunity to join the ranks of successful entrepreneurs who have harnessed the potential of our product. We&#039;re here to answer any questions you may have and guide you on this exciting journey. It&#039;s time to turn your business dreams into reality.&quot;
&amp;gt;
&amp;gt;  
 
 The text stresses the importance of finding a high-performing solution in the business world. 
 The product is designed for automation and scaling business operations. 
 It envisions a future where businesses outperform competitors. 
 The product is presented as the catalyst for this vision. 
 Encourages readers to experience the product&#039;s benefits through personalized demonstrations. 
 Positions the product as a partner for business growth and excellence. 
 Invites entrepreneurs to seize the opportunity and achieve their business dreams. 
 
 &amp;nbsp; 
 Conclusion 
 In this article, we covered a few different ways to rephrase texts into longer or shorter ones. The results are not bad at all, and actually very difficult to tell that it was processed in some way. The applications of this are practically limitless, and will help business to finetune their websites and marketing content.&amp;nbsp; 
 For more tips, have a look at our  prompt engineering guide . 
 &amp;nbsp; 
                ]]>
            </content>

                            <updated>2023-08-15T00:00:00+02:00</updated>
                    </entry>

    
</feed>
