openai-php / laravel

⚡️ OpenAI PHP for Laravel is a supercharged PHP API client that allows you to interact with OpenAI API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error when use Assistant with stream

jsinoti opened this issue · comments

When I define to use the OpenAI::threads()->createAndRun with stream true, I'm getting a error with de result parse.

`OpenAI\Exceptions\UnserializableResponse {#1453 ▼ // app/Helper/OpenIAHelper.php:43
#message: "Syntax error"
#code: 0
#file: "
/xxxxxxx/vendor/openai-php/client/src/Transporters/HttpTransporter.php"
#line: 63
-previous: JsonException {#1416 ▼
#message: "Syntax error"
#code: 4
#file: "
/xxxxxxx/vendor/openai-php/client/
src/Transporters/HttpTransporter.php"
#line: 61
trace: {▼

/xxxxxxx/vendor/openai-php/client/
src/Transporters/HttpTransporter.php:61 {▼
OpenAI\Transporters\HttpTransporter->requestObject(Payload $payload): Response …
› /** @var array{error?: array{message: string, type: string, code: string}} $data */
› $data = json_decode($contents, true, flags: JSON_THROW_ON_ERROR);
› } catch (JsonException $jsonException) {
arguments: {▼
$json: """
event: thread.created
data: {"id":"thread_rICWuyxxxxxxxxxxaj","object":"thread","created_at":1712078109,"metadata":{}}
....
`

This is because assistant V2 must be used. The library needs to be updated to pass v2 here:
->withHttpHeader('OpenAI-Beta', 'assistants=v2')

Stream support has been added (no need for API v2).

https://github.com/openai-php/laravel/releases/tag/v0.9.0