Skip to content

[WIP] Assistants v2 support #395

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

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
292cb59
assistants v2: Merge with latest changes
knash94 May 17, 2024
1885131
assistants v2: Fix tests and add test coverage for tool resource resp…
knash94 May 14, 2024
1ecc16c
assistants v2: Add response formats with tests
knash94 May 14, 2024
ec2ff8c
assistants v2: Add response formats with tests
knash94 May 14, 2024
fb57211
assistants v2: Update ThreadMessages to v2 assistants API
knash94 May 15, 2024
d6298df
assistants v2: Remove todo
knash94 May 15, 2024
3028e95
assistants v2: Add support for ThreadRuns on v2 assistants API + tests
knash94 May 16, 2024
71e87c7
assistants v2: Add ThreadMessageResponseAttachmentCodeInterpreterTool
knash94 May 16, 2024
ec202e5
assistants v2: Update ThreadRunSteps to use V2
knash94 May 16, 2024
7a8f330
assistants v2: Update responses
knash94 May 17, 2024
00af3cd
assistants v2: Fix unresolved merge conflicts
knash94 May 17, 2024
cb6d256
assistants v2: Change expired_at to expires_at
knash94 May 17, 2024
8b28e6c
assistants v2: Update stream events to match modified responses
knash94 May 17, 2024
ec1f732
assistants v2: Add vector stores endpoints and resources
knash94 May 17, 2024
c006a9e
assistants v2: Run lint
knash94 May 17, 2024
4b53e77
assistants v2: Apply rector
knash94 May 17, 2024
243bd1a
assistants v2: Run lint
knash94 May 17, 2024
c9267ad
assistants v2: Adding responses for vector files
knash94 May 17, 2024
095c64b
assistants v2: Adding responses for vector store files
knash94 May 21, 2024
0c7ebb5
assistants v2: Run lint and rector
knash94 May 21, 2024
9591c6d
assistants v2: Update array typing for assistants & vector stores
knash94 May 21, 2024
3e681a9
assistants v2: Add vector store file batches
knash94 May 21, 2024
174cb93
assistants v2: Merge main branch
knash94 May 22, 2024
e9f7454
assistants v2: Fix annotations
knash94 May 22, 2024
d5a1caa
assistants v2: Fix styling and types
knash94 May 22, 2024
4737c7e
assistants v2: Update existing endpoints on readme
knash94 May 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 75 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@ $response->toArray(); // ['created' => 1589478378, data => ['url' => 'https://oa

> **Note:** If you are creating the client manually from the factory. Make sure you provide the necessary header:
> ```php
> $factory->withHttpHeader('OpenAI-Beta', 'assistants=v1')
> $factory->withHttpHeader('OpenAI-Beta', 'assistants=v2')
> ```

#### `create`
Expand All @@ -969,8 +969,11 @@ $response->instructions; // 'You are a personal math tutor. When asked a questio
$response->model; // 'gpt-4'
$response->description; // null
$response->tools[0]->type; // 'code_interpreter'
$response->fileIds; // []
$response->toolResources; // []
$response->metadata; // []
$response->temperature: // null
$response->topP: // null
$response->format: // 'auto'

$response->toArray(); // ['id' => 'asst_gxzBkD1wkKEloYqZ410pT5pd', ...]
```
Expand All @@ -990,8 +993,11 @@ $response->instructions; // 'You are a personal math tutor. When asked a questio
$response->model; // 'gpt-4'
$response->description; // null
$response->tools[0]->type; // 'code_interpreter'
$response->fileIds; // []
$response->toolResources; // []
$response->metadata; // []
$response->temperature: // null
$response->topP: // null
$response->format: // 'auto'

$response->toArray(); // ['id' => 'asst_gxzBkD1wkKEloYqZ410pT5pd', ...]
```
Expand All @@ -1013,8 +1019,11 @@ $response->instructions; // 'You are a personal math tutor. When asked a questio
$response->model; // 'gpt-4'
$response->description; // null
$response->tools[0]->type; // 'code_interpreter'
$response->fileIds; // []
$response->toolResources; // []
$response->metadata; // []
$response->temperature: // null
$response->topP: // null
$response->format: // 'auto'

