Skip to content

Commit

Permalink
Update assistants API to v2
Browse files Browse the repository at this point in the history
  • Loading branch information
gehrisandro committed May 26, 2024
1 parent 48be8a3 commit b74b254
Show file tree
Hide file tree
Showing 117 changed files with 1,977 additions and 1,678 deletions.
231 changes: 90 additions & 141 deletions README.md

Large diffs are not rendered by default.

9 changes: 1 addition & 8 deletions src/Contracts/Resources/AssistantsContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface AssistantsContract
/**
* Create an assistant with a model and instructions.
*
* @see https://platform.openai.com/docs/api-reference/assistants/object
* @see https://platform.openai.com/docs/api-reference/assistants/createAssistant
*
* @param array<string, mixed> $parameters
*/
Expand Down Expand Up @@ -48,11 +48,4 @@ public function delete(string $id): AssistantDeleteResponse;
* @param array<string, mixed> $parameters
*/
public function list(array $parameters = []): AssistantListResponse;

/**
* Manage files attached to an assistant.
*
* @see https://platform.openai.com/docs/api-reference/assistants
*/
public function files(): AssistantsFilesContract;
}
42 changes: 0 additions & 42 deletions src/Contracts/Resources/AssistantsFilesContract.php

This file was deleted.

7 changes: 0 additions & 7 deletions src/Contracts/Resources/ThreadsMessagesContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,4 @@ public function modify(string $threadId, string $messageId, array $parameters):
* @param array<string, mixed> $parameters
*/
public function list(string $threadId, array $parameters = []): ThreadMessageListResponse;

/**
* Manage files attached to a thread message.
*
* @see https://platform.openai.com/docs/api-reference/messages/file-object
*/
public function files(): ThreadsMessagesFilesContract;
}
25 changes: 0 additions & 25 deletions src/Contracts/Resources/ThreadsMessagesFilesContract.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/OpenAI.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static function client(string $apiKey, ?string $organization = null): Cli
return self::factory()
->withApiKey($apiKey)
->withOrganization($organization)
->withHttpHeader('OpenAI-Beta', 'assistants=v1')
->withHttpHeader('OpenAI-Beta', 'assistants=v2')
->make();
}

Expand Down
21 changes: 5 additions & 16 deletions src/Resources/Assistants.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace OpenAI\Resources;

use OpenAI\Contracts\Resources\AssistantsContract;
use OpenAI\Contracts\Resources\AssistantsFilesContract;
use OpenAI\Responses\Assistants\AssistantDeleteResponse;
use OpenAI\Responses\Assistants\AssistantListResponse;
use OpenAI\Responses\Assistants\AssistantResponse;
Expand All @@ -19,15 +18,15 @@ final class Assistants implements AssistantsContract
/**
* Create an assistant with a model and instructions.
*
* @see https://platform.openai.com/docs/api-reference/assistants/object
* @see https://platform.openai.com/docs/api-reference/assistants/createAssistant
*
* @param array<string, mixed> $parameters
*/
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: 'retrieval'}|array{type: 'function', function: array{description: string, name: string, parameters: array<string, mixed>}}>, file_ids: array<int, string>, metadata: array<string, string>}> $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{code_interpreter?: array{file_ids: array<int,string>}, file_search?: array{vector_store_ids: array<int,string>}}, metadata: array<string, string>, temperature: ?float, top_p: ?float, response_format: string|array{type: 'text'|'json_object'}}> $response */
$response = $this->transporter->requestObject($payload);

return AssistantResponse::from($response->data(), $response->meta());
Expand All @@ -42,7 +41,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: 'retrieval'}|array{type: 'function', function: array{description: string, name: string, parameters: array<string, mixed>}}>, file_ids: array<int, string>, metadata: array<string, string>}> $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{code_interpreter?: array{file_ids: array<int,string>}, file_search?: array{vector_store_ids: array<int,string>}}, metadata: array<string, string>, temperature: ?float, top_p: ?float, response_format: string|array{type: 'text'|'json_object'}}> $response */
$response = $this->transporter->requestObject($payload);

return AssistantResponse::from($response->data(), $response->meta());
Expand All @@ -59,7 +58,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: 'retrieval'}|array{type: 'function', function: array{description: string, name: string, parameters: array<string, mixed>}}>, file_ids: array<int, string>, metadata: array<string, string>}> $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{code_interpreter?: array{file_ids: array<int,string>}, file_search?: array{vector_store_ids: array<int,string>}}, metadata: array<string, string>, temperature: ?float, top_p: ?float, response_format: string|array{type: 'text'|'json_object'}}> $response */
$response = $this->transporter->requestObject($payload);

