openai-php / laravel

⚡️ OpenAI PHP for Laravel is a supercharged PHP API client that allows you to interact with OpenAI API
MIT License
2.75k stars 185 forks source link

Error when use Assistant with stream #92

Closed jsinoti closed 5 months ago

jsinoti commented 7 months ago

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":{}} ....
`

devgeek27 commented 6 months ago

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

gehrisandro commented 5 months ago

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

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