I’m trying to upload a PDF file with chatPGT API and ask it if the file contain a specific word but It seems to not see that a gave it a file.
To upload the file, I used this code
$pdfFile contains a correct path to the pdf file.
ch = curl_init(https://api.openai.com/v1/files);
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),
));
$response_upload = curl_exec($ch);
$info_upload = curl_getinfo($ch);
curl_close($ch);
response contain a valid id : for example file-lbNMtTgJHW01QZxRZXarx2Ve
I tried to ask my question
$file_id = 'file-lbNMtTgJHW01QZxRZXarx2Ve';
$data = array(
'model' => $model,
'messages' => array(
array('role' => 'system', 'content' => 'Vous êtes un assistant'),
array(
'role' => 'user',
'content' => 'Does this PDF file contain the word XXXX',
'file_ids' => [$file_id]
))
);
$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
));
And the reply is something like
For me to help you determine if a file contains the expressed word you must provide the contents of the file or a file
Has anyone ever asked ChatGPT to analyze the content of a PDF file?
I specify that if I use chapGPT online, it works very well
Thank’s
WebShaker is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1