I’m trying to upload a pdf file in order to ask chatgpt if the file contain a specific word.
To upload the file I’m using this code
$api_upload = 'https://api.openai.com/v1/files';
$pdfFile = 'myfile.pdf';
$ch = curl_init($api_upload);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $api_key));
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'purpose' => 'assistants',
'file' => new CURLFile($pdfFile, 'application/pdf'),
));
I get a valid uploaded file
and the status is proceeded.
To ask the question, I’m using this code
api_url = 'https://api.openai.com/v1/chat/completions';
$model = 'gpt-3.5-turbo';
$fileID // <- profide by previous call
$data = array(
'model' => $model,
'messages' => array(
array('role' => 'system', 'content' => 'Vous êtes un assistant'),
array(
'role' => 'user',
'content' => "Does this file contains the word: Hello",
'file_ids' => [$fileID]
))
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Authorization: Bearer ' . $api_key
));
But the chapgpt response is always, that I do not had provide a file to analyze (or something like this).
Can anybody help me.
I have more than 1000 file to parse and analyze
Thank’s
Etienne