$response->toArray(); // ['id' => 'asst_gxzBkD1wkKEloYqZ410pT5pd', ...]
```
Expand Down Expand Up @@ -1055,7 +1064,7 @@ foreach ($response->data as $result) {
$response->toArray(); // ['object' => 'list', ...]]
```

### `Assistants Files` Resource
### `Assistants Files` Resource [Deprecated]

#### `create`

Expand Down Expand Up @@ -1183,8 +1192,16 @@ $response->lastError; // null
$response->model; // 'gpt-4'
$response->instructions; // null
$response->tools; // []
$response->fileIds; // []
$response->metadata; // []
$response->incompleteDetails; // []
$response->usage?->total_tokens; // 579
$response->temperature; // null
$response->topP; // null
$response->maxPromptTokens; // 1000
$response->maxCompletionTokens; // 1000
$response->truncationStrategy->type; // 'auto'
$response->responseFormat; // 'auto'
$response->toolChoice; // 'auto'

$response->toArray(); // ['id' => 'run_4RCYyYzX9m41WQicoJtUQAb8', ...]
```
Expand Down Expand Up @@ -1259,7 +1276,7 @@ $response->content[0]->text->value; // 'What is the sum of 5 and 7?'
$response->content[0]->text->annotations; // []
$response->assistantId; // null
$response->runId; // null
$response->fileIds; // []
$response->attachments; // []
$response->metadata; // []

$response->toArray(); // ['id' => 'msg_SKYwvF3zcigxthfn6F4hnpdU', ...]
Expand All @@ -1285,7 +1302,7 @@ $response->content[0]->text->value; // 'What is the sum of 5 and 7?'
$response->content[0]->text->annotations; // []
$response->assistantId; // null
$response->runId; // null
$response->fileIds; // []
$response->attachments; // []
$response->metadata; // []

$response->toArray(); // ['id' => 'msg_SKYwvF3zcigxthfn6F4hnpdU', ...]
Expand Down Expand Up @@ -1316,7 +1333,7 @@ $response->content[0]->text->value; // 'What is the sum of 5 and 7?'
$response->content[0]->text->annotations; // []
$response->assistantId; // null
$response->runId; // null
$response->fileIds; // []
$response->attachments; // []
$response->metadata; // ['name' => 'My new message name']

$response->toArray(); // ['id' => 'msg_SKYwvF3zcigxthfn6F4hnpdU', ...]
Expand Down Expand Up @@ -1344,7 +1361,7 @@ foreach ($response->data as $result) {
$response->toArray(); // ['object' => 'list', ...]]
```

### `Threads Messages Files` Resource
### `Threads Messages Files` Resource [Deprecated]

#### `retrieve`

Expand Down Expand Up @@ -1419,9 +1436,17 @@ $response->completedAt; // null
$response->lastError; // null
$response->model; // 'gpt-4'
$response->instructions; // null
$response->tools[0]->type; // 'code_interpreter'
$response->fileIds; // []
$response->tools; // []
$response->metadata; // []
$response->incompleteDetails; // []
$response->usage?->total_tokens; // 579
$response->temperature; // null
$response->topP; // null
$response->maxPromptTokens; // 1000
$response->maxCompletionTokens; // 1000
$response->truncationStrategy->type; // 'auto'
$response->responseFormat; // 'auto'
$response->toolChoice; // 'auto'

