-
-
Notifications
You must be signed in to change notification settings - Fork 547
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
assistants v2: Add vector store file batches
- Loading branch information
Showing
12 changed files
with
486 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/Contracts/Resources/VectorStoresFileBatchesContract.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace OpenAI\Contracts\Resources; | ||
|
||
use OpenAI\Resources\VectorStoresFileBatches; | ||
use OpenAI\Responses\VectorStores\FileBatches\VectorStoreFileBatchResponse; | ||
use OpenAI\Responses\VectorStores\Files\VectorStoreFileDeleteResponse; | ||
use OpenAI\Responses\VectorStores\Files\VectorStoreFileListResponse; | ||
use OpenAI\Responses\VectorStores\Files\VectorStoreFileResponse; | ||
use OpenAI\ValueObjects\Transporter\Payload; | ||
use OpenAI\ValueObjects\Transporter\Response; | ||
|
||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenAI\Resources; | ||
|
||
use OpenAI\Contracts\Resources\VectorStoresFileBatchesContract; | ||
use OpenAI\Responses\VectorStores\FileBatches\VectorStoreFileBatchResponse; | ||
use OpenAI\Responses\VectorStores\Files\VectorStoreFileListResponse; | ||
use OpenAI\ValueObjects\Transporter\Payload; | ||
use OpenAI\ValueObjects\Transporter\Response; | ||
|
||
final class VectorStoresFileBatches implements VectorStoresFileBatchesContract | ||
{ | ||
use Concerns\Transportable; | ||
|
||
/** | ||
* 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 | ||
{ | ||
$payload = Payload::create("vector_stores/$vectorStoreId/file_batches", $parameters); | ||
|
||
/** @var Response<array{id: string, object: string, created_at: int, vector_store_id: string, status: string, file_counts: array{in_progress: int, completed: int, failed: int, cancelled: int, total: int}}> $response */ | ||
$response = $this->transporter->requestObject($payload); | ||
|
||
return VectorStoreFileBatchResponse::from($response->data(), $response->meta()); | ||
} | ||
|
||
/** | ||
* 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 | ||
{ | ||
$payload = Payload::retrieve("vector_stores/$vectorStoreId/file_batches", $fileBatchId); | ||
|
||
/** @var Response<array{id: string, object: string, created_at: int, vector_store_id: string, status: string, file_counts: array{in_progress: int, completed: int, failed: int, cancelled: int, total: int}}> $response */ | ||
$response = $this->transporter->requestObject($payload); | ||
|
||
return VectorStoreFileBatchResponse::from($response->data(), $response->meta()); | ||
} | ||
|
||
/** | ||
* 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 | ||
{ | ||
$payload = Payload::list("vector_stores/$vectorStoreId/file_batches/$fileBatchId/files"); | ||
|
||
/** @var Response<array{object: string, data: array<int, array{id: string, object: string, usage_bytes: int, created_at: int, vector_store_id: string, status: string, last_error: ?array{code: string, message: string}}>, first_id: ?string, last_id: ?string, has_more: bool}> $response */ | ||
$response = $this->transporter->requestObject($payload); | ||
|
||
return VectorStoreFileListResponse::from($response->data(), $response->meta()); | ||
} | ||
|
||
/** | ||
* 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 | ||
{ | ||
$payload = Payload::delete("vector_stores/$vectorStoreId/file_batches", $fileBatchId); | ||
|
||
/** @var Response<array{id: string, object: string, created_at: int, vector_store_id: string, status: string, file_counts: array{in_progress: int, completed: int, failed: int, cancelled: int, total: int}}> $response */ | ||
$response = $this->transporter->requestObject($payload); | ||
|
||
return VectorStoreFileBatchResponse::from($response->data(), $response->meta()); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
src/Responses/VectorStores/FileBatches/VectorStoreFileBatchFileCountsResponse.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenAI\Responses\VectorStores\FileBatches; | ||
|
||
use OpenAI\Contracts\ResponseContract; | ||
use OpenAI\Responses\Concerns\ArrayAccessible; | ||
use OpenAI\Testing\Responses\Concerns\Fakeable; | ||
|
||
/** | ||
* @implements ResponseContract<array{in_progress: int, completed: int, failed: int, cancelled: int, total: int}> | ||
*/ | ||
final class VectorStoreFileBatchFileCountsResponse implements ResponseContract | ||
{ | ||
/** | ||
* @use ArrayAccessible<array{in_progress: int, completed: int, failed: int, cancelled: int, total: int}> | ||
*/ | ||
use ArrayAccessible; | ||
|
||
use Fakeable; | ||
|
||
private function __construct( | ||
public readonly int $inProgress, | ||
public readonly int $completed, | ||
public readonly int $failed, | ||
public readonly int $cancelled, | ||
public readonly int $total, | ||
) { | ||
} | ||
|
||
/** | ||
* Acts as static factory, and returns a new Response instance. | ||
* | ||
* @param array{in_progress: int, completed: int, failed: int, cancelled: int, total: int} $attributes | ||
*/ | ||
public static function from(array $attributes): self | ||
{ | ||
return new self( | ||
$attributes['in_progress'], | ||
$attributes['completed'], | ||
$attributes['cancelled'], | ||
$attributes['failed'], | ||
$attributes['total'], | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function toArray(): array | ||
{ | ||
return [ | ||
'in_progress' => $this->inProgress, | ||
'completed' => $this->completed, | ||
'failed' => $this->failed, | ||
'cancelled' => $this->cancelled, | ||
'total' => $this->total, | ||
]; | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
src/Responses/VectorStores/FileBatches/VectorStoreFileBatchResponse.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenAI\Responses\VectorStores\FileBatches; | ||
|
||
use OpenAI\Contracts\ResponseContract; | ||
use OpenAI\Contracts\ResponseHasMetaInformationContract; | ||
use OpenAI\Responses\Concerns\ArrayAccessible; | ||
use OpenAI\Responses\Concerns\HasMetaInformation; | ||
use OpenAI\Responses\Meta\MetaInformation; | ||
use OpenAI\Responses\VectorStores\Files\VectorStoreFileLastErrorResponse; | ||
use OpenAI\Testing\Responses\Concerns\Fakeable; | ||
|
||
/** | ||
* @implements ResponseContract<array{id: string, object: string, created_at: int, vector_store_id: string, status: string, file_counts: array{in_progress: int, completed: int, failed: int, cancelled: int, total: int}}> | ||
*/ | ||
final class VectorStoreFileBatchResponse implements ResponseContract, ResponseHasMetaInformationContract | ||
{ | ||
/** | ||
* @use ArrayAccessible<array{id: string, object: string, created_at: int, vector_store_id: string, status: string, file_counts: array{in_progress: int, completed: int, failed: int, cancelled: int, total: int}}> | ||
*/ | ||
use ArrayAccessible; | ||
|
||
use Fakeable; | ||
use HasMetaInformation; | ||
|
||
private function __construct( | ||
public readonly string $id, | ||
public readonly string $object, | ||
public readonly int $createdAt, | ||
public readonly string $vectorStoreId, | ||
public readonly string $status, | ||
public readonly VectorStoreFileBatchFileCountsResponse $fileCounts, | ||
private readonly MetaInformation $meta, | ||
) { | ||
} | ||
|
||
/** | ||
* Acts as static factory, and returns a new Response instance. | ||
* | ||
* @param array{id: string, object: string, created_at: int, vector_store_id: string, status: string, file_counts: array{in_progress: int, completed: int, failed: int, cancelled: int, total: int}} $attributes | ||
*/ | ||
public static function from(array $attributes, MetaInformation $meta): self | ||
{ | ||
return new self( | ||
$attributes['id'], | ||
$attributes['object'], | ||
$attributes['created_at'], | ||
$attributes['vector_store_id'], | ||
$attributes['status'], | ||
VectorStoreFileBatchFileCountsResponse::from($attributes['file_counts']), | ||
$meta, | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function toArray(): array | ||
{ | ||
return [ | ||
'id' => $this->id, | ||
'object' => $this->object, | ||
'created_at' => $this->createdAt, | ||
'vector_store_id' => $this->vectorStoreId, | ||
'status' => $this->status, | ||
'file_counts' => $this->fileCounts->toArray(), | ||
]; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/Testing/Resources/VectorStoresFileBatchesTestResource.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace OpenAI\Testing\Resources; | ||
|
||
use OpenAI\Contracts\Resources\VectorStoresFileBatchesContract; | ||
use OpenAI\Resources\VectorStoresFileBatches; | ||
use OpenAI\Responses\VectorStores\FileBatches\VectorStoreFileBatchResponse; | ||
use OpenAI\Responses\VectorStores\Files\VectorStoreFileListResponse; | ||
use OpenAI\Testing\Resources\Concerns\Testable; | ||
|
||
final class VectorStoresFileBatchesTestResource implements VectorStoresFileBatchesContract | ||
{ | ||
use Testable; | ||
|
||
public function resource(): string | ||
{ | ||
return VectorStoresFileBatches::class; | ||
} | ||
|
||
public function retrieve(string $vectorStoreId, string $fileBatchId): VectorStoreFileBatchResponse | ||
{ | ||
return $this->record(__FUNCTION__, func_get_args()); | ||
} | ||
|
||
public function cancel(string $vectorStoreId, string $fileBatchId): VectorStoreFileBatchResponse | ||
{ | ||
return $this->record(__FUNCTION__, func_get_args()); | ||
} | ||
|
||
public function create(string $vectorStoreId, array $parameters): VectorStoreFileBatchResponse | ||
{ | ||
return $this->record(__FUNCTION__, func_get_args()); | ||
} | ||
|
||
public function listFiles(string $vectorStoreId, string $fileBatchId): VectorStoreFileListResponse | ||
{ | ||
return $this->record(__FUNCTION__, func_get_args()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
/** | ||
* @return array<string, mixed> | ||
*/ | ||
function vectorStoreFileBatchResource(): array | ||
{ | ||
return [ | ||
'id' => 'vsfb_abc123', | ||
'object' => 'vector_store.file_batch', | ||
'created_at' => 1699061776, | ||
'vector_store_id' => 'vs_abc123', | ||
'status' => 'cancelling', | ||
'file_counts' => [ | ||
'in_progress' => 12, | ||
'completed' => 3, | ||
'failed' => 0, | ||
'cancelled' => 0, | ||
'total' => 15, | ||
] | ||
]; | ||
} |
Oops, something went wrong.