Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

feat: support 'attributes' on vector store files #551

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

Merged
merged 4 commits into from
Apr 10, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
feat: support 'attributes' on vector store files
  • Loading branch information
iBotPeaches committed Apr 10, 2025
commit 5e4482673b478a1ba1641c40fe7ec4ec19ccccbd
2 changes: 1 addition & 1 deletion 2 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 6 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 12 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
6 changes: 6 additions & 0 deletions 6 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 All @@ -35,6 +38,9 @@ function vectorStoreFileWithLastErrorResource(): array
'created_at' => 1715956697,
'vector_store_id' => 'vs_xds05V7ep0QMGI5JmYnWsJwb',
'status' => 'completed',
'attributes' => [
'foo' => 'bar',
],
'last_error' => [
'code' => 'error-001',
'message' => 'Error scanning file',
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.