openai-php / client

⚡️ OpenAI PHP is a supercharged community-maintained PHP API client that allows you to interact with OpenAI API.
MIT License
4.57k stars 466 forks source link

[Bug]: error OpenAI\Exceptions\UnserializableResponse #281

Closed TitorovD closed 7 months ago

TitorovD commented 7 months ago

Description

When accessing the Openal API, my service returns an error exeption: "OpenAI\Exceptions\UnserializableResponse" file /vendor/openai-php/client/src/Transporters/HttpTransporter.php line 62

I use a paid account model gpt-3.5-turbo-instruct

The error appeared three weeks ago, locally in the development environment it "flickering" appears from time to time The error always appears on the server I will be grateful for your help. What needs to be done?

Steps To Reproduce

$response = $client->completions()->create([ 'model' => 'gpt-3.5-turbo-instruct', 'prompt' => $request_ai, 'max_tokens' => 500, 'temperature' => 0 ]);

OpenAI PHP Client Version

0.4.1

PHP Version

8.1.2

Notes

No response

TitorovD commented 7 months ago

updated the Openal Client version 0.8.0 But the error remained

gehrisandro commented 7 months ago

Hi @TitorovD

Can you please send an updated stacktrace from the current version?

And if possible, the prompt you are using or the raw http response content?

TitorovD commented 7 months ago
{
    "message": "Syntax error",
    "exception": "OpenAI\\Exceptions\\UnserializableResponse",
    "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/openai-php/client/src/Transporters/HttpTransporter.php",
    "line": 63,
    "trace": [
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/openai-php/client/src/Resources/Completions.php",
            "line": 33,
            "function": "requestObject",
            "class": "OpenAI\\Transporters\\HttpTransporter",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/app/Http/Controllers/staff/StaffAjaxController.php",
            "line": 342,
            "function": "create",
            "class": "OpenAI\\Resources\\Completions",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/app/Http/Controllers/staff/StaffAjaxController.php",
            "line": 59,
            "function": "report_ai",
            "class": "App\\Http\\Controllers\\staff\\StaffAjaxController",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/laravel/framework/src/Illuminate/Routing/Controller.php",
            "line": 54,
            "function": "router",
            "class": "App\\Http\\Controllers\\staff\\StaffAjaxController",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php",
            "line": 43,
            "function": "callAction",
            "class": "Illuminate\\Routing\\Controller",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/laravel/framework/src/Illuminate/Routing/Route.php",
            "line": 260,
            "function": "dispatch",
            "class": "Illuminate\\Routing\\ControllerDispatcher",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/laravel/framework/src/Illuminate/Routing/Route.php",
            "line": 205,
            "function": "runController",
            "class": "Illuminate\\Routing\\Route",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 798,
            "function": "run",
            "class": "Illuminate\\Routing\\Route",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 141,
            "function": "Illuminate\\Routing\\{closure}",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/app/Http/Middleware/NucleusUser.php",
            "line": 38,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 180,
            "function": "handle",
            "class": "App\\Http\\Middleware\\NucleusUser",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php",
            "line": 50,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 180,
            "function": "handle",
            "class": "Illuminate\\Routing\\Middleware\\SubstituteBindings",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php",
            "line": 78,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 180,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php",
            "line": 49,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 180,
            "function": "handle",
            "class": "Illuminate\\View\\Middleware\\ShareErrorsFromSession",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php",
            "line": 121,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php",
            "line": 64,
            "function": "handleStatefulRequest",
            "class": "Illuminate\\Session\\Middleware\\StartSession",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 180,
            "function": "handle",
            "class": "Illuminate\\Session\\Middleware\\StartSession",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php",
            "line": 37,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 180,
            "function": "handle",
            "class": "Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php",
            "line": 67,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 180,
            "function": "handle",
            "class": "Illuminate\\Cookie\\Middleware\\EncryptCookies",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 116,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 799,
            "function": "then",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 776,
            "function": "runRouteWithinStack",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 740,
            "function": "runRoute",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/laravel/framework/src/Illuminate/Routing/Router.php",
            "line": 729,
            "function": "dispatchToRoute",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
            "line": 190,
            "function": "dispatch",
            "class": "Illuminate\\Routing\\Router",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 141,
            "function": "Illuminate\\Foundation\\Http\\{closure}",
            "class": "Illuminate\\Foundation\\Http\\Kernel",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/barryvdh/laravel-debugbar/src/Middleware/InjectDebugbar.php",
            "line": 66,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 180,
            "function": "handle",
            "class": "Barryvdh\\Debugbar\\Middleware\\InjectDebugbar",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php",
            "line": 21,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php",
            "line": 31,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 180,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\ConvertEmptyStringsToNull",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php",
            "line": 21,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php",
            "line": 40,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 180,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\TrimStrings",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php",
            "line": 27,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 180,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php",
            "line": 86,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 180,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Middleware\\PreventRequestsDuringMaintenance",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/laravel/framework/src/Illuminate/Http/Middleware/HandleCors.php",
            "line": 49,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 180,
            "function": "handle",
            "class": "Illuminate\\Http\\Middleware\\HandleCors",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/fideloper/proxy/src/TrustProxies.php",
            "line": 57,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 180,
            "function": "handle",
            "class": "Fideloper\\Proxy\\TrustProxies",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
            "line": 116,
            "function": "Illuminate\\Pipeline\\{closure}",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
            "line": 165,
            "function": "then",
            "class": "Illuminate\\Pipeline\\Pipeline",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php",
            "line": 134,
            "function": "sendRequestThroughRouter",
            "class": "Illuminate\\Foundation\\Http\\Kernel",
            "type": "->"
        },
        {
            "file": "/var/www/www-root/data/www/demo.mojo.education/public/index.php",
            "line": 52,
            "function": "handle",
            "class": "Illuminate\\Foundation\\Http\\Kernel",
            "type": "->"
        }
    ]
}
TitorovD commented 7 months ago

standard test promt

$response = $client->completions()->create([
                'model' => 'gpt-3.5-turbo-instruct',
                'prompt' => 'Say this is a test',
                'max_tokens' => 6,
                'temperature' => 0
            ]);
gehrisandro commented 7 months ago

This is strange. If I execute exactly the same request, it works fine.

Could you please send the body of the response? To do so, you can add dd($contents); on line 60 of the HttpTransporter.

TitorovD commented 7 months ago

I took your advice, added dd($contents); Judging by what the server returns, this is a problem with Cloudflare, which we use for additional protection of our service. I don't know yet what rule needs to be set in Cloudflare for Openair to start working

Снимок экрана 2023-11-30 в 13 05 31
TitorovD commented 7 months ago

The administrator wrote to me that api.openai.com cloudflare is also protected and for some reason blocks requests from your client. How can this be fixed?

gehrisandro commented 7 months ago

Hi @TitorovD

Thanks for clarification.

I don't think, this is related to our client. Looking into the OpenAI forum I found this thread: https://community.openai.com/t/api-access-failed-showing-cloudflare-block-page/506015/37

Didn't read it, but you may find a solution for your problem there.

If there is anything we can improve in our client to mitigate this issue, please let me know. But as I said before, I don't think that there is anything we can do from our side.