<?xml version="1.0" encoding="UTF-8" ?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <link href="https://rockin.ai/blog/?sAtom=1" rel="self" type="application/atom+xml" />
    <author>
        <name>Rockin.AI</name>
    </author>
    <title>Blog/Atom feed</title>
    <id>https://rockin.ai/blog/?sRss=1</id>
    <updated>2026-05-05T11:26:34+02:00</updated>
    
        <entry>
            <title type="text">OpenAI Embeddings Tutorial</title>
            <id>https://rockin.ai/blog/generative-ai/openai-embeddings-tutorial</id>
            <link href="https://rockin.ai/blog/generative-ai/openai-embeddings-tutorial"/>
            <summary type="html">
                <![CDATA[
                
                                            Embeddings help to relate different texts with similar meaning. This new AI capability will change several tech industries.
                                        ]]>
            </summary>
            <content type="html">
                <![CDATA[
                 OpenAI embeddings present a new way to describe texts, so that those texts can be ranked or classified based on their meaning. This is a new technology bound to change how we work with text data today. 
 To give a concrete example, most current solutions search for substrings or keywords. With embeddings we can search for  semantic meaning , and not just syntax. 
 In the following tutorial, we will use embeddings to search and rank texts based on their natural language meaning, and provide code samples along the way. Also, we will not be using any fancy tools, and just stick to the basics so that anyone can follow along. 
 &amp;nbsp; 
 What Are Embedding Vectors and Vector Databases? 
 An embedding vector is just a list of decimal values, which describe a given text. For example, the word &quot; Dog &quot; may be represented as [1.5, 2.3, 3.8], which may seem meaningless at first glance. The vector starts to make sense if we compare it to another vector for &quot; Canine &quot;, which may be [1.5, 2.2, 3.7]. Notice how the two vectors are very similar even though the texts are nothing like each other. 
 OpenAI gives us vectors (or just lists of decimal values), which are all of the same size:   1536  values . These vectors capture the meaning of the texts. 
 A vector database is a collection of texts, with their vectors stored in a database table, such as MySQL. This database can later be used ot quickly search or rank results based on a search query. 
 &amp;nbsp; 
 OpenAI Simple Embeddings Client 
 Below is a simple API client for OpenAI&#039;s embeddings function. We will use it later to get embedding vectors for our database and also for our search query. 
 The entire concept only needs a single API endpoint from OpenAI:  /embeddings  
  Side note: &amp;nbsp;please remember to sanitize your text input through  OpenAI moderations in a production setting . 
  
&amp;lt;?php
class OpenAIEmbeddingSimpleClient {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;private static $open_ai_key = &#039;&amp;lt;your openai key here&amp;gt;&#039;;
&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;public static function embeddings($text, $model=&#039;text-embedding-ada-002&#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; input = $text;
&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;$result = self::_sendMessage(&#039;/embeddings&#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;, $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; 
 Fetching Vectors and Storing Them In Our Database 
 First, let&#039;s create a MySQL database table, where we will store our texts and vectors. 
  
CREATE TABLE `vectors` (
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;`text` TEXT NULL DEFAULT NULL,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;`embedding` TEXT NULL DEFAULT NULL,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;PRIMARY KEY (`id`) USING BTREE
)
ENGINE=InnoDB;
 
 
 &amp;nbsp;Then, using the above API client, we can connect to OpenAI, and create our vector database, which looks like the following: 
   
 &amp;nbsp; 
 We use the   `embedding`   column with type TEXT to store the vectors as plain text, however in a production setting we would probably use a BLOB and store the values as 8 byte floating point values. This would greatly increase efficiency, and would also reduce our database size by a factor of 3. However, we can get good performance even with this naive approach. 
 It is worth noting there are other tools available, which can manage vectors natively - but these normally come with a price tag. 
  &amp;nbsp;  
 How Much Does The OpenAI Embeddings API Cost? 
 OpenAI charges&amp;nbsp;$0.0001 per 1K tokens, and 1K tokens are roughly 4k characters of text. To put this in perspective, it would cost just&amp;nbsp; two cents  to get embeddings for a 100 page book. 
 This is also a one-time cost, which does not have to be repeated if the embeddings are stored in a database. If your texts start to get too long,  consider using text rephrasing capabilities . 
 &amp;nbsp; 
 Example Code For Searching Our Vector Database 
 Below is a script, which fetches an embedding for our test text &quot; canine &quot;, and then sorts all of our existing texts based on how close in meaning they are to this text. 
  
&amp;lt;?php
include_once(&#039;OpenAIEmbeddingSimpleClient.php&#039;);

//establish DB connection
$GLOBALS[&#039;db_connection&#039;] = mysqli_connect(&#039;localhost&#039;, &#039;root&#039;, &#039;&#039;, &#039;test&#039;) or die(&quot;db connection error&quot;); 
mysqli_query($GLOBALS[&#039;db_connection&#039;], &quot;SET NAMES &#039;utf8&#039;&quot;);


//&quot;canine&quot; embedding, test text
$openAIEmbedding = OpenAIEmbeddingSimpleClient::embeddings(&#039;canine&#039;);

$compareEmbedding = $openAIEmbedding[&#039;data&#039;][0][&#039;embedding&#039;];
foreach($compareEmbedding as $ind =&amp;gt; $v) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$compareEmbedding[$ind] = doubleval($v);
}


//fetch our stored vector database from MySQL/MariaDB
$res = executeQuery(&#039;select * from vectors;&#039;); 
$list = [];

while($row = fetchArray($res)) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$similarityScore = cosineSimilarity(explode(&#039;,&#039;, $row[&#039;embedding&#039;]), $compareEmbedding);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$list[] = [
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;text&#039; =&amp;gt; $row[&#039;text&#039;],
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#039;score&#039; =&amp;gt; $similarityScore
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;];
}

usort($list, function($a, $b) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return $b[&#039;score&#039;] &amp;lt;=&amp;gt; $a[&#039;score&#039;];
});

print_r($list);
//end of script...


//OpenAI Recommended Algorithm For Comparing Embeddings
function cosineSimilarity($vector1, $vector2) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$dotProduct = 0.0;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$sqSum1 = 0.0;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$sqSum2 = 0.0;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//Performance hack? Stop after 100 comparisons, depending on your data this may be enough
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;foreach($vector1 as $ind =&amp;gt; $d1) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$d1 = doubleval($d1);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$d2 = $vector2[$ind];
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$dotProduct += $d1 * $d2;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$sqSum1 += $d1 * $d1;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$sqSum2 += $d2 * $d2;
&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 $dotProduct / (sqrt($sqSum1) * sqrt($sqSum2));
}

//DB helper functions
function dbError(){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;throw new Exception(&quot;db_error:&quot;.mysqli_error($GLOBALS[&#039;db_connection&#039;]));
}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
function executeQuery($query){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (!is_null($query)) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$resultResource = mysqli_query($GLOBALS[&#039;db_connection&#039;], $query);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (!$resultResource) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;dbError();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&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(stripos($query, &#039;insert&#039;) === 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;return mysqli_insert_id($GLOBALS[&#039;db_connection&#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 $resultResource;
&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;throw new Exception(&quot;query not set&quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
}

function fetchArray($resultResource){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return mysqli_fetch_array($resultResource, MYSQLI_ASSOC);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
}
 
 
 And the following is what the result looks like, if we have a database of 1k existing texts that we want to rank.&amp;nbsp; 
   
 &amp;nbsp; 
 &amp;nbsp; 
 Performance Of Using PHP and MySQL For Vector Databases 
 We did some test benchmarks of the above implementation, and here are the figures: 
 
 For  1,000 vectors  (texts), we are able to rank all of them based on a search query in  0.8 seconds . 
 For  10,000 vectors , the same script runs in  7 seconds . 
 
 &amp;nbsp; 
 It is important to realize, we managed to work with AI vectors, just by using plain vanilla PHP and MySQL.&amp;nbsp; There are other storage systems available now, which have these structures built in -  but these are not necessary to get started . 
 &amp;nbsp; 
 While doing all of this, we discovered a very nice thing! 
 We actually  do not have to compare all 1536 vector values  to still achieve good results!&amp;nbsp;&amp;nbsp; 
 Specifically, just by comparing the first 100 vector values, the ranking did not change, and we were able to process 10k vectors in under 1 second. 
  Pro tip:  to implement this in a performance setting, the comparison function should accept an extra parameter between 0 and 1, stating how much of the vector should be processed. At least from our tests, we found that we do not always have to compare the entire vector. 
 &amp;nbsp; 
 Which Comparison Function Is Best 
 OpenAI recommends to use the  cosine similarity  algorithm, and we also found it to yield the best results. Another algorithm we tried was the  dot product , however we do not recommend it because the performance boost was minimal and the ranking results were considerably worse. 
 In the above code sample, we implemented the cosine similarity function in PHP, and share it with you here. 
 &amp;nbsp; 
 Capabilities Of Vector Embeddings 
 The following are already existing capabilities of using vector embeddings: 
 
  Rank and search  (covered in this tutorial) 
  Grouping and classification  (put similar texts into buckets) 
  Recommendation systems  (show the user top X results) 
  Detect anomalies  (check if a given text or dataset has a completely different semantic meaning) 
  Statistics and distributions  (similar to above, but check if groups of texts fall into normal patterns) 
  Image recognition  (if we transform an image into text first) 
 
 &amp;nbsp; 
 Like with other AI solutions, the challenge still remains for how to collect and format the texts, but this is expected. For example, it may not be worth while to get an embedding for a very long text document, and instead do this on a page-by-page basis, so that when a user does a search, we can forward them to the best matching page within the document. 
 Detecting anomalies is an especially interesting application, and we wonder if it would be possible to separate fake reviews from real ones. This is another major issue in front of many online businesses today. 
 &amp;nbsp; 
 Conclusion 
 Traditional text searching and ranking is based on substrings or keyword search. This has been the dominating methodology for decades, driving all kinds of solutions such as Fuzzy Search, Solr Search and text indexing at the Database level such as MySQL. The biggest challenge of all these systems is, they have a hard time with synonyms and semantic meaning.&amp;nbsp; 
 In the above tutorial we successfully ranked the words &quot;Puppy&quot; and &quot;Dog&quot; as the top results when searching for &quot;Canine&quot;, and we did this by using embedding vectors. The performance is good, and we believe this has the potential to become the next replacement for many search applications.&amp;nbsp; 
 If this tutorial was helpful, then you&#039;ll like the following example, where  we teach an AI to fix email address mistypes . 
 &amp;nbsp; 
                ]]>
            </content>

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

    
    
        <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">ChatGPT Developer Mode</title>
            <id>https://rockin.ai/blog/generative-ai/chatgpt-developer-mode</id>
            <link href="https://rockin.ai/blog/generative-ai/chatgpt-developer-mode"/>
            <summary type="html">
                <![CDATA[
                
                                            ChatGPT is able to produce decent code, but a good developer will still easily beat it even on simple tasks.
                                        ]]>
            </summary>
            <content type="html">
                <![CDATA[
                 Step aside developers, an AI is about to take your spot! Not really, but this is what the news say.&amp;nbsp; 
 First, being developers ourselves, we at rockin.ai love mahcines and artificial intelligence. We love the technology, the breakthroughs and the challenges. One such breakthrough recently was ChatGPT&#039;s ability to write code.&amp;nbsp; 
 We went ahead and did some testing, and will report our findings here.&amp;nbsp; Overall, if we were giving it a grade it would be a C-, which is both disappointing and respectable at the same time. It is respectable because we realize this is only the start, and next versions will no doubt improve! 
 If you are a developer, you should know that  OpenAI has opened up a waitlist for plugin developers . 
 &amp;nbsp; 
 What Is ChatGPT Developer Mode? 
 One of the most hyped capabilities of ChatGPT is its coding skills. Simply asking it to write a piece of code (in any language), will usually result in code being produced. So, enabling developer mode is simply asking  &quot; please write code that solves &amp;lt;insert problem here&amp;gt; &quot; .&amp;nbsp; Let&#039;s have a closer look at the code ChatGPT writes, and see how good it really is. 
 &amp;nbsp; 
 Asking ChatGPT For A Simple Function 
 In the below screenshot, we&#039;re asking ChatGPT to write a function to count all 1s in a binary integer. We have to say it is ironic that we have machine producing human-readable code...&amp;nbsp; 
 While the result actually works, it is also very slow.&amp;nbsp; Maybe this is even the slowest possible implementation.&amp;nbsp; The proposed code from ChatGPT will first convert the integer to a binary string, and then search it for substrings matching &#039;1&#039;. 
   
 &amp;nbsp; 
 Asking ChatGPT For An Optimized Function 
 In an effort to improve the situation, we will ask the same question like before, but ask ChatGPT to optimize the code. We were impressed that ChatGPT immediately realized that using bitwise will make sense.&amp;nbsp; 
 &amp;nbsp; 
   
 &amp;nbsp; 
 &amp;nbsp;&amp;nbsp; 
 Below is the code from ChatGPT so you can also try it out. While it looks like an improvement, ChatGPT forgot that integers can be negative. Also, right-shifting negative numbers in PHP will  not  shift the sign bit, and therefore this becomes an infinite loop! But it was still a nice try.&amp;nbsp; 
  
function countOnes($integer) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//Irony! Machine writing human code.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$count = 0;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;while ($integer) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Increment count if the last bit is a one
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$count += $integer &amp;amp; 1;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Right shift to move to the next bit
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$integer &amp;gt;&amp;gt;= 1;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return $count;
}
 
 
 &amp;nbsp; 
 Writing A Real Solution By Ourselves 
 The real implementation would look more like the one below, where we have to left shift the integer instead (which does shift the sign bit!). Also, we have to remember that some machines have 32 bit integers, and others have 64 bits. The below code is by no means optimal - but at least it is not buggy anymore, and works decently fast. To achieve even faster performance, we can unwrap the loop, and look to hardcode the bitwise operations, probably achieving a near constant runtime - but then the code would barely be readable at all to other developers. 
  
function countOnes($integer) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//Irony! Human writing Machine Code.
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$count = 0;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;while ($integer !== 0) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Increment count if the last bit is a one
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if(($integer &amp;amp; PHP_INT_MIN) !== 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;$count++;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Left shift to move to the next bit
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$integer &amp;lt;&amp;lt;= 1;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return $count;
}
 
 
 &amp;nbsp; 
 Would We Recommend To Use ChatGPT Code In Production? 
 This depends on the context of the application. If the application has to run perfectly, be decently optimized and secure - then most probably not.&amp;nbsp; At best, the AI might be used as a &quot; co-pilot &quot; and not more than just a code suggestion tool. Its results are easily buggy or slow or both. 
 On the other hand, if the application does not need to be perfect or fast - and is a throw-away app anyway, then definitely yes! The solution proposed by ChatGPT at the very top was working just fine for such a use case.&amp;nbsp; 
 We&#039;ll say for sure,  ChatGPT is much better at cleaning data  than writing code! For example, we have a  separate tutorial about creating a fine-tuned model to fix email addresses . 
 &amp;nbsp; 
 How Does ChatGPT Know What Code To Write? 
 ChatGPT is an LLM under the hood, and it writes code just like it writes essays. It will look for common patterns and try recommending the next most probably word or &quot;token&quot;. The model was likely fed millions of StackOverflow pages to process through, and that is how it is able to come up with logical results. That last part is only a theory by the way, as only the OpenAI team knows how the model was actually trained. 
  &amp;nbsp;  
 Conclusion 
 From our tests, we have to say two things: the results of ChatGPT developing code are poor when comparing to even a bad developer.&amp;nbsp; But! The results are also extremely promising and exciting!&amp;nbsp;&amp;nbsp; 
 Just think about it, if this is only the first iteration of the solution, then what will the next years bring? All comments are welcome below.&amp;nbsp; 
 It may interest you to  connect to the ChatGPT API with a simple client , and do some of these tests in code. 
 &amp;nbsp; 
                ]]>
            </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">Google DevFest 2023: Unpacking the AI Revolution in Toronto</title>
            <id>https://rockin.ai/blog/google-devfest-2023-unpacking-the-ai-revolution-in-toronto</id>
            <link href="https://rockin.ai/blog/google-devfest-2023-unpacking-the-ai-revolution-in-toronto"/>
            <summary type="html">
                <![CDATA[
                
                                            Delve into the highlights of Google DevFest 2023 in Toronto, where the tech world converged to explore the disruptive power of AI and the limitless opportunities for innovation in this young field. From practical insights on Large Language Models (LLMs) to discussions on the f...
                                        ]]>
            </summary>
            <content type="html">
                <![CDATA[
                 In the bustling city of Toronto, Google DevFest 2023 unfolded as a gathering of some of the brightest minds in the technology world. The conference brought together an array of prominent speakers, who demonstrated to the crowd with the latest advancements in the world of Artificial Intelligence (AI) and the intricacies of Large Language Models (LLMs). With a primary focus on AI and its implications, DevFest 2023 explored how the technology is reshaping industries and the incredible opportunities it presents for innovation. 
 In case you missed this event, the main tech focus here was AI. Comparing to other conferences, the audience was very engaged and many speakers had trouble leaving the podium because there were so many questions! 
 &amp;nbsp; 
 The AI Invasion: Disrupting the Tech Industry 
 The 2023 Google DevFest in Toronto left no room for doubt – AI is not the future; it&#039;s the present. The conference served as a testament to the pivotal role AI plays in the tech industry&#039;s evolution. It has disrupted traditional business models and redefined how organizations operate. The consensus among the speakers and the audience was that AI is no longer a luxury but a necessity, and large companies are eager to incorporate AI into their core business processes. 
 Actually, what we learned was -  almost all companies are already  actively adding AI tools   to all departments! 
 AI is not just the domain of tech giants anymore. Businesses of all sizes are racing to harness the power of AI for enhanced productivity, efficiency, and customer engagement. From predictive analytics to personalized customer experiences, AI has found applications across industries such as healthcare, finance, retail, and more. The speakers at DevFest emphasized that AI&#039;s reach knows no bounds, and organizations that embrace it are well-positioned for the future. 
 &amp;nbsp; 
 A Field in Its Infancy: Opportunities for Innovation 
 While AI is making significant strides, one interesting message resonated throughout the conference –  the field of AI is still remarkably young . The opportunities for innovation and breakthroughs in AI are virtually limitless. From improving the capabilities of existing AI models to developing entirely new AI-driven solutions, the future is brimming with potential. 
 The technology ecosystem is in constant flux, and AI, at its core, is a dynamic and evolving field. Startups, established companies, and individual developers have the opportunity to make substantial contributions. This was a recurring theme in many of the presentations and discussions. AI pioneers at DevFest made it clear that the future belongs to those who dare to think beyond the boundaries of current AI capabilities. 
 While the speakers agreed that there is plenty of opportunity, they hesitated to make any forecasts. And this is exciting because it means  anyone at all can make the next breakthrough.  
 &amp;nbsp; 
 Key Lessons from DevFest 2023 
  AI is Reshaping Industries:  The tech industry is undergoing a transformation, and AI is at the helm of this revolution. Whether it&#039;s automating tasks, optimizing processes, or providing data-driven insights, AI is integral to the future of businesses. 
  AI&#039;s Youth Presents Opportunity:  The AI field is still in its infancy. Attendees learned that there is ample room for innovation, and the evolving AI landscape invites new entrants to bring fresh ideas and approaches to the table. 
 &amp;nbsp; 
 Exploring LLMs and Prompting 
 LLMs were at the heart of discussions at Google DevFest 2023, particularly regarding their application in a wide range of AI-related tasks. The audience was keenly interested in understanding how these models work and how they could be harnessed for various applications,  including data classification . 
 &amp;nbsp; 
 Tapping LLMs for Classification Problems 
 In one engaging session, the audience got a firsthand look at how Large Language Models can be used to solve classification problems. The process involves designing effective prompts that guide the model to categorize data into predefined classes. This is particularly useful in situations where you need to automate the sorting of vast amounts of information. 
 &amp;nbsp; 
 For example, by crafting a clear and specific prompt like &quot;Classify the sentiment of the following text as &#039;Positive,&#039; &#039;Negative,&#039; or &#039;Neutral,&#039;&quot; the model  can efficiently categorize text data based on the provided instructions . This session underscored the practical applications of LLMs in data classification and how they can revolutionize tasks like sentiment analysis, content tagging, and more. 
 &amp;nbsp; 
 The Near Future of AI 
 One of the most anticipated sessions revolved around the future of AI. Attendees were eager to gain insights into what lies ahead for the field. The speakers emphasized that the pace of AI advancement shows no signs of slowing down. 
 AI in the near future is expected to become more pervasive, integrated into daily life in ways we can scarcely imagine. From autonomous vehicles to medical diagnostics, AI will become deeply ingrained in various sectors. Ethical considerations, regulatory challenges, and data privacy will also be paramount in shaping the future of AI. The speakers encouraged the audience to stay informed and engaged in discussions surrounding AI&#039;s societal impact. 
 &amp;nbsp; 
 Questions from the Inquisitive Audience 
 The audience at Google DevFest 2023 was engaged and curious. Several people shared their experience and pains of building apps around AI. One in particular that stood out, was a student who wrote a document parsing app, but discovered that ChatGPT was sometimes providing details never menioned in those documents! Indeed, it was relying on data it had learned from elsewhere. 
 &amp;nbsp; 
 Some of the most thought-provoking questions that emerged included: 
 &amp;nbsp; 
  &quot;How to Tap LLMs for Classification Problems?&quot;  
 This question reflects a growing interest in the practical applications of LLMs for data classification. The answer lies in writing&amp;nbsp;  precise and instructive prompts  . LLMs have the capacity to learn patterns in data and classify it based on the instructions they receive. Effective prompts guide the model in making accurate classifications, whether it&#039;s sorting text, images, or any other form of data. 
 &amp;nbsp; 
  &quot;What Does the Near Future for AI Look Like?&quot;  
 The future of AI, as discussed at DevFest,  promises to be transformative . It will involve AI solutions that are more adaptable, transparent, and accountable. As AI becomes more integrated into our lives, the ethical and societal implications of these advancements will gain prominence. The future of AI is a complex tapestry, with threads of innovation, regulation, and societal impact interwoven. 
 &amp;nbsp; 
 Conclusion 
 Google DevFest 2023 in Toronto was a testament to the   incredible impact AI is having on the tech industry  . The conference shed light on the necessity of AI adoption for businesses of all sizes and emphasized the immense potential for innovation in this still-emerging field. Attendees left with valuable insights into harnessing LLMs for data classification and a glimpse into the exciting and transformative future that AI promises. As the industry continues to evolve, events like DevFest serve as vital platforms for sharing knowledge and driving innovation. 
                ]]>
            </content>

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

    
    
        <entry>
            <title type="text">The Art of Prompt Engineering</title>
            <id>https://rockin.ai/blog/prompt-engineering/the-art-of-prompt-engineering</id>
            <link href="https://rockin.ai/blog/prompt-engineering/the-art-of-prompt-engineering"/>
            <summary type="html">
                <![CDATA[
                
                                            Discover the art of directing LLMs to perform language translation, text summarization, data classification, and more through real-world examples and insights.
                                        ]]>
            </summary>
            <content type="html">
                <![CDATA[
                 Language models have come a long way in recent years, with Large Language Models (LLMs) like GPT-4 revolutionizing the field of Natural Language Processing (NLP). These models can understand, generate, and manipulate human language in ways that were once considered science fiction. However, harnessing the full potential of LLMs requires more than just feeding them text – it requires effective prompt engineering. 
 In this article, we&#039;ll explore what prompt engineering is in the context of LLMs, how to craft powerful prompts, and the concept of chaining prompts. We will also dive into data classification using prompt engineering with practical examples. 
 &amp;nbsp; 
 What is Prompt Engineering? 
 Prompt engineering is the process of designing or constructing an input query or instruction for a language model to achieve a desired output. LLMs like GPT-4 rely on text-based prompts to generate responses, making prompt engineering a crucial skill to harness their capabilities effectively. 
 In the context of LLMs, prompts can take various forms, including single-sentence questions, multi-step instructions, or even templates. The art of prompt engineering lies in crafting prompts that are clear, concise, and tailored to the specific task you want the model to perform. 
 &amp;nbsp; 
 The Science Behind Prompt Engineering 
 Effective prompt engineering requires a deep understanding of how LLMs function. These models have been trained on vast amounts of text data and aim to predict the most likely next word based on the input they receive. Therefore, the quality of the prompt is essential for eliciting the desired output. 
 To design a good prompt: 
   Be specific:   State your task or question as clearly and precisely as possible. Vague or ambiguous prompts could yield unpredictable results. 
   Use context:   Incorporate relevant context into your prompt. LLMs rely on context to provide accurate responses. For example, if you want to know the capital of France, a prompt like &quot;   What is the capital of the country known for the Eiffel Tower?   &quot; is more effective than &quot;   Capital of France?   &quot; 
   Experiment:   Prompt engineering often involves trial and error. Experiment with different phrasings, wording, or additional context to see what yields the best results. 
   Consider verbosity:   Depending on the model&#039;s capabilities and your specific use case, you might want to specify the level of detail in your prompt. A more verbose prompt might be needed for complex tasks. Adding examples to your prompts goes a long way. 
   Balance context and conciseness:   Striking the right balance between providing adequate context and keeping your prompt concise can be challenging. Be sure to consider both factors for optimal results. 
 &amp;nbsp; 
 Crafting Effective Prompts 
 Let&#039;s delve into some practical examples to understand how to write effective prompts for different tasks: 
 &amp;nbsp; 
 Example 1: Language Translation 
  Task:  Translate the English sentence &quot;The quick brown fox jumps over the lazy dog&quot; into French. 
 &amp;nbsp; 
  Ineffective Prompt:   Translate the sentence about a fox and lazy dog into French.    
  Effective Prompt:   Translate the following English sentence into French: &#039;The quick brown fox jumps over the lazy dog.&#039;    
 In the effective prompt, you provide the model with the specific task and the sentence to be translated. This minimizes ambiguity and ensures that the model knows precisely what is expected. 
 &amp;nbsp; 
 Example 2: Text Summarization 
  Task:  Summarize the following article on climate change in 100 words. 
 &amp;nbsp; 
  Ineffective Prompt:   Summarize the article about climate change.    
  Effective Prompt:   Summarize the following article on climate change in 100 words: [Provide the article text here].    
 By including the article text in the prompt, you provide the model with context, making it clear which content should be summarized and the desired length of the summary. We have a separate  article devoted to the topic of rephrasing texts . 
 &amp;nbsp; 
 Example 3: Data Classification 
 Data classification is a common application of prompt engineering. You can use prompts to classify text, images, or other data into predefined categories. For example, you could use a prompt like: 
  Task:  Classify the following text as &quot;Positive,&quot; &quot;Negative,&quot; or &quot;Neutral.&quot; 
  Prompt:   Classify the sentiment of the following text: &#039;I love the product. It&#039;s amazing.&#039;    
 In this case, the prompt instructs the model to categorize the sentiment of the given text into one of the three specified categories. 
 &amp;nbsp; 
 Chaining Prompts for Complex Tasks 
 Chaining prompts is a powerful technique that involves using a sequence of prompts to perform a more complex task. This approach is particularly useful when you need the model to follow a series of steps or answer multiple questions. 
 &amp;nbsp; 
 Example: Writing a Sales Report 
  Task:  Generate a sales report based on the following data. 
 &amp;nbsp; 
  Chained Prompts:  
 1)    Create a sales report for Q3 2023 based on the following data: [Provide the data].    
 2)    Include a breakdown of sales by region and product category.    
 3)    Generate a summary of the key findings and trends.    
 In this example, each prompt builds on the previous one, creating a multi-step instruction that guides the model to perform a complex task. 
 &amp;nbsp; 
 Data Classification with Prompt Engineering 
 Data classification is a common application of prompt engineering, particularly in scenarios where you need to  categorize information or make decisions based on data . Let&#039;s look at an example of using prompt engineering for text classification. 
 &amp;nbsp; 
 Example: Sentiment Analysis 
  Task:  Classify a set of customer reviews as &quot;Positive&quot; or &quot;Negative.&quot; 
 &amp;nbsp; 
  Chained Prompts:  
 1)    Classify the sentiment of the following customer reviews as &#039;Positive&#039; or &#039;Negative&#039;:    
 2)    Review 1: &#039;This product is fantastic; I love it!&#039;    
 3)    Review 2: &#039;Terrible experience with this product; I regret the purchase.&#039;    
 4)    Review 3: &#039;It&#039;s okay, but not great.&#039;    
 By chaining prompts, you can efficiently classify multiple pieces of text as either positive or negative sentiment. The model processes each review based on the instructions provided and assigns the appropriate label. 
 &amp;nbsp; 
 Conclusion 
 Prompt engineering is an essential skill for effectively utilizing Large Language Models like GPT-4. Understanding the inner workings of these models and crafting clear, context-rich prompts is key to obtaining the desired output. Whether you&#039;re translating languages, summarizing text, or performing data classification, the art of prompt engineering can unlock the potential of LLMs, making them valuable tools across a wide range of applications. By experimenting, iterating, and perfecting your prompts, you can harness the full power of these remarkable language models.&amp;nbsp; 
 When you are ready to start coding, have a look at our  tutorial on connecting to the GPT-4 API . 
                ]]>
            </content>

                            <updated>2023-10-22T00: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">ChatGPT Data Analysis and Cleanup Examples</title>
            <id>https://rockin.ai/blog/generative-ai/chatgpt-data-analysis-and-cleanup-examples</id>
            <link href="https://rockin.ai/blog/generative-ai/chatgpt-data-analysis-and-cleanup-examples"/>
            <summary type="html">
                <![CDATA[
                
                                            In this guide, we&#039;ll explore how to harness the power of ChatGPT for basic data tasks. After seeing some of the examples, it&#039;s no wonder the whole world is changing.
                                        ]]>
            </summary>
            <content type="html">
                <![CDATA[
                 In this guide, we&#039;ll explore how to harness the power of ChatGPT for data analysis tasks. ChatGPT is a versatile AI model that can assist in a wide range of natural language processing tasks, including text classification, analysis and more. We&#039;ll walk you through the process, step by step, and provide practical examples along the way. 
 &amp;nbsp; 
 Data Analysis 
 Data analysis is both difficult and time consuming. This is especially true in a business environment, where things can often move very slowly. 
 Most probably, the actual job of data analysis isn&#039;t going anywhere soon. LLMs and ChatGPT are great new tools that can be used really by anyone. Below is a screenshot of what&#039;s possible in the free version of ChatGPT today. Please note that in the newer versions of  GPT-4 and up, it is possible to upload PDF files and even Excel . 
   
 &amp;nbsp; 
 What is Data Analysis? 
 Data analysis is the systematic process of examining, cleaning, interpreting, and modeling data to uncover meaningful insights and inform decision-making. It involves collecting, processing, and visualizing data to extract valuable information and patterns, making it a cornerstone of informed actions and discoveries. 
 &amp;nbsp; 
 How to do Data Analysis in ChatGPT? 
 Using the free version of ChatGPT, the data can simply be pasted into the prompt, and questions can be asked.&amp;nbsp; The prompt format goes as follows: 
 
 Provide context for the data - what is it about? 
 Provide the data itself, in the cleanest possible way so ChatGPT can parse it. 
 Ask questions about the data. 
 
 &amp;nbsp; 
 Example Data Analysis Prompt in ChatGPT? 
 Please see the sample prompt below as an example for a data analysis request for ChatGPT: 
   
We are given the following data table of sales during the past 7 days:
weekday, product sold, customer city, sale price
Sunday, Widget1, New York, $100
Sunday, Widget1, San Francisco, $100
Monday, Widget1, New York, $100
Monday, Widget1, San Francisco, $100
Tuesday, Widget1, New York, $100
Tuesday, Widget1, San Francisco, $100
Wednesday, Widget2, New York, $200
Wednesday, Widget1, New York, $100
Wednesday, Widget1, San Francisco, $100
Thursday, Widget1, New York, $100
Friday, Widget2, New York, $200
Saturday, Widget1, New York, $100
Saturday, Widget2, New York, $200

 Which products have the highest demand? 

&amp;nbsp;
&amp;nbsp;
&amp;gt; Based on the provided sales data, it appears that Widget1 and Widget2 are the products being sold. To determine which product has the highest demand, we can analyze the frequency of each product sold:

Widget1 was sold on Sunday, Monday, Tuesday, Wednesday, Thursday, and Saturday.
Widget2 was sold on Wednesday and Friday.
From this analysis,  Widget1 appears to have the highest demand  since it was sold on more days compared to Widget2.
 
 
 &amp;nbsp; 
 Data Cleanup 
 Clean and complete data is a major problem in the &quot;real world&quot;.    Here is a typical scenario:  business might ask their marketing department to create a landing page with a registration of some sort (maybe for a raffle or giveaway). Marketing in turn might copy an existing template, change some content and push it out to their leads. Not too much thought is placed on the data collected, because...  deadline . 
 And some data gets collected over the following weeks... 
 Eventually this new list of customers needs to be used, with all the flawed data that was collected. What could some of these flaws possibly be, you ask? 
 
 People mistyped their information 
 Project scope changed a bit, now you need more data 
 Some obvious data was just missed 
 
 &amp;nbsp; 
 Now, we have a &quot;dirty&quot; set of data, which could take a lot of time and effort to clean up or expand, and this is a real world problem where someone has to manually make adjustments. 
 Please see the screenshot below, of how you can take a simple line of data and actually Generate additional data for it: 
   
 &amp;nbsp; 
 Using ChatGPT to generate user data? 
 Obviously, there are limits to how much data can be generated. For example there&#039;s no way to generate someone&#039;s birthday just using their name and address (or is there...?). 
 However, generating basic knowledge about a customer, by infering from already known information is work wonders if that&#039;s all you need!&amp;nbsp; 
 &amp;nbsp; 
 Correcting User Inputs with ChatGPT 
 We have done a lot of tests on ChatGPT to clean up lists of data.&amp;nbsp; By clean up, we want it to be fixed up for obvious mistypes or misspellings.&amp;nbsp; The results are just stunning, and resemble what a person my do manually! 
 Below is a screenshot, of how ChatGPT can  automatically correct email addresses . Notice how the results is actually very good, given simple prompt to clean the email list. Now, imagine  building an API connection to ChatGPT , and sending all emails to be processed like this! 
   
 &amp;nbsp; 
 Generating New User Data with ChatGPT 
 ChatGPT makes it possible to generate new content based on publicly known information and some current starting point to expand on. In the example below, we request additional address details based on an incomplete address provided by the user: 
    
What is the zip code, telephone area code, country ISO code, for the following address:  &quot;1600 Amphitheatre Parkway in Mountain View, California&quot;?   &amp;gt;  &amp;gt;The information for the address &quot;1600 Amphitheatre Parkway, Mountain View, California&quot; is as follows:
ZIP Code:  94043 
Telephone Area Code:  650 
Country ISO Code:  US  (United States)
 
 
 &amp;nbsp; 
 Conclusion 
 LLMs and ChatGPT in particular have now proven themselves to be capable of many tasks, which would be very time consuming for a mere human to accomplish.  Tapping into these new tools and capabilities deserves a good look, especially now in a world where productivity is paramount. With the above article and provided examples, you should be on a good way to improve your data today. 
 We hope the above tips were helpful, and here are  some more tips on designing good prompts . 
                ]]>
            </content>

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

    
    
        <entry>
            <title type="text">Generative AI vs. Predictive AI: The Distinction</title>
            <id>https://rockin.ai/blog/generative-ai/generative-ai-vs.-predictive-ai-the-distinction</id>
            <link href="https://rockin.ai/blog/generative-ai/generative-ai-vs.-predictive-ai-the-distinction"/>
            <summary type="html">
                <![CDATA[
                
                                            Explore the fascinating world of AI through the lens of generative AI and predictive AI in this in-depth article. Uncover the definitions of these AI branches, their real-world applications in content creation, predictive analytics, and more, and witness how businesses across ...
                                        ]]>
            </summary>
            <content type="html">
                <![CDATA[
                 The world of artificial intelligence (AI) is teeming with innovation, and two prominent branches,  generative AI  and  predictive AI , stand out with unique capabilities and applications. While both fields contribute to the advancement of AI, they serve distinct purposes and offer different real-world solutions in various industries. In this article, we&#039;ll delve into the definitions of generative and predictive AI, provide real-world examples to illustrate their practical applications, and emphasize the growing significance of these technologies in the business world. 
 &amp;nbsp; 
 Generative AI: Creating from Imagination 
 Generative AI is a fascinating realm of artificial intelligence that revolves around the  creation of new, original content , often by extrapolating from existing data or generating entirely new and unique creations. It is a technology that empowers machines to generate content, whether it be text, images, videos, music, or even entire scenes and landscapes. 
 &amp;nbsp; 
 Definition of Generative AI 
 Generative AI can be defined as a subset of artificial intelligence that focuses on creating content, whether it&#039;s text, images, or other forms of media, often by utilizing existing data patterns and learning to generate content that appears to have been created by humans. 
 Generative AI models are powered by deep learning techniques, particularly variants of neural networks such as Generative Adversarial Networks (GANs) and Transformers. These models learn from vast datasets and generate content by combining, adapting, or even creating data patterns themselves. As an example of transformers in real development,  vector embeddings  are often used to give better search results. 
 &amp;nbsp; 
 Real-World Examples of Generative AI 
  Text-to-Image Generation:  One remarkable application of generative AI is in generating images from text descriptions. For instance, given a textual description like &quot;a serene beach at sunset with palm trees and crashing waves,&quot; generative AI models can produce a corresponding image that aligns with this description. 
  Text-to-Video Generation:  Generative AI can also create videos from  textual prompts . It can turn a written narrative into a visual representation by learning from a dataset of video sequences and applying patterns to construct a coherent video. 
  Artistic Creations:  Generative AI has also made waves in the art world. AI tools like DALL-E have generated artwork based on textual prompts, demonstrating how machines can create art from scratch.  We&#039;re giving away a DALL-E API client &amp;nbsp;to anyone who wants to try this. 
 Generative AI&#039;s remarkable capabilities have found applications in creative fields, content generation, and even in generating realistic synthetic data for various purposes. 
 &amp;nbsp; 
 Predictive AI: Forecasting and Guiding Decisions 
 Predictive AI, on the other hand, is a branch of AI that focuses on  analyzing historical data and patterns to predict future events or outcomes . This technology excels at making informed forecasts and aiding in decision-making processes, often with the aim of improving efficiency, reducing risks, and enhancing customer experiences.&amp;nbsp; 
 &amp;nbsp; 
  Predictive AI concepts are actually used by generative AI, when for example generating an image down at the pixel level, these colors are &quot;predicted&quot; to what will most likely come next. The key differentiation with generative AI is, an entirely new subject is created as the main result.  
 &amp;nbsp; 
 Definition of Predictive AI 
 Predictive AI can be succinctly defined as the application of machine learning and statistical techniques to analyze historical data, identify patterns and trends, and make predictions about future events or outcomes. This technology is widely used in various industries, from finance to marketing and healthcare. 
 Predictive AI employs techniques like regression analysis, time series forecasting, and machine learning algorithms to draw insights from data and provide actionable predictions. These predictions are invaluable for businesses aiming to optimize their operations and anticipate future trends. 
 &amp;nbsp; 
 Real-World Examples of Predictive AI 
  Social Media Click Predictions:  Social media platforms employ predictive AI to anticipate user behavior. By analyzing past interactions and content preferences, they can predict the likelihood of users clicking on specific posts or advertisements. This enables them to optimize content placement and improve user engagement. 
  Fraud Detection in Payment Processing:  Payment processors use predictive AI to detect fraudulent transactions. By analyzing transaction patterns and historical data, they can identify potentially suspicious activities in real-time, preventing financial losses and protecting customers. 
  Product Recommendations in E-commerce:  Shopping websites employ predictive AI to offer personalized product recommendations. By analyzing a user&#039;s past purchases, browsing history, and preferences, these platforms can suggest items that are most likely to pique the user&#039;s interest, increasing sales and enhancing user satisfaction. 
 Predictive AI provides businesses with the means to make data-driven decisions, reduce risks, and enhance customer experiences. It&#039;s a powerful tool that&#039;s being widely adopted in various industries. 
 &amp;nbsp; 
 The Widening Applications of AI 
 Both generative and predictive AI have found their way into countless industries,  transforming the way businesses operate and interact with their customers . The practical applications of these technologies continue to grow, underscoring their importance in the modern world. 
 &amp;nbsp; 
 Generative AI Applications 
 Generative AI&#039;s applications are expanding rapidly, and here are some of the key domains where it is already making a significant impact: 
  Content Creation  
 Generative AI is being used in  content creation and cleanup , automating the generation of written articles, reports, and product descriptions. 
  Image and Video Production  
 In the creative industry, it&#039;s being used to create visual content, such as art, graphics, and video animations. 
  Synthetic Data Generation  
 Generative AI is instrumental in creating synthetic datasets for training machine learning models, enabling data scientists to work with more extensive and diverse data. 
  Programming Code  
  ChatGPT is already capable of writing code , which happens to be another form of generative AI. 
 &amp;nbsp; 
 Predictive AI Applications 
 Predictive AI, too, is making waves across various industries. Here are some applications that highlight its growing significance: 
  Financial Services  
 In finance, predictive AI is utilized for risk assessment, fraud detection, and investment portfolio optimization. 
  Healthcare  
 Predictive AI is used in healthcare for patient diagnosis, treatment planning, and predicting disease outbreaks. 
  Marketing and Advertising  
 It helps businesses personalize marketing strategies, optimize ad targeting, and predict consumer trends. 
  Supply Chain Management  
 Predictive AI assists in forecasting demand, optimizing inventory management, and reducing supply chain inefficiencies. 
  Energy Management  
 In the energy sector, predictive AI is employed to optimize power generation, reduce energy consumption, and enhance grid stability. 
 As both generative and predictive AI technologies mature, their applications will continue to diversify, providing innovative solutions in sectors ranging from healthcare and finance to entertainment and transportation. 
 &amp;nbsp; 
 The Path Forward 
 In conclusion, generative and predictive AI represent two distinct yet complementary facets of the AI landscape. Generative AI offers the power to create content and images from imagination, enabling entirely new creative possibilities. Predictive AI, on the other hand, helps us forecast and make data-driven decisions, making it a valuable tool for optimizing business processes and customer experiences. 
 The adoption of these technologies is growing across various industries, and their significance is only poised to increase in the coming years. As businesses continue to leverage AI for content generation, prediction, and data-driven decision-making, the lines between generative and predictive AI may blur, leading to exciting and innovative applications that benefit us all. The journey of AI is still unfolding, and its potential is boundless. As these technologies advance, they will undoubtedly shape the future of industries, making them more efficient, creative, and productive. 
                ]]>
            </content>

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

    
</feed>