$response->toArray(); // ['id' => 'run_4RCYyYzX9m41WQicoJtUQAb8', ...]
```
Expand Down Expand Up @@ -1526,13 +1551,19 @@ $response->completedAt; // null
$response->lastError; // null
$response->model; // 'gpt-4'
$response->instructions; // null
$response->tools[0]->type; // 'code_interpreter'
$response->fileIds; // []
$response->tools; // []
$response->metadata; // []

$response->incompleteDetails; // []
$response->usage->promptTokens; // 25,
$response->usage->completionTokens; // 32,
$response->usage->totalTokens; // 57
$response->temperature; // null
$response->topP; // null
$response->maxPromptTokens; // 1000
$response->maxCompletionTokens; // 1000
$response->truncationStrategy->type; // 'auto'
$response->responseFormat; // 'auto'
$response->toolChoice; // 'auto'

$response->toArray(); // ['id' => 'run_4RCYyYzX9m41WQicoJtUQAb8', ...]
```
Expand Down Expand Up @@ -1566,8 +1597,16 @@ $response->completedAt; // null
$response->lastError; // null
$response->model; // 'gpt-4'
$response->instructions; // null
$response->tools[0]->type; // 'code_interpreter'
$response->fileIds; // []
$response->tools; // []
$response->incompleteDetails; // []
$response->usage?->total_tokens; // 579
$response->temperature; // null
$response->topP; // null
$response->maxPromptTokens; // 1000
$response->maxCompletionTokens; // 1000
$response->truncationStrategy->type; // 'auto'
$response->responseFormat; // 'auto'
$response->toolChoice; // 'auto'
$response->metadata; // ['name' => 'My new run name']

$response->toArray(); // ['id' => 'run_4RCYyYzX9m41WQicoJtUQAb8', ...]
Expand Down Expand Up @@ -1597,8 +1636,16 @@ $response->completedAt; // null
$response->lastError; // null
$response->model; // 'gpt-4'
$response->instructions; // null
$response->tools[0]->type; // 'code_interpreter'
$response->fileIds; // []
$response->tools; // []
$response->incompleteDetails; // []
$response->usage?->total_tokens; // 579
$response->temperature; // null
$response->topP; // null
$response->maxPromptTokens; // 1000
$response->maxCompletionTokens; // 1000
$response->truncationStrategy->type; // 'auto'
$response->responseFormat; // 'auto'
$response->toolChoice; // 'auto'
$response->metadata; // []

$response->toArray(); // ['id' => 'run_4RCYyYzX9m41WQicoJtUQAb8', ...]
Expand Down Expand Up @@ -1636,8 +1683,16 @@ $response->completedAt; // null
$response->lastError; // null
$response->model; // 'gpt-4'
$response->instructions; // null
$response->incompleteDetails; // []
$response->usage?->total_tokens; // 579
$response->temperature; // null
$response->topP; // null
$response->maxPromptTokens; // 1000
$response->maxCompletionTokens; // 1000
$response->truncationStrategy->type; // 'auto'
$response->responseFormat; // 'auto'
$response->toolChoice; // 'auto'
$response->tools[0]->type; // 'function'
$response->fileIds; // []
$response->metadata; // []

$response->toArray(); // ['id' => 'run_4RCYyYzX9m41WQicoJtUQAb8', ...]
Expand Down
12 changes: 12 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use OpenAI\Contracts\ClientContract;
use OpenAI\Contracts\Resources\ThreadsContract;
use OpenAI\Contracts\Resources\VectorStoresContract;
use OpenAI\Contracts\TransporterContract;
use OpenAI\Resources\Assistants;
use OpenAI\Resources\Audio;
Expand All @@ -20,6 +21,7 @@
use OpenAI\Resources\Models;
use OpenAI\Resources\Moderations;
use OpenAI\Resources\Threads;
use OpenAI\Resources\VectorStores;

final class Client implements ClientContract
{
Expand Down Expand Up @@ -163,4 +165,14 @@ public function threads(): ThreadsContract
{
return new Threads($this->transporter);
}

/**
* Create and update vector stores that assistants can interact with
*
* @see https://platform.openai.com/docs/api-reference/vector-stores
*/
public function vectorStores(): VectorStoresContract
{
return new VectorStores($this->transporter);
}
}
8 changes: 8 additions & 0 deletions src/Contracts/ClientContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use OpenAI\Contracts\Resources\ModelsContract;
use OpenAI\Contracts\Resources\ModerationsContract;
use OpenAI\Contracts\Resources\ThreadsContract;
use OpenAI\Contracts\Resources\VectorStoresContract;

interface ClientContract
{
Expand Down Expand Up @@ -113,4 +114,11 @@ public function assistants(): AssistantsContract;
* @see https://platform.openai.com/docs/api-reference/threads
*/
public function threads(): ThreadsContract;

/**
* Create and update vector stores that assistants can interact with
*
* @see https://platform.openai.com/docs/api-reference/vector-stores
*/
public function vectorStores(): VectorStoresContract;
}
63 changes: 63 additions & 0 deletions src/Contracts/Resources/VectorStoresContract.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace OpenAI\Contracts\Resources;

use OpenAI\Responses\VectorStores\VectorStoreDeleteResponse;
use OpenAI\Responses\VectorStores\VectorStoreListResponse;
use OpenAI\Responses\VectorStores\VectorStoreResponse;

interface VectorStoresContract
{
/**
* Modify a vector store
*
* @see https://platform.openai.com/docs/api-reference/vector-stores/modify
*
* @param array<string, mixed> $parameters
*/
public function modify(string $vectorStore, array $parameters): VectorStoreResponse;

/**
* Retrieves a vector store.
*
* @see https://platform.openai.com/docs/api-reference/vector-stores/retrieve
*/
public function retrieve(string $vectorStore): VectorStoreResponse;

/**
* Delete a vector store.
*
* https://platform.openai.com/docs/api-reference/vector-stores/delete
*/
public function delete(string $vectorStore): VectorStoreDeleteResponse;

/**
* Create a vector store
*
* @see https://platform.openai.com/docs/api-reference/vector-stores/create
*
* @param array<string, mixed> $parameters
*/
public function create(array $parameters): VectorStoreResponse;

/**
* Returns a list of vector stores.
*
* @see https://platform.openai.com/docs/api-reference/vector-stores/list
*/
public function list(): VectorStoreListResponse;

/**
* Manage the files related to the vector store
*
* @see https://platform.openai.com/docs/api-reference/vector-stores-files
*/
public function files(): VectorStoresFilesContract;

/**
* Manage the file batches related to the vector store
*
* @see https://platform.openai.com/docs/api-reference/vector-stores-file-batches
*/
public function batches(): VectorStoresFileBatchesContract;
}
39 changes: 39 additions & 0 deletions src/Contracts/Resources/VectorStoresFileBatchesContract.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace OpenAI\Contracts\Resources;

use OpenAI\Responses\VectorStores\FileBatches\VectorStoreFileBatchResponse;
use OpenAI\Responses\VectorStores\Files\VectorStoreFileListResponse;

interface VectorStoresFileBatchesContract
{
/**
* Retrieves a file batch within a vector store.
*
* @see https://platform.openai.com/docs/api-reference/vector-stores-file-batches/getBatch
*/
public function retrieve(string $vectorStoreId, string $fileBatchId): VectorStoreFileBatchResponse;

/**
* Cancel a vector store file batch
*
* @see https://platform.openai.com/docs/api-reference/vector-stores-file-batches/cancelBatch
*/
public function cancel(string $vectorStoreId, string $fileBatchId): VectorStoreFileBatchResponse;

/**
* Create a file batch on a vector store
*
* @see https://platform.openai.com/docs/api-reference/vector-stores-file-batches/createBatch
*
* @param array<string, mixed> $parameters
*/
public function create(string $vectorStoreId, array $parameters): VectorStoreFileBatchResponse;

/**
* Lists the files within a file batch within a vector store
*
* @see https://platform.openai.com/docs/api-reference/vector-stores-file-batches/listBatchFiles
*/
public function listFiles(string $vectorStoreId, string $fileBatchId): VectorStoreFileListResponse;
}
Loading