Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[improvement]: No support for assistant version v2 #381

Closed
ks-dipeshc opened this issue Apr 24, 2024 · 30 comments
Closed

[improvement]: No support for assistant version v2 #381

ks-dipeshc opened this issue Apr 24, 2024 · 30 comments
Labels
bug Something isn't working

Comments

@ks-dipeshc
Copy link

Description

Hello,

Current library only support the lagacy (v1) version for assistant, threads, and messages.
So we can not used the latest supported request payload mention in open-ai documentation.

Thank you.

Steps To Reproduce

Can not use tool_resources field of the create thread api. click here

OpenAI PHP Client Version

latest

PHP Version

8.1.20

Notes

No response

@ks-dipeshc ks-dipeshc added the bug Something isn't working label Apr 24, 2024
@ks-dipeshc ks-dipeshc changed the title [improovement]: No support for assistant version v2 [improvement]: No support for assistant version v2 Apr 24, 2024
@gehrisandro
Copy link
Collaborator

Going to add support for v2 asap.

@jhull
Copy link

jhull commented Apr 25, 2024

Can you also make sure to add 'attachments' to create messages endpoints? 🙏

@fangyuan0306
Copy link

Please hurry, I found some issues with v1

@Jamz1Santos
Copy link

On line 18 of ](https://github.com/openai-php/client/blob/main/src/OpenAI.php line 18:

->withHttpHeader('OpenAI-Beta', 'assistants=v1') to ->withHttpHeader('OpenAI-Beta', 'assistants=v2')

Just a quick fix and my code runs. but there still need to fix migration issues.

@ircykk
Copy link

ircykk commented May 6, 2024

You can create client manually with beta header:

$client = OpenAI::factory()
    ->withApiKey($apiKey)
    ->withOrganization($organization)
    ->withHttpHeader('OpenAI-Beta', 'assistants=v2')
    ->make();

but it won't help because the class doesn't match the request/response

@subet
Copy link

subet commented May 7, 2024

@gehrisandro, we are looking forward to its completion :D Is there any platform where we can buy you a coffee?

@wishborn
Copy link

wishborn commented May 7, 2024

Do we have any kind of ETA on when these changes might be getting implemented? I'm in the middle of a big upgrade of our AI code and want to utilize this asap. I second @subet request too.

@nunomaduro
Copy link
Contributor

Folks; be sure to sponsor Sandro's work here: gehrisandro.

@nunomaduro nunomaduro reopened this May 8, 2024
@subet
Copy link

subet commented May 8, 2024

Thanks @nunomaduro ! We will...

@ehsanwwe
Copy link

ehsanwwe commented May 14, 2024

when i migrate to V2 by below way
->withHttpHeader('OpenAI-Beta', 'assistants=v2')

i'll get this error in each of request by Assistant
Undefined array key "file_ids"

at this code
$responseCharacters = OpenAI::threads()->createAndRun( [ 'assistant_id' => 'asst_oths*****************', 'thread' => [ 'messages' => [ [ 'role' => 'user', 'content' => "read below screenplay text carefully and return a list each of character in there is in the below screenplay in english language with this column names : Name, gender , age , description , ID in JSON format ".$request->input('screenplay_text'), ], [ 'role' => 'user', 'content' => "append all location with ID ,Time_of_date , is_exterior ,atmosphere_mood , atmosphere_visuals , description to above JSON" ], [ 'role' => 'user', 'content' => "append sequence with ID , charachters IDs (available in sequence) , location ID to above JSON" ], [ 'role' => 'user', 'content' => "append sequence_action for characters in each of sequence with id ,character_id ,dialog ,is_walking ,is_talking, is_stand ,is_ride_a_hors ,is_armed ,is_bow_active ,is_bow_hold ,is_angry ,is_normal ,is_happy ,is_friendly ,is_enemy ,start_positon_in_x_y_z (estimate it) ,end_positon_in_x_y_z (estimate it) ,start_rotation_in_x_y_z (estimate it) ,end_rotation_in_x_y_z (estimate it) ,head_look_at_point_in_x_y_z (estimate it) to above JSON" ], ], ], ]);;

@Cryental
Copy link

I'm getting the same thing as @ehsanwwe. Hope you can upgrade it :)

@PatricioCabo
Copy link

getting the same ! Thanks for the effort guys

@agmike77
Copy link

agmike77 commented May 14, 2024

in files:
/vendor/openai-php/client/src/Responses/Assistants/AssistantResponse.php
/vendor/openai-php/client/src/Responses/Threads/Messages/ThreadMessageResponse.php
/vendor/openai-php/client/src/Responses/Threads/Runs/ThreadRunResponse.php
replace this line

$attributes['file_ids']

with this one

$attributes['file_ids'] ?? []

@PatricioCabo
Copy link

PatricioCabo commented May 14, 2024

in files: /vendor/openai-php/client/src/Responses/Assistants/AssistantResponse.php /vendor/openai-php/client/src/Responses/Threads/Messages/ThreadMessageResponse.php bitrix/vendor/openai-php/client/src/Responses/Threads/Runs/ThreadRunResponse.php replace this line

$attributes['file_ids']

with this one

$attributes['file_ids'] ?? []

This works !!! Thank you so much @agmike77 !!

@nadirhamid
Copy link

I am also having issues when working with assistants configured for GPT 4. It doesn't seem to work with the assistants v1 API so need a work around.

Also, I tried to just change the HTTP header so it uses assistants v2 but that resulted in some new errors. I think this upgrade would not be overly complex, although I am not sure if anyone is actively maintaining this project.

That said, this fix would be largely helpful to me and any others looking to use the newer APIs.

If theres anything I can do to make this happen let me know.

I look forward to when you integrate this to the library.

@fangyuan0306
Copy link

I have now resolved the file_ids issue, but a new issue has emerged: Unhandled match case '...' {"exception":"[object] (UnhandledMatchError(code: 0): Unhandled match case '...' at .../vendor/openai-php/client/src/Responses/Threads/Runs/ThreadRunResponse.php:64)"},
I also printed out the type, and I found that in version v2, the type values have changed. The type now includes file_search, so I modified it as follows:

$tools = array_map(
function (array $tool): ThreadRunResponseToolCodeInterpreter|ThreadRunResponseToolRetrieval|ThreadRunResponseToolFunction {
return match ($tool['type']) {
'code_interpreter' => ThreadRunResponseToolCodeInterpreter::from($tool),
'retrieval' => ThreadRunResponseToolRetrieval::from($tool),
'function' => ThreadRunResponseToolFunction::from($tool),
'file_search' => ThreadRunResponseToolRetrieval::from($tool),
default => throw new UnhandledMatchError("Unhandled match case '{$tool['type']}'"),
};
},
$attributes['tools'],
);
Additionally, I need to modify line 38 in vendor/openai-php/client/src/Responses/Threads/Messages/ThreadMessageResponseContentTextAnnotationFileCitation.php to:

$attributes['quote'] ?? ''
Now it works, but I'm not sure if it's correct.

@nunomaduro
Copy link
Contributor

I've just created a $12,000 a month tier, on my sponsors page, in case there a company truly relying on this package and it needs this feature urgently: https://github.com/sponsors/nunomaduro.

@wishborn
Copy link

Is this feature being held hostage?

@jhull
Copy link

jhull commented May 23, 2024

There are companies that do rely on this package but for which 12k is impossible. No worries though, besides the fact that files attached to threads don't even work anyways (known bug OAI engineers are working on), you can get assistants v2 up and running just by writing your own single php page. Took a couple of hours, but it works quite well (difference is night and day with v1 assistant), so the rest of us will just have to patiently wait ...

@nunomaduro
Copy link
Contributor

@wishborn @jhull, you can always contribute to this package instead of waiting. On our side, we will work on it once we find the time. 👍🏻

@wishborn
Copy link

@wishborn @jhull, you can always contribute to this package instead of waiting. On our side, we will work on it once we find the time. 👍🏻

If I knew what I was doing and wasn't homeless, I would. I'm still learning.

@gehrisandro
Copy link
Collaborator

API v2 support comes in this PR: #405

Feel free to check it out and give feedback there (atm, only the vector stores API is implemented, the rest is coming the next days).

@gehrisandro
Copy link
Collaborator

Release for assistants v2 has arrived (beta). 🚀

Happy to hear your feedback before making it a stable release.

https://github.com/openai-php/client/releases/tag/v0.10.0-beta.1

@arturspon
Copy link

Thanks for the release @gehrisandro 🎉
I just tried the beta version, but I'm getting this error when listing thread messages:

ErrorException: Undefined array key "attachments" in file /var/www/vendor/openai-php/client/src/Responses/Threads/Messages/ThreadMessageResponse.php on line 65

#0 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(256): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'Undefined array...', '/var/www/vendor...', 65)
#1 /var/www/vendor/openai-php/client/src/Responses/Threads/Messages/ThreadMessageResponse.php(65): Illuminate\Foundation\Bootstrap\HandleExceptions->Illuminate\Foundation\Bootstrap\{closure}(2, 'Undefined array...', '/var/www/vendor...', 65)
#2 /var/www/vendor/openai-php/client/src/Resources/ThreadsMessages.php(31): OpenAI\Responses\Threads\Messages\ThreadMessageResponse::from(Array, Object(OpenAI\Responses\Meta\MetaInformation))
#3 /var/www/app/Services/Chat/ChatService.php(54): OpenAI\Resources\ThreadsMessages->create('thread_3kF2toIo...', Array)
#4 /var/www/app/Http/Controllers/ChatController.php(75): App\Services\Chat\ChatService->createStreamedText(Object(App\Models\Chat), 'ol\xC3\xA1!', Array)
#5 /var/www/vendor/symfony/http-foundation/StreamedResponse.php(106): App\Http\Controllers\ChatController->App\Http\Controllers\{closure}()
#6 /var/www/vendor/symfony/http-foundation/Response.php(395): Symfony\Component\HttpFoundation\StreamedResponse->sendContent()
#7 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(1172): Symfony\Component\HttpFoundation\Response->send()
#8 /var/www/public/index.php(17): Illuminate\Foundation\Application->handleRequest(Object(Illuminate\Http\Request))
#9 {main}

@Nerenso
Copy link

Nerenso commented May 28, 2024

Running into the same problem as you @arturspon

Did you find any work around?

@gehrisandro
Copy link
Collaborator

Hi @arturspon, @Nerenso

Looks like you both ran into the same issue, where the request still used the v1 header.

Fixed with the new release for the Laravel Client: https://github.com/openai-php/laravel/releases/tag/v0.10.0-beta.2

If the problem still persists, please let me know.

@fixating
Copy link

@gehrisandro is the v2 feature coming to the next overall release? that will make a HUGE difference as it will allow us to the use the latest OpenAI GTP-4o model which is lightning fast in comparison.

@slim-dg9
Copy link

Hi @arturspon, @Nerenso

Looks like you both ran into the same issue, where the request still used the v1 header.

Fixed with the new release for the Laravel Client: https://github.com/openai-php/laravel/releases/tag/v0.10.0-beta.2

If the problem still persists, please let me know.

@gehrisandro Can we do the same for symfony client? openai-php/symfony#19

@Radiergummi
Copy link

Radiergummi commented Jul 18, 2024

@gehrisandro I still see this issue intermittently, sometimes the attachments attribute seems to be missing from thread message objects; from my quick looking at the log output, this appears to happen on processing the response to a createThreadMessage call, but I'll keep looking.

Since OpenAI is moving quickly with their API (well, just about anything actually..) might it make sense to be a bit more lenient in processing responses? Null coalescing would indeed be a good way to prevent this issue from happening; judging from the number of open issues and PRs, the maintainers seem to be preoccupied with other projects right now, so being more liberal in response parsing might alleviate the support burden for this library a bit?

@jhull
Copy link

jhull commented Jul 23, 2024

You're better off just building your own...that's what I ended up doing. OpenAI changes things so much (and sometimes don't even put in the docs!) that you'll save yourself a ton of headaches building your own integration (that's what I ended up doing).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests