Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/Resources/VectorStoresFileBatches.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function listFiles(string $vectorStoreId, string $fileBatchId, array $par
{
$payload = Payload::list("vector_stores/$vectorStoreId/file_batches/$fileBatchId/files", $parameters);

/** @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}, chunking_strategy: array{type: 'static', static: array{max_chunk_size_tokens: int, chunk_overlap_tokens: int}}|array{type: 'other'}}>, first_id: ?string, last_id: ?string, has_more: bool}> $response */
/** @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, attributes: array<string, string>, last_error: ?array{code: string, message: string}, chunking_strategy: array{type: 'static', static: array{max_chunk_size_tokens: int, chunk_overlap_tokens: int}}|array{type: 'other'}}>, first_id: ?string, last_id: ?string, has_more: bool}> $response */
$response = $this->transporter->requestObject($payload);

return VectorStoreFileListResponse::from($response->data(), $response->meta());
Expand Down
6 changes: 3 additions & 3 deletions src/Resources/VectorStoresFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function create(string $vectorStoreId, array $parameters): VectorStoreFil
{
$payload = Payload::create("vector_stores/$vectorStoreId/files", $parameters);

/** @var Response<array{id: string, object: string, usage_bytes: int, created_at: int, vector_store_id: string, status: string, last_error: ?array{code: string, message: string}, chunking_strategy: array{type: 'static', static: array{max_chunk_size_tokens: int, chunk_overlap_tokens: int}}|array{type: 'other'}}> $response */
/** @var Response<array{id: string, object: string, usage_bytes: int, created_at: int, vector_store_id: string, status: string, attributes: array<string, string>, last_error: ?array{code: string, message: string}, chunking_strategy: array{type: 'static', static: array{max_chunk_size_tokens: int, chunk_overlap_tokens: int}}|array{type: 'other'}}> $response */
$response = $this->transporter->requestObject($payload);

return VectorStoreFileResponse::from($response->data(), $response->meta());
Expand All @@ -43,7 +43,7 @@ public function list(string $vectorStoreId, array $parameters = []): VectorStore
{
$payload = Payload::list("vector_stores/$vectorStoreId/files", $parameters);

/** @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}, chunking_strategy: array{type: 'static', static: array{max_chunk_size_tokens: int, chunk_overlap_tokens: int}}|array{type: 'other'}}>, first_id: ?string, last_id: ?string, has_more: bool}> $response */
/** @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, attributes: array<string, string>, last_error: ?array{code: string, message: string}, chunking_strategy: array{type: 'static', static: array{max_chunk_size_tokens: int, chunk_overlap_tokens: int}}|array{type: 'other'}}>, first_id: ?string, last_id: ?string, has_more: bool}> $response */
$response = $this->transporter->requestObject($payload);

return VectorStoreFileListResponse::from($response->data(), $response->meta());
Expand All @@ -58,7 +58,7 @@ public function retrieve(string $vectorStoreId, string $fileId): VectorStoreFile
{
$payload = Payload::retrieve("vector_stores/$vectorStoreId/files", $fileId);

/** @var Response<array{id: string, object: string, usage_bytes: int, created_at: int, vector_store_id: string, status: string, last_error: ?array{code: string, message: string}, chunking_strategy: array{type: 'static', static: array{max_chunk_size_tokens: int, chunk_overlap_tokens: int}}|array{type: 'other'}}> $response */
/** @var Response<array{id: string, object: string, usage_bytes: int, created_at: int, vector_store_id: string, status: string, attributes: array<string, string>, last_error: ?array{code: string, message: string}, chunking_strategy: array{type: 'static', static: array{max_chunk_size_tokens: int, chunk_overlap_tokens: int}}|array{type: 'other'}}> $response */
$response = $this->transporter->requestObject($payload);

return VectorStoreFileResponse::from($response->data(), $response->meta());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
use OpenAI\Testing\Responses\Concerns\Fakeable;

/**
* @implements ResponseContract<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}>
* @implements ResponseContract<array{object: string, data: array<int, array{id: string, object: string, usage_bytes: int, created_at: int, vector_store_id: string, status: string, attributes: array<string, string>, last_error: ?array{code: string, message: string}}>, first_id: ?string, last_id: ?string, has_more: bool}>
*/
final class VectorStoreFileListResponse implements ResponseContract, ResponseHasMetaInformationContract
{
/**
* @use ArrayAccessible<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}>
* @use ArrayAccessible<array{object: string, data: array<int, array{id: string, object: string, usage_bytes: int, created_at: int, vector_store_id: string, status: string, attributes: array<string, string>, last_error: ?array{code: string, message: string}}>, first_id: ?string, last_id: ?string, has_more: bool}>
*/
use ArrayAccessible;

Expand All @@ -39,7 +39,7 @@ private function __construct(
/**
* Acts as static factory, and returns a new Response instance.
*
* @param 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}, chunking_strategy: array{type: 'static', static: array{max_chunk_size_tokens: int, chunk_overlap_tokens: int}}|array{type: 'other'}}>, first_id: ?string, last_id: ?string, has_more: bool} $attributes
* @param array{object: string, data: array<int, array{id: string, object: string, usage_bytes: int, created_at: int, vector_store_id: string, status: string, attributes: array<string, string>, last_error: ?array{code: string, message: string}, chunking_strategy: array{type: 'static', static: array{max_chunk_size_tokens: int, chunk_overlap_tokens: int}}|array{type: 'other'}}>, first_id: ?string, last_id: ?string, has_more: bool} $attributes
*/
public static function from(array $attributes, MetaInformation $meta): self
{
Expand All @@ -61,7 +61,7 @@ public static function from(array $attributes, MetaInformation $meta): self
/**
* {@inheritDoc}
*
* @return 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}|null}>, first_id: string|null, last_id: string|null, has_more: bool}
* @return array{object: string, data: array<int, array{id: string, object: string, usage_bytes: int, created_at: int, vector_store_id: string, status: string, attributes: array<string, string>, last_error: array{code: string, message: string}|null}>, first_id: string|null, last_id: string|null, has_more: bool}
*/
public function toArray(): array
{
Expand Down
12 changes: 9 additions & 3 deletions src/Responses/VectorStores/Files/VectorStoreFileResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,29 @@
use OpenAI\Testing\Responses\Concerns\Fakeable;

/**
* @implements ResponseContract<array{id: string, object: string, usage_bytes: int, created_at: int, vector_store_id: string, status: string, last_error: ?array{code: string, message: string}, chunking_strategy: array{type: 'static', static: array{max_chunk_size_tokens: int, chunk_overlap_tokens: int}}|array{type: 'other'}}>
* @implements ResponseContract<array{id: string, object: string, usage_bytes: int, created_at: int, vector_store_id: string, status: string, attributes: array<string, string>, last_error: ?array{code: string, message: string}, chunking_strategy: array{type: 'static', static: array{max_chunk_size_tokens: int, chunk_overlap_tokens: int}}|array{type: 'other'}}>
*/
final class VectorStoreFileResponse implements ResponseContract, ResponseHasMetaInformationContract
{
/**
* @use ArrayAccessible<array{id: string, object: string, usage_bytes: int, created_at: int, vector_store_id: string, status: string, last_error: ?array{code: string, message: string}, chunking_strategy: array{type: 'static', static: array{max_chunk_size_tokens: int, chunk_overlap_tokens: int}}|array{type: 'other'}}>
* @use ArrayAccessible<array{id: string, object: string, usage_bytes: int, created_at: int, vector_store_id: string, status: string, attributes: array<string, string>, last_error: ?array{code: string, message: string}, chunking_strategy: array{type: 'static', static: array{max_chunk_size_tokens: int, chunk_overlap_tokens: int}}|array{type: 'other'}}>
*/
use ArrayAccessible;

use Fakeable;
use HasMetaInformation;

/**
* @param array<string, string> $attributes
*/
private function __construct(
public readonly string $id,
public readonly string $object,
public readonly int $usageBytes,
public readonly int $createdAt,
public readonly string $vectorStoreId,
public readonly string $status,
public readonly array $attributes,
public readonly ?VectorStoreFileResponseLastError $lastError,
public readonly VectorStoreFileResponseChunkingStrategyStatic|VectorStoreFileResponseChunkingStrategyOther $chunkingStrategy,
private readonly MetaInformation $meta,
Expand All @@ -39,7 +43,7 @@ private function __construct(
/**
* Acts as static factory, and returns a new Response instance.
*
* @param array{id: string, object: string, usage_bytes: int, created_at: int, vector_store_id: string, status: string, last_error: ?array{code: string, message: string}, chunking_strategy: array{type: 'static', static: array{max_chunk_size_tokens: int, chunk_overlap_tokens: int}}|array{type: 'other'}} $attributes
* @param array{id: string, object: string, usage_bytes: int, created_at: int, vector_store_id: string, status: string, attributes: ?array<string, string>, last_error: ?array{code: string, message: string}, chunking_strategy: array{type: 'static', static: array{max_chunk_size_tokens: int, chunk_overlap_tokens: int}}|array{type: 'other'}} $attributes
*/
public static function from(array $attributes, MetaInformation $meta): self
{
Expand All @@ -50,6 +54,7 @@ public static function from(array $attributes, MetaInformation $meta): self
$attributes['created_at'],
$attributes['vector_store_id'],
$attributes['status'],
$attributes['attributes'] ?? [],
isset($attributes['last_error']) ? VectorStoreFileResponseLastError::from($attributes['last_error']) : null,
$attributes['chunking_strategy']['type'] === 'static' ? VectorStoreFileResponseChunkingStrategyStatic::from($attributes['chunking_strategy']) : VectorStoreFileResponseChunkingStrategyOther::from($attributes['chunking_strategy']),
$meta,
Expand All @@ -68,6 +73,7 @@ public function toArray(): array
'created_at' => $this->createdAt,
'vector_store_id' => $this->vectorStoreId,
'status' => $this->status,
'attributes' => $this->attributes,
'last_error' => $this->lastError instanceof VectorStoreFileResponseLastError ? $this->lastError->toArray() : null,
'chunking_strategy' => $this->chunkingStrategy->toArray(),
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ final class VectorStoreFileListResponseFixture
'created_at' => 1_715_956_697,
'vector_store_id' => 'vs_xds05V7ep0QMGI5JmYnWsJwb',
'status' => 'completed',
'attributes' => [],
'last_error' => null,
],
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ final class VectorStoreFileResponseFixture
'created_at' => 1_715_956_697,
'vector_store_id' => 'vs_xds05V7ep0QMGI5JmYnWsJwb',
'status' => 'completed',
'attributes' => [],
'last_error' => null,
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ final class VectorStoreListResponseFixture
'object' => 'vector_store',
'name' => 'Product Knowledge Base',
'status' => 'completed',
'attributes' => [],
'usage_bytes' => 29882,
'created_at' => 1_715_953_317,
'file_counts' => [
Expand All @@ -31,6 +32,7 @@ final class VectorStoreListResponseFixture
'object' => 'vector_store',
'name' => null,
'status' => 'completed',
'attributes' => [],
'usage_bytes' => 0,
'created_at' => 1_710_869_420,
'file_counts' => [
Expand Down
3 changes: 3 additions & 0 deletions tests/Fixtures/VectorStoreFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ function vectorStoreFileResource(): array
'created_at' => 1715956697,
'vector_store_id' => 'vs_xds05V7ep0QMGI5JmYnWsJwb',
'status' => 'completed',
'attributes' => [
'foo' => 'bar',
],
'last_error' => null,
'chunking_strategy' => [
'type' => 'static',
Expand Down
10 changes: 10 additions & 0 deletions tests/Responses/VectorStores/Files/VectorStoreFileResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,23 @@
->createdAt->toBe(1715956697)
->vectorStoreId->toBe('vs_xds05V7ep0QMGI5JmYnWsJwb')
->status->toBe('completed')
->attributes->toBe(['foo' => 'bar'])
->lastError->toBeNull()
->chunkingStrategy->toBeInstanceOf(VectorStoreFileResponseChunkingStrategyStatic::class)
->chunkingStrategy->type->toBe('static')
->chunkingStrategy->maxChunkSizeTokens->toBe(800)
->chunkingStrategy->chunkOverlapTokens->toBe(400);
});

test('from while missing attributes', function () {
$payload = vectorStoreFileResource();
unset($payload['attributes']);
$result = VectorStoreFileResponse::from($payload, meta());

expect($result)
->attributes->toBe([]);
});

test('as array accessible', function () {
$result = VectorStoreFileResponse::from(vectorStoreFileResource(), meta());

Expand Down