(PHP) File upload for fine tuning not working [Solved, with tutorial]

Finally, I have managed to do it like this

$headers = array();
$headers[] = "Content-Type: multipart/form-data";
$headers[] = "Authorization: Bearer sk...";

$cf = new CURLFile("trainingdata.jsonl");
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://api.openai.com/v1/files");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, ["purpose" => "fine-tune" ,"file" => $cf]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
curl_close($ch);

I hope this helps someone!

3 Likes