return AssistantResponse::from($response->data(), $response->meta());
Expand Down Expand Up @@ -91,19 +90,9 @@ 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: 'retrieval'}|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}> $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{code_interpreter?: array{file_ids: array<int,string>}, file_search?: array{vector_store_ids: array<int,string>}}, metadata: array<string, string>, temperature: ?float, top_p: ?float, response_format: string|array{type: 'text'|'json_object'}}>, first_id: ?string, last_id: ?string, has_more: bool}> $response */
$response = $this->transporter->requestObject($payload);

return AssistantListResponse::from($response->data(), $response->meta());
}

/**
* Manage files attached to an assistant.
*
* @see https://platform.openai.com/docs/api-reference/assistants
*/
public function files(): AssistantsFilesContract
{
return new AssistantsFiles($this->transporter);
}
}
81 changes: 0 additions & 81 deletions src/Resources/AssistantsFiles.php

This file was deleted.

8 changes: 4 additions & 4 deletions src/Resources/Threads.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function create(array $parameters): ThreadResponse
{
$payload = Payload::create('threads', $parameters);

/** @var Response<array{id: string, object: string, created_at: int, metadata: array<string, string>}> $response */
/** @var Response<array{id: string, object: string, created_at: int, tool_resources: ?array{code_interpreter?: array{file_ids: array<int,string>}, file_search?: array{vector_store_ids: array<int,string>}}, metadata: array<string, string>}> $response */
$response = $this->transporter->requestObject($payload);

return ThreadResponse::from($response->data(), $response->meta());
Expand All @@ -48,7 +48,7 @@ public function createAndRun(array $parameters): ThreadRunResponse
{
$payload = Payload::create('threads/runs', $parameters);

/** @var Response<array{id: string, object: string, created_at: int, thread_id: string, assistant_id: string, status: string, required_action?: array{type: string, submit_tool_outputs: array{tool_calls: array<int, array{id: string, type: string, function: array{name: string, arguments: string}}>}}, last_error: ?array{code: string, message: string}, expires_at: ?int, started_at: ?int, cancelled_at: ?int, failed_at: ?int, completed_at: ?int, model: string, instructions: ?string, tools: array<int, array{type: 'code_interpreter'}|array{type: 'retrieval'}|array{type: 'function', function: array{description: string, name: string, parameters: array<string, mixed>}}>, file_ids: array<int, string>, metadata: array<string, string>}> $response */
/** @var Response<array{id: string, object: string, created_at: int, thread_id: string, assistant_id: string, status: string, required_action?: array{type: string, submit_tool_outputs: array{tool_calls: array<int, array{id: string, type: string, function: array{name: string, arguments: string}}>}}, last_error: ?array{code: string, message: string}, expires_at: ?int, started_at: ?int, cancelled_at: ?int, failed_at: ?int, completed_at: ?int, 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>}}>, metadata: array<string, string>, usage?: array{prompt_tokens: int, completion_tokens: int|null, total_tokens: int}, incomplete_details: ?array{reason: string}, temperature: float|int|null, top_p: null|float|int, max_prompt_tokens: ?int, max_completion_tokens: ?int, truncation_strategy: array{type: string, last_messages: ?int}, tool_choice: string|array{type: string, function?: array{name: string}}, response_format: string|array{type: 'text'|'json_object'}}> $response */
$response = $this->transporter->requestObject($payload);

return ThreadRunResponse::from($response->data(), $response->meta());
Expand Down Expand Up @@ -82,7 +82,7 @@ public function retrieve(string $id): ThreadResponse
{
$payload = Payload::retrieve('threads', $id);

/** @var Response<array{id: string, object: string, created_at: int, metadata: array<string, string>}> $response */
/** @var Response<array{id: string, object: string, created_at: int, tool_resources: ?array{code_interpreter?: array{file_ids: array<int,string>}, file_search?: array{vector_store_ids: array<int,string>}}, metadata: array<string, string>}> $response */
$response = $this->transporter->requestObject($payload);

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

/** @var Response<array{id: string, object: string, created_at: int, metadata: array<string, string>}> $response */
/** @var Response<array{id: string, object: string, created_at: int, tool_resources: ?array{code_interpreter?: array{file_ids: array<int,string>}, file_search?: array{vector_store_ids: array<int,string>}}, metadata: array<string, string>}> $response */
$response = $this->transporter->requestObject($payload);

return ThreadResponse::from($response->data(), $response->meta());
Expand Down
Loading

0 comments on commit b74b254

Please sign in to comment.