openai-php / client

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

[0.8.x] Add Assistant API #243

Closed gehrisandro closed 8 months ago

gehrisandro commented 8 months ago

https://platform.openai.com/docs/api-reference/assistants

gehrisandro commented 8 months ago

The Assistant / Threads API has a nested structured and I am currently trying to figure out, how we should access the API. Here are lists of some of the endpoints in three different variations:

1) Nested Resources

$client->assistants()->create(parameters: [/* ... */]);

$client->assistants()->files()->retrieve(assistantId: 'asst_123', fileId: 'file_123');

$client->threads()->create(parameters: [/* ... */]);

$client->threads()->runs()->create(threadId: 'thread_123', parameters: [/* ... */]);

$client->threads()->runs()->submitToolOutputs(threadId: 'thread_123', runId: 'run_123', parameters: [/* ... */]);

$client->threads()->runs()->steps()->retrieve(threadId: 'thread_123', runId: 'run_123', stepId: 'step_123');

$client->threads()->runs()->steps()->list(threadId: 'thread_123', runId: 'run_123');

2) Nested Resources with ID parameters

$client->assistants()->create(parameters: [/* ... */]);

$client->assistant(assistantId: 'asst_123')->retrieve(fileId: 'file_123');

$client->threads()->create(parameters: [/* ... */]);

$client->thread(threadId: 'thread_123')->runs()->create(parameters: [/* ... */]);

$client->thread(threadId: 'thread_123')->run(runId: 'run_123')->submitToolOutputs(parameters: [/* ... */]);

$client->thread(threadId: 'thread_123')->run(runId: 'run_123')->steps()->retrieve(stepId: 'step_123');

$client->thread(threadId: 'thread_123')->run(runId: 'run_123')->steps()->list();

3) Sibling Resources

$client->assistants()->create(parameters: [/* ... */]);

$client->assistantFiles()->retrieve(assistantId: 'asst_123', fileId: 'file_123');

$client->threads()->create(parameters: [/* ... */]);

$client->threadRuns()->create(threadId: 'thread_123', parameters: [/* ... */]);

$client->threadRuns()->submitToolOutputs(threadId: 'thread_123', runId: 'run_123', parameters: [/* ... */]);

$client->threadRunSteps()->retrieve(threadId: 'thread_123', runId: 'run_123', stepId: 'step_123');

$client->threadRunSteps()->list(threadId: 'thread_123', runId: 'run_123');

@nunomaduro What do you think? ATM I would probably go for variation 1.

obaid commented 8 months ago

I would pick from variation 1 or 2.

coreation commented 8 months ago

I'd go for version 2 simply because of the "RESTful" approach of it. You define what resource you're working with as you chain the functions together. I wonder if there's a non-chaining approach so that you basically go for variation 1 but with a specific "fetch" function. I.e ...->fetchAssistantStep(threadId, runId, stepId) (or something in that nature).

Just my 2 cents, I haven't deep dived into the beta API just yet :) In any case, thanks so much for adding the feature!

TomasVotruba commented 8 months ago

@gehrisandro Thanks for kicking of :+1: Already running your PR locally and trying it out :clap:

TomasVotruba commented 8 months ago

@gehrisandro :clap: :clap: :clap: Thank you

gehrisandro commented 8 months ago

@gehrisandro 👏 👏 👏 Thank you

You are welcome! And thanks for supporting me!

coreation commented 8 months ago

Nice work @gehrisandro !

ThibautPV commented 8 months ago

Good job @gehrisandro 👏

Thank you !

xitude commented 8 months ago

Well done @gehrisandro 🎉

heychazza commented 7 months ago

Thank you @gehrisandro, is it possible to upload the new API somehow? I see the docs show that you can, but don't see it in the PHP wrapper

xitude commented 7 months ago

Thank you @gehrisandro, is it possible to upload the new API somehow? I see the docs show that you can, but don't see it in the PHP wrapper

Can you explain by what you mean by "new API"

heychazza commented 7 months ago

Thank you @gehrisandro, is it possible to upload the new API somehow? I see the docs show that you can, but don't see it in the PHP wrapper

Can you explain by what you mean by "new API"

Hey, sorry I meant - using the files API, how would we upload a file to OpenAI?

Is it possible to upload a temp file?

Holsta0822 commented 5 months ago

Thanks