Skip to content

Commit

Permalink
assistants v2: Update array typing for assistants & vector stores
Browse files Browse the repository at this point in the history
  • Loading branch information
knash94 committed May 21, 2024
1 parent 0c7ebb5 commit 9591c6d
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 24 deletions.
8 changes: 4 additions & 4 deletions src/Resources/Assistants.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function create(array $parameters): AssistantResponse
{
$payload = Payload::create('assistants', $parameters);

/** @var Response<array{id: string, object: string, created_at: int, name: ?string, description: ?string, model: string, instructions: ?string, tools: array<int, array{type: 'code_interpreter'}|array{type: 'file_search'}|array{type: 'function', function: array{description: string, name: string, parameters: array<string, mixed>}}>, tool_resources: array<int, array{type: 'code_interpreter', function: array{file_ids: array<string>}}|array{type: 'file_search', function: array{vector_store_ids: array<string>}}>, metadata: array<string, string>, temperature: ?float, top_p: ?float, response_format: ?string|array<int, array{type: 'text'}|array{type: 'json_object'}>}> $response */
/** @var Response<array{id: string, object: string, created_at: int, name: ?string, description: ?string, model: string, instructions: ?string, tools: array<int, array{type: 'code_interpreter'}|array{type: 'file_search'}|array{type: 'function', function: array{description: string, name: string, parameters: array<string, mixed>}}>, tool_resources: array<int, array{type: 'code_interpreter', file_ids: array<string>}|array{type: 'file_search', vector_store_ids: array<int, string>}>, metadata: array<string, string>, temperature: ?float, top_p: ?float, response_format: string|array{type: 'text'}|array{type: 'json_object'}}> $response */
$response = $this->transporter->requestObject($payload);

return AssistantResponse::from($response->data(), $response->meta());
Expand All @@ -42,7 +42,7 @@ public function retrieve(string $id): AssistantResponse
{
$payload = Payload::retrieve('assistants', $id);

/** @var Response<array{id: string, object: string, created_at: int, name: ?string, description: ?string, model: string, instructions: ?string, tools: array<int, array{type: 'code_interpreter'}|array{type: 'file_search'}|array{type: 'function', function: array{description: string, name: string, parameters: array<string, mixed>}}>, tool_resources: array<int, array{type: 'code_interpreter', function: array{file_ids: array<string>}}|array{type: 'file_search', function: array{vector_store_ids: array<string>}}>, metadata: array<string, string>, temperature: ?float, top_p: ?float, response_format: ?string|array<int, array{type: 'text'}|array{type: 'json_object'}>}> $response */
/** @var Response<array{id: string, object: string, created_at: int, name: ?string, description: ?string, model: string, instructions: ?string, tools: array<int, array{type: 'code_interpreter'}|array{type: 'file_search'}|array{type: 'function', function: array{description: string, name: string, parameters: array<string, mixed>}}>, tool_resources: array<int, array{type: 'code_interpreter', file_ids: array<string>}|array{type: 'file_search', vector_store_ids: array<int, string>}>, metadata: array<string, string>, temperature: ?float, top_p: ?float, response_format: string|array{type: 'text'}|array{type: 'json_object'}}> $response */
$response = $this->transporter->requestObject($payload);

return AssistantResponse::from($response->data(), $response->meta());
Expand All @@ -59,7 +59,7 @@ public function modify(string $id, array $parameters): AssistantResponse
{
$payload = Payload::modify('assistants', $id, $parameters);

/** @var Response<array{id: string, object: string, created_at: int, name: ?string, description: ?string, model: string, instructions: ?string, tools: array<int, array{type: 'code_interpreter'}|array{type: 'file_search'}|array{type: 'function', function: array{description: string, name: string, parameters: array<string, mixed>}}>, tool_resources: array<int, array{type: 'code_interpreter', function: array{file_ids: array<string>}}|array{type: 'file_search', function: array{vector_store_ids: array<string>}}>, metadata: array<string, string>, temperature: ?float, top_p: ?float, response_format: ?string|array<int, array{type: 'text'}|array{type: 'json_object'}>}> $response */
/** @var Response<array{id: string, object: string, created_at: int, name: ?string, description: ?string, model: string, instructions: ?string, tools: array<int, array{type: 'code_interpreter'}|array{type: 'file_search'}|array{type: 'function', function: array{description: string, name: string, parameters: array<string, mixed>}}>, tool_resources: array<int, array{type: 'code_interpreter', file_ids: array<string>}|array{type: 'file_search', vector_store_ids: array<int, string>}>, metadata: array<string, string>, temperature: ?float, top_p: ?float, response_format: string|array{type: 'text'}|array{type: 'json_object'}}> $response */
$response = $this->transporter->requestObject($payload);

return AssistantResponse::from($response->data(), $response->meta());
Expand Down Expand Up @@ -91,7 +91,7 @@ public function list(array $parameters = []): AssistantListResponse
{
$payload = Payload::list('assistants', $parameters);

/** @var Response<array{object: string, data: array<int, array{id: string, object: string, created_at: int, name: ?string, description: ?string, model: string, instructions: ?string, tools: array<int, array{type: 'code_interpreter'}|array{type: 'file_search'}|array{type: 'function', function: array{description: string, name: string, parameters: array<string, mixed>}}>, tool_resources: array<int, array{type: 'code_interpreter', function: array{file_ids: array<string>}}|array{type: 'file_search', function: array{vector_store_ids: array<string>}}>, metadata: array<string, string>, temperature: ?float, top_p: ?float, response_format: ?string|array<int, array{type: 'text'}|array{type: 'json_object'}>}>}> $response */
/** @var Response<array{object: string, data: array<int, array{id: string, object: string, created_at: int, name: ?string, description: ?string, model: string, instructions: ?string, tools: array<int, array{type: 'code_interpreter'}|array{type: 'file_search'}|array{type: 'function', function: array{description: string, name: string, parameters: array<string, mixed>}}>, tool_resources: array<int, array{type: 'code_interpreter', file_ids: array<string>}|array{type: 'file_search', vector_store_ids: array<int, string>}>, metadata: array<string, string>, temperature: ?float, top_p: ?float, response_format: string|array{type: 'text'}|array{type: 'json_object'}}>, first_id: ?string, last_id: ?string, has_more: bool}> $response */
$response = $this->transporter->requestObject($payload);

return AssistantListResponse::from($response->data(), $response->meta());
Expand Down
8 changes: 4 additions & 4 deletions src/Resources/VectorStores.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function create(array $parameters): VectorStoreResponse
{
$payload = Payload::create('vector_stores', $parameters);

/** @var Response<array{id: string, object: string, created_at: int, name: ?string, usage_bytes: int, file_counts: array{in_progress: int, completed: int, failed: int, cancelled: int, total: int}, status: string, expires_after: ?array{anchor: string, days: int}, expires_at: ?int, last_active_at: ?int, metadata: <string, string>}> $response */
/** @var Response<array{id: string, object: string, created_at: int, name: ?string, usage_bytes: int, file_counts: array{in_progress: int, completed: int, failed: int, cancelled: int, total: int}, status: string, expires_after: ?array{anchor: string, days: int}, expires_at: ?int, last_active_at: ?int, metadata: array<string, string>}> $response */
$response = $this->transporter->requestObject($payload);

return VectorStoreResponse::from($response->data(), $response->meta());
Expand All @@ -42,7 +42,7 @@ public function list(): VectorStoreListResponse
{
$payload = Payload::list('vector_stores');

/** @var Response<array{id: string, object: string, created_at: int, name: ?string, usage_bytes: int, file_counts: array{in_progress: int, completed: int, failed: int, cancelled: int, total: int}, status: string, expires_after: ?array{anchor: string, days: int}, expires_at: ?int, last_active_at: ?int, metadata: <string, string>}> $response */
/** @var Response<array{object: string, data: array<int, array{id: string, object: string, created_at: int, name: ?string, usage_bytes: int, file_counts: array{in_progress: int, completed: int, failed: int, cancelled: int, total: int}, status: string, expires_after: ?array{anchor: string, days: int}, expires_at: ?int, last_active_at: ?int, metadata: array<string, string>}>, first_id: ?string, last_id: ?string, has_more: bool}> $response */
$response = $this->transporter->requestObject($payload);

return VectorStoreListResponse::from($response->data(), $response->meta());
Expand All @@ -57,7 +57,7 @@ public function retrieve(string $vectorStore): VectorStoreResponse
{
$payload = Payload::retrieve('vector_stores', $vectorStore);

/** @var Response<array{id: string, object: string, created_at: int, name: ?string, usage_bytes: int, file_counts: array{in_progress: int, completed: int, failed: int, cancelled: int, total: int}, status: string, expires_after: ?array{anchor: string, days: int}, expires_at: ?int, last_active_at: ?int, metadata: <string, string>}> $response */
/** @var Response<array{id: string, object: string, created_at: int, name: ?string, usage_bytes: int, file_counts: array{in_progress: int, completed: int, failed: int, cancelled: int, total: int}, status: string, expires_after: ?array{anchor: string, days: int}, expires_at: ?int, last_active_at: ?int, metadata: array<string, string>}> $response */
$response = $this->transporter->requestObject($payload);

return VectorStoreResponse::from($response->data(), $response->meta());
Expand All @@ -74,7 +74,7 @@ public function modify(string $vectorStore, array $parameters): VectorStoreRespo
{
$payload = Payload::modify('vector_stores', $vectorStore, $parameters);

/** @var Response<array{id: string, object: string, created_at: int, name: ?string, usage_bytes: int, file_counts: array{in_progress: int, completed: int, failed: int, cancelled: int, total: int}, status: string, expires_after: ?array{anchor: string, days: int}, expires_at: ?int, last_active_at: ?int, metadata: <string, string>}> $response */
/** @var Response<array{id: string, object: string, created_at: int, name: ?string, usage_bytes: int, file_counts: array{in_progress: int, completed: int, failed: int, cancelled: int, total: int}, status: string, expires_after: ?array{anchor: string, days: int}, expires_at: ?int, last_active_at: ?int, metadata: array<string, string>}> $response */
$response = $this->transporter->requestObject($payload);

return VectorStoreResponse::from($response->data(), $response->meta());
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/VectorStoresFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function list(string $vectorStoreId): VectorStoreFileListResponse
{
$payload = Payload::list("vector_stores/$vectorStoreId/files");

/** @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}}> $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, 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());
Expand Down
6 changes: 3 additions & 3 deletions src/Responses/Assistants/AssistantListResponse.php
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, created_at: int, name: ?string, description: ?string, model: string, instructions: ?string, tools: array<int, array{type: string}|array{type: string}|array{type: string, function: array{description: string, name: string, parameters: array<string, mixed>}}>, file_ids: array<int, string>, metadata: array<string, string>}>, first_id: ?string, last_id: ?string, has_more: bool}>
* @implements ResponseContract<array{object: string, data: array<int, array{id: string, object: string, created_at: int, name: ?string, description: ?string, model: string, instructions: ?string, tools: array<int, array{type: string}|array{type: string}|array{type: string, function: array{description: string, name: string, parameters: array<string, mixed>}}>, tool_resources: array<int, array{type: string, file_ids: array<int,string>}|array{type: string, vector_store_ids: array<int,string>}>, metadata: array<string, string>, temperature: ?float, top_p: ?float, response_format: string|array{type: string}}>, first_id: ?string, last_id: ?string, has_more: bool}>
*/
final class AssistantListResponse implements ResponseContract, ResponseHasMetaInformationContract
{
/**
* @use ArrayAccessible<array{object: string, data: array<int, array{id: string, object: string, created_at: int, name: ?string, description: ?string, model: string, instructions: ?string, tools: array<int, array{type: string}|array{type: string}|array{type: string, function: array{description: string, name: string, parameters: array<string, mixed>}}>, file_ids: array<int, string>, metadata: array<string, string>}>, first_id: ?string, last_id: ?string, has_more: bool}>
* @use ArrayAccessible<array{object: string, data: array<int, array{id: string, object: string, created_at: int, name: ?string, description: ?string, model: string, instructions: ?string, tools: array<int, array{type: string}|array{type: string}|array{type: string, function: array{description: string, name: string, parameters: array<string, mixed>}}>, tool_resources: array<int, array{type: string, file_ids: array<int,string>}|array{type: string, vector_store_ids: array<int,string>}>, metadata: array<string, string>, temperature: ?float, top_p: ?float, response_format: string|array{type: string}}>, first_id: ?string, last_id: ?string, has_more: bool}>
*/
use ArrayAccessible;

Expand All @@ -40,7 +40,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, created_at: int, name: ?string, description: ?string, model: string, instructions: ?string, tools: array<int, array{type: 'code_interpreter'}|array{type: 'file_search'}|array{type: 'function', function: array{description: string, name: string, parameters: array<string, mixed>}}>, file_ids: array<int, string>, metadata: array<string, string>}>, first_id: ?string, last_id: ?string, has_more: bool} $attributes
* @param array{object: string, data: array<int, array{id: string, object: string, created_at: int, name: ?string, description: ?string, model: string, instructions: ?string, tools: array<int, array{type: 'code_interpreter'}|array{type: 'file_search'}|array{type: 'function', function: array{description: string, name: string, parameters: array<string, mixed>}}>, tool_resources: array<int, array{type: 'code_interpreter', file_ids: array<string>}|array{type: 'file_search', vector_store_ids: array<int, string>}>, metadata: array<string, string>, temperature: ?float, top_p: ?float, response_format: string|array{type: 'text'}|array{type: 'json_object'}}>, first_id: ?string, last_id: ?string, has_more: bool} $attributes
*/
public static function from(array $attributes, MetaInformation $meta): self
{
Expand Down
5 changes: 2 additions & 3 deletions src/Responses/Assistants/AssistantResponse.php
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{id: string, object: string, created_at: int, name: ?string, description: ?string, model: string, instructions: ?string, tools: array<int, array{type: string}|array{type: string}|array{type: string, function: array{description: string, name: string, parameters: array<string, mixed>}}>, tool_resources: array<int, array{type: string, function: array{file_ids: array<string>}}|array{type: string, function: array{vector_store_ids: array<string>}}>, metadata: array<string, string>, temperature: ?float, top_p: ?float, response_format: string|array{type: string}}>
* @implements ResponseContract<array{id: string, object: string, created_at: int, name: ?string, description: ?string, model: string, instructions: ?string, tools: array<int, array{type: string}|array{type: string}|array{type: string, function: array{description: string, name: string, parameters: array<string, mixed>}}>, tool_resources: array<int, array{type: string, file_ids: array<int,string>}|array{type: string, vector_store_ids: array<int,string>}>, metadata: array<string, string>, temperature: ?float, top_p: ?float, response_format: string|array{type: string}}>
*/
final class AssistantResponse implements ResponseContract, ResponseHasMetaInformationContract
{
/**
* @use ArrayAccessible<array{ids: string, object: string, created_at: int, name: ?string, description: ?string, model: string, instructions: ?string, tools: array<int, array{type: 'code_interpreter'}|array{type: 'file_search'}|array{type: 'function', function: array{description: string, name: string, parameters: array<string, mixed>}}>, tool_resources: array<int, array{type: 'code_interpreter', function: array{file_ids: array<string>}}|array{type: 'file_search', function: array{vector_store_ids: array<string>}}>, metadata: array<string, string>, temperature: ?float, top_p: ?float, response_format: ?string|array<int, array{type: 'text'}|array{type: 'json_object'}>}>
* @use ArrayAccessible<array{id: string, object: string, created_at: int, name: ?string, description: ?string, model: string, instructions: ?string, tools: array<int, array{type: string}|array{type: string}|array{type: string, function: array{description: string, name: string, parameters: array<string, mixed>}}>, tool_resources: array<int, array{type: string, file_ids: array<int,string>}|array{type: string, vector_store_ids: array<int,string>}>, metadata: array<string, string>, temperature: ?float, top_p: ?float, response_format: string|array{type: string}}>
*/
use ArrayAccessible;

Expand All @@ -27,7 +27,6 @@ final class AssistantResponse implements ResponseContract, ResponseHasMetaInform
/**
* @param array<int, AssistantResponseToolCodeInterpreter|AssistantResponseToolFileSearch|AssistantResponseToolFunction> $tools
* @param array<int, AssistantResponseToolResourceCodeInterpreter|AssistantResponseToolResourceFileSearch> $toolResources
* @param array<int, string> $fileIds
* @param array<string, string> $metadata
*/
private function __construct(
Expand Down
Loading

0 comments on commit 9591c6d

Please sign in to comment.