Hello T_ray,
Sorry I forgot about the “new CURLFile” part, glad you solved it by yourself.
Anyway, since I did not find this anywhere, I will leave my full code here for: file uploading, retreving fine tune id, fine-tuning and making a completion with your trained model. Hope it helps the few id!ots like me who still need to use PHP for this:
Step 1: Uploading a fine-tune file (given that you already have a formated jsonl file):
$headers = array();
$headers[] = "Content-Type: multipart/form-data";
$headers[] = "Authorization: Bearer **YOUR_KEY**";
$c_file = new CurlFile("file.jsonl", 'application/json', "file.jsonl"); // file must be in the same directory
$post_fields = array('purpose' => 'fine-tune', 'file' => $c_file);
$ch = curl_init();
$curl_info = [ // some of this options are probably not needed
CURLOPT_URL => "https://api.openai.com/v1/files",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $post_fields,
CURLOPT_HTTPHEADER => $headers,
];
curl_setopt_array($ch, $curl_info);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
echo $result; // you will find the file id here, which should look like this: file-g4mXvDisehjEKLSNKiUSDnBQAy
Step 2: Fine-tune a model with that file
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.openai.com/v1/fine-tunes");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, '{
"model": "davinci",
"training_file": "file-g4mXvDisehjEKLSNKiUSDnBQAy"
}');
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array();
$headers[] = "Content-Type: application/json";
$headers[] = "Authorization: Bearer **YOUR_KEY**";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
echo $result; // you will find the fine-tune id here, which should look like this: ft-OQeSiun18gzOSKE5sRVtYA7T
Next steps in the following reply…