DEV Community

Cover image for How to fix error `operation aborted by callback` with OpenAI PHP SDK
Kirill
Kirill

Posted on • Edited on

How to fix error `operation aborted by callback` with OpenAI PHP SDK

During uploading a file to OpenAI API you can receive an error:

Fatal error: Uncaught Exception: operation aborted by callback in /var/www/html/vendor/orhanerday/open-ai/src/OpenAi.php on line 962
Enter fullscreen mode Exit fullscreen mode

Here is my code which produces this error:

require 'vendor/autoload.php';
use Orhanerday\OpenAi\OpenAi;
$openAi = new OpenAi($_SERVER['OPEN_AI_KEY']);
$pricesFile = curl_file_create(__DIR__ . '/../data/file.json');
$file = $openAi->uploadFile([
    'file' => $pricesFile,
    'purpose' => 'assistants',
]);
Enter fullscreen mode Exit fullscreen mode

Solution

The problem is that I didn't have the file on the provided path: __DIR__ . '/../data/file.json. You need to check and fix the path and then run your script again.

Follow me on X (prev Twitter)

Top comments (1)

Collapse
 
ripon52 profile image
Ripon Uddin
{"text": "What is Laravel?", "label": "Laravel is a free, open-source PHP web framework used for web application development."}
{"text": "How do you install Laravel?", "label": "Laravel can be installed using Composer. Run `composer create-project --prefer-dist laravel/laravel project-name`."}
{"text": "What is Eloquent ORM?", "label": "Eloquent is Laravel's built-in ORM (Object-Relational Mapping) for working with databases using an elegant syntax."}
{"text": "Explain Laravel Blade templates.", "label": "Blade is the templating engine in Laravel. It provides a clean, concise syntax for writing templates with features like template inheritance and control structures."}

Enter fullscreen mode Exit fullscreen mode

isn't this valid jsonl file content?
Because i am getting errors