From b8d62ce8863919cbaa356bea28bf8a1124626e69 Mon Sep 17 00:00:00 2001 From: gehrisandro Date: Fri, 10 Nov 2023 08:37:59 +0100 Subject: [PATCH] WIP: Threads Runs and Thread Runs Steps endpoints added --- src/Contracts/Resources/ThreadsContract.php | 17 +++ .../Resources/ThreadsRunsContract.php | 78 ++++++++++ .../Resources/ThreadsRunsStepsContract.php | 27 ++++ src/Resources/Threads.php | 29 ++++ src/Resources/ThreadsRuns.php | 134 ++++++++++++++++++ src/Resources/ThreadsRunsSteps.php | 52 +++++++ .../Runs/Steps/ThreadRunStepListResponse.php | 78 ++++++++++ .../Runs/Steps/ThreadRunStepResponse.php | 105 ++++++++++++++ .../ThreadRunStepResponseCodeInterpreter.php | 68 +++++++++ ...StepResponseCodeInterpreterOutputImage.php | 57 ++++++++ ...esponseCodeInterpreterOutputImageImage.php | 54 +++++++ ...nStepResponseCodeInterpreterOutputLogs.php | 57 ++++++++ .../ThreadRunStepResponseCodeToolCall.php | 60 ++++++++ .../Steps/ThreadRunStepResponseFunction.php | 60 ++++++++ .../ThreadRunStepResponseFunctionToolCall.php | 60 ++++++++ .../ThreadRunStepResponseMessageCreation.php | 57 ++++++++ ...StepResponseMessageCreationStepDetails.php | 57 ++++++++ ...ThreadRunStepResponseRetrievalToolCall.php | 60 ++++++++ ...eadRunStepResponseToolCallsStepDetails.php | 57 ++++++++ .../Threads/Runs/ThreadRunListResponse.php | 78 ++++++++++ .../Threads/Runs/ThreadRunResponse.php | 122 ++++++++++++++++ .../Runs/ThreadRunResponseLastError.php | 56 ++++++++ .../Runs/ThreadRunResponseRequiredAction.php | 58 ++++++++ ...ResponseRequiredActionFunctionToolCall.php | 59 ++++++++ ...RequiredActionFunctionToolCallFunction.php | 56 ++++++++ ...esponseRequiredActionSubmitToolOutputs.php | 55 +++++++ .../ThreadRunResponseToolCodeInterpreter.php | 53 +++++++ .../Runs/ThreadRunResponseToolFunction.php | 56 ++++++++ .../ThreadRunResponseToolFunctionFunction.php | 59 ++++++++ .../Runs/ThreadRunResponseToolRetrieval.php | 53 +++++++ 30 files changed, 1872 insertions(+) create mode 100644 src/Contracts/Resources/ThreadsRunsContract.php create mode 100644 src/Contracts/Resources/ThreadsRunsStepsContract.php create mode 100644 src/Resources/ThreadsRuns.php create mode 100644 src/Resources/ThreadsRunsSteps.php create mode 100644 src/Responses/Threads/Runs/Steps/ThreadRunStepListResponse.php create mode 100644 src/Responses/Threads/Runs/Steps/ThreadRunStepResponse.php create mode 100644 src/Responses/Threads/Runs/Steps/ThreadRunStepResponseCodeInterpreter.php create mode 100644 src/Responses/Threads/Runs/Steps/ThreadRunStepResponseCodeInterpreterOutputImage.php create mode 100644 src/Responses/Threads/Runs/Steps/ThreadRunStepResponseCodeInterpreterOutputImageImage.php create mode 100644 src/Responses/Threads/Runs/Steps/ThreadRunStepResponseCodeInterpreterOutputLogs.php create mode 100644 src/Responses/Threads/Runs/Steps/ThreadRunStepResponseCodeToolCall.php create mode 100644 src/Responses/Threads/Runs/Steps/ThreadRunStepResponseFunction.php create mode 100644 src/Responses/Threads/Runs/Steps/ThreadRunStepResponseFunctionToolCall.php create mode 100644 src/Responses/Threads/Runs/Steps/ThreadRunStepResponseMessageCreation.php create mode 100644 src/Responses/Threads/Runs/Steps/ThreadRunStepResponseMessageCreationStepDetails.php create mode 100644 src/Responses/Threads/Runs/Steps/ThreadRunStepResponseRetrievalToolCall.php create mode 100644 src/Responses/Threads/Runs/Steps/ThreadRunStepResponseToolCallsStepDetails.php create mode 100644 src/Responses/Threads/Runs/ThreadRunListResponse.php create mode 100644 src/Responses/Threads/Runs/ThreadRunResponse.php create mode 100644 src/Responses/Threads/Runs/ThreadRunResponseLastError.php create mode 100644 src/Responses/Threads/Runs/ThreadRunResponseRequiredAction.php create mode 100644 src/Responses/Threads/Runs/ThreadRunResponseRequiredActionFunctionToolCall.php create mode 100644 src/Responses/Threads/Runs/ThreadRunResponseRequiredActionFunctionToolCallFunction.php create mode 100644 src/Responses/Threads/Runs/ThreadRunResponseRequiredActionSubmitToolOutputs.php create mode 100644 src/Responses/Threads/Runs/ThreadRunResponseToolCodeInterpreter.php create mode 100644 src/Responses/Threads/Runs/ThreadRunResponseToolFunction.php create mode 100644 src/Responses/Threads/Runs/ThreadRunResponseToolFunctionFunction.php create mode 100644 src/Responses/Threads/Runs/ThreadRunResponseToolRetrieval.php diff --git a/src/Contracts/Resources/ThreadsContract.php b/src/Contracts/Resources/ThreadsContract.php index a8318bed..a7cc7997 100644 --- a/src/Contracts/Resources/ThreadsContract.php +++ b/src/Contracts/Resources/ThreadsContract.php @@ -5,6 +5,7 @@ use OpenAI\Responses\Assistants\AssistantDeleteResponse; use OpenAI\Responses\Assistants\AssistantListResponse; use OpenAI\Responses\Assistants\AssistantResponse; +use OpenAI\Responses\Threads\Runs\ThreadRunResponse; use OpenAI\Responses\Threads\ThreadDeleteResponse; use OpenAI\Responses\Threads\ThreadListResponse; use OpenAI\Responses\Threads\ThreadResponse; @@ -20,6 +21,15 @@ interface ThreadsContract */ public function create(array $parameters): ThreadResponse; + /** + * Create a thread and run it in one request. + * + * @see https://platform.openai.com/docs/api-reference/runs/createThreadAndRun + * + * @param array $parameters + */ + public function createAndRun(array $parameters): ThreadRunResponse; + /** * Retrieves a thread. * @@ -58,4 +68,11 @@ public function list(array $parameters = []): ThreadListResponse; * @see https://platform.openai.com/docs/api-reference/messages */ public function messages(): ThreadsMessagesContract; + + /** + * Represents an execution run on a thread. + * + * @see https://platform.openai.com/docs/api-reference/runs + */ + public function runs(): ThreadsRunsContract; } diff --git a/src/Contracts/Resources/ThreadsRunsContract.php b/src/Contracts/Resources/ThreadsRunsContract.php new file mode 100644 index 00000000..08522272 --- /dev/null +++ b/src/Contracts/Resources/ThreadsRunsContract.php @@ -0,0 +1,78 @@ + $parameters + */ + public function create(string $threadId, array $parameters): ThreadRunResponse; + + /** + * Retrieves a run. + * + * @see https://platform.openai.com/docs/api-reference/runs/getRun + */ + public function retrieve(string $threadId, string $runId): ThreadRunResponse; + + /** + * Modifies a run. + * + * @see https://platform.openai.com/docs/api-reference/runs/modifyRun + * + * @param array $parameters + */ + public function modify(string $threadId, string $runId, array $parameters): ThreadRunResponse; + + /** + * This endpoint can be used to submit the outputs from the tool calls once they're all completed. + * + * @see https://platform.openai.com/docs/api-reference/runs/submitToolOutputs + * + * @param array $parameters + */ + public function submitToolOutputs(string $threadId, string $runId, array $parameters): ThreadRunResponse; + + /** + * Cancels a run that is `in_progress`. + * + * @see https://platform.openai.com/docs/api-reference/runs/cancelRun + * + * @param array $parameters + */ + public function cancel(string $threadId, string $runId): ThreadRunResponse; + +// /** +// * Delete an message. +// * +// * @see TBD - there is no documentation yet +// */ +// public function delete(string $threadId, string $messageId): ThreadMessageDeleteResponse; + + /** + * Returns a list of runs belonging to a thread. + * + * @see https://platform.openai.com/docs/api-reference/runs/listRuns + * + * @param array $parameters + */ + public function list(string $threadId, array $parameters = []): ThreadRunListResponse; + + /** + * Get steps attached to a run. + * + * @see https://platform.openai.com/docs/api-reference/runs/step-object + */ + public function steps(): ThreadsRunsStepsContract; +} diff --git a/src/Contracts/Resources/ThreadsRunsStepsContract.php b/src/Contracts/Resources/ThreadsRunsStepsContract.php new file mode 100644 index 00000000..efc9f0cf --- /dev/null +++ b/src/Contracts/Resources/ThreadsRunsStepsContract.php @@ -0,0 +1,27 @@ + $parameters + */ + public function list(string $threadId, string $runId, array $parameters = []): ThreadRunStepListResponse; +} diff --git a/src/Resources/Threads.php b/src/Resources/Threads.php index 9c6b3eed..f39694ec 100644 --- a/src/Resources/Threads.php +++ b/src/Resources/Threads.php @@ -9,9 +9,11 @@ use OpenAI\Contracts\Resources\ListAssistantsResponse; use OpenAI\Contracts\Resources\ThreadsContract; use OpenAI\Contracts\Resources\ThreadsMessagesContract; +use OpenAI\Contracts\Resources\ThreadsRunsContract; use OpenAI\Responses\Assistants\AssistantDeleteResponse; use OpenAI\Responses\Assistants\AssistantListResponse; use OpenAI\Responses\Assistants\AssistantResponse; +use OpenAI\Responses\Threads\Runs\ThreadRunResponse; use OpenAI\Responses\Threads\ThreadDeleteResponse; use OpenAI\Responses\Threads\ThreadListResponse; use OpenAI\Responses\Threads\ThreadResponse; @@ -39,6 +41,23 @@ public function create(array $parameters): ThreadResponse return ThreadResponse::from($response->data(), $response->meta()); } + /** + * Create a thread and run it in one request. + * + * @see https://platform.openai.com/docs/api-reference/runs/createThreadAndRun + * + * @param array $parameters + */ + public function createAndRun(array $parameters): ThreadRunResponse + { + $payload = Payload::create('threads/runs', $parameters); + + /** @var Response}> $response */ + $response = $this->transporter->requestObject($payload); + + return ThreadRunResponse::from($response->data(), $response->meta()); + } + /** * Retrieves a thread. * @@ -112,4 +131,14 @@ public function messages(): ThreadsMessagesContract { return new ThreadsMessages($this->transporter); } + + /** + * Represents an execution run on a thread. + * + * @see https://platform.openai.com/docs/api-reference/runs + */ + public function runs(): ThreadsRunsContract + { + return new ThreadsRuns($this->transporter); + } } diff --git a/src/Resources/ThreadsRuns.php b/src/Resources/ThreadsRuns.php new file mode 100644 index 00000000..f3bebb60 --- /dev/null +++ b/src/Resources/ThreadsRuns.php @@ -0,0 +1,134 @@ + $parameters + */ + public function create(string $threadId, array $parameters): ThreadRunResponse + { + $payload = Payload::create('threads/'.$threadId.'/runs', $parameters); + + /** @var Response}> $response */ + $response = $this->transporter->requestObject($payload); + + return ThreadRunResponse::from($response->data(), $response->meta()); + } + + /** + * Retrieves a run. + * + * @see https://platform.openai.com/docs/api-reference/runs/getRun + */ + public function retrieve(string $threadId, string $runId): ThreadRunResponse + { + $payload = Payload::retrieve('threads/'.$threadId.'/runs', $runId); + + /** @var Response}> $response */ + $response = $this->transporter->requestObject($payload); + + return ThreadRunResponse::from($response->data(), $response->meta()); + } + + /** + * Modifies a run. + * + * @see https://platform.openai.com/docs/api-reference/runs/modifyRun + * + * @param array $parameters + */ + public function modify(string $threadId, string $runId, array $parameters): ThreadRunResponse + { + $payload = Payload::modify('threads/'.$threadId.'/runs', $runId, $parameters); + + /** @var Response}> $response */ + $response = $this->transporter->requestObject($payload); + + return ThreadRunResponse::from($response->data(), $response->meta()); + } + + /** + * This endpoint can be used to submit the outputs from the tool calls once they're all completed. + * + * @see https://platform.openai.com/docs/api-reference/runs/submitToolOutputs + * + * @param array $parameters + */ + public function submitToolOutputs(string $threadId, string $runId, array $parameters): ThreadRunResponse + { + $payload = Payload::create('threads/'.$threadId.'/runs/'.$runId.'/submit_tool_outputs', $parameters); + + /** @var Response}> $response */ + $response = $this->transporter->requestObject($payload); + + return ThreadRunResponse::from($response->data(), $response->meta()); + } + + /** + * Cancels a run that is `in_progress`. + * + * @see https://platform.openai.com/docs/api-reference/runs/cancelRun + * + * @param array $parameters + */ + public function cancel(string $threadId, string $runId): ThreadRunResponse + { + $payload = Payload::cancel('threads/'.$threadId.'/runs', $runId); + + /** @var Response}> $response */ + $response = $this->transporter->requestObject($payload); + + return ThreadRunResponse::from($response->data(), $response->meta()); + } + + /** + * Returns a list of runs belonging to a thread. + * + * @see https://platform.openai.com/docs/api-reference/runs/listRuns + * + * @param array $parameters + */ + public function list(string $threadId, array $parameters = []): ThreadRunListResponse + { + $payload = Payload::list('threads/'.$threadId.'/runs', $parameters); + + /** @var Response}> $response */ + $response = $this->transporter->requestObject($payload); + + return ThreadRunListResponse::from($response->data(), $response->meta()); + } + + /** + * Get steps attached to a run. + * + * @see https://platform.openai.com/docs/api-reference/runs/step-object + */ + public function steps(): ThreadsRunsStepsContract + { + return new ThreadsRunsSteps($this->transporter); + } +} diff --git a/src/Resources/ThreadsRunsSteps.php b/src/Resources/ThreadsRunsSteps.php new file mode 100644 index 00000000..f9e49364 --- /dev/null +++ b/src/Resources/ThreadsRunsSteps.php @@ -0,0 +1,52 @@ +}> $response */ + $response = $this->transporter->requestObject($payload); + + return ThreadRunStepResponse::from($response->data(), $response->meta()); + } + + /** + * Returns a list of run steps belonging to a run. + * + * @see https://platform.openai.com/docs/api-reference/runs/listRunSteps + * + * @param array $parameters + */ + public function list(string $threadId, string $runId, array $parameters = []): ThreadRunStepListResponse + { + $payload = Payload::list('threads/'.$threadId.'/runs/'.$runId.'/steps', $parameters); + + /** @var Response}> $response */ + $response = $this->transporter->requestObject($payload); + + return ThreadRunStepListResponse::from($response->data(), $response->meta()); + } +} diff --git a/src/Responses/Threads/Runs/Steps/ThreadRunStepListResponse.php b/src/Responses/Threads/Runs/Steps/ThreadRunStepListResponse.php new file mode 100644 index 00000000..8db043e5 --- /dev/null +++ b/src/Responses/Threads/Runs/Steps/ThreadRunStepListResponse.php @@ -0,0 +1,78 @@ +, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int}>, has_more: bool}> + */ +final class ThreadRunStepListResponse implements ResponseContract, ResponseHasMetaInformationContract +{ + /** + * @use ArrayAccessible, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int}>, has_more: bool}> + */ + use ArrayAccessible; + + use Fakeable; + use HasMetaInformation; + + /** + * @param array $data + */ + private function __construct( + public readonly string $object, + public readonly array $data, + public readonly ?string $firstId, + public readonly ?string $lastId, + public readonly bool $hasMore, + private readonly MetaInformation $meta, + ) { + } + + /** + * Acts as static factory, and returns a new Response instance. + * + * @param array{object: string, data: array, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int}>, has_more: bool} $attributes + */ + public static function from(array $attributes, MetaInformation $meta): self + { + $data = array_map(fn (array $result): ThreadRunStepResponse => ThreadRunStepResponse::from( + $result, + $meta, + ), $attributes['data']); + + return new self( + $attributes['object'], + $data, + $attributes['first_id'], + $attributes['last_id'], + $attributes['has_more'], + $meta, + ); + } + + /** + * {@inheritDoc} + */ + public function toArray(): array + { + return [ + 'object' => $this->object, + 'data' => array_map( + static fn (ThreadRunStepResponse $response): array => $response->toArray(), + $this->data, + ), + 'first_id' => $this->firstId, + 'last_id' => $this->lastId, + 'has_more' => $this->hasMore, + ]; + } +} diff --git a/src/Responses/Threads/Runs/Steps/ThreadRunStepResponse.php b/src/Responses/Threads/Runs/Steps/ThreadRunStepResponse.php new file mode 100644 index 00000000..4c74ce66 --- /dev/null +++ b/src/Responses/Threads/Runs/Steps/ThreadRunStepResponse.php @@ -0,0 +1,105 @@ +, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> + */ +final class ThreadRunStepResponse implements ResponseContract +{ + /** + * @use ArrayAccessible, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> + */ + use ArrayAccessible; + + use Fakeable; + use HasMetaInformation; + + private function __construct( + public string $id, + public string $object, + public int $createdAt, + public string $threadId, + public string $assistantId, + public string $runId, + public string $type, + public string $status, + public ThreadRunStepResponseMessageCreationStepDetails|ThreadRunStepResponseToolCallsStepDetails $stepDetails, + public ?ThreadRunResponseLastError $lastError, + public ?int $expiresAt, + public ?int $cancelledAt, + public ?int $failedAt, + public ?int $completedAt, + public array $metadata, + private readonly MetaInformation $meta, + ) + { + } + + /** + * Acts as static factory, and returns a new Response instance. + * + * @param array{task: ?string, language: ?string, duration: ?float, segments: array, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}|string $attributes + */ + public static function from(array|string $attributes, MetaInformation $meta): self + { + $stepDetails = match ($attributes['step_details']['type']) { + 'message_creation' => ThreadRunStepResponseMessageCreationStepDetails::from($attributes['step_details']), + 'tool_calls' => ThreadRunStepResponseToolCallsStepDetails::from($attributes['step_details']), + }; + + return new self( + $attributes['id'], + $attributes['object'], + $attributes['created_at'], + $attributes['thread_id'], + $attributes['assistant_id'], + $attributes['run_id'], + $attributes['type'], + $attributes['status'], + $stepDetails, + isset($attributes['last_error']) ? ThreadRunResponseLastError::from($attributes['last_error']) : null, + $attributes['expires_at'], + $attributes['cancelled_at'], + $attributes['failed_at'], + $attributes['completed_at'], + $attributes['metadata'] ?? [], + $meta, + ); + } + + /** + * {@inheritDoc} + */ + public function toArray(): array + { + return [ + 'id' => $this->id, + 'object' => $this->object, + 'created_at' => $this->createdAt, + 'thread_id' => $this->threadId, + 'assistant_id' => $this->assistantId, + 'run_id' => $this->runId, + 'type' => $this->type, + 'status' => $this->status, + 'step_details' => $this->stepDetails?->toArray(), + 'last_error' => $this->lastError?->toArray(), + 'expires_at' => $this->expiresAt, + 'cancelled_at' => $this->cancelledAt, + 'failed_at' => $this->failedAt, + 'completed_at' => $this->completedAt, + 'metadata' => $this->metadata, + ]; + } +} diff --git a/src/Responses/Threads/Runs/Steps/ThreadRunStepResponseCodeInterpreter.php b/src/Responses/Threads/Runs/Steps/ThreadRunStepResponseCodeInterpreter.php new file mode 100644 index 00000000..670a6981 --- /dev/null +++ b/src/Responses/Threads/Runs/Steps/ThreadRunStepResponseCodeInterpreter.php @@ -0,0 +1,68 @@ +, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> + */ +final class ThreadRunStepResponseCodeInterpreter implements ResponseContract +{ + /** + * @use ArrayAccessible, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> + */ + use ArrayAccessible; + + use Fakeable; + + /** + * @param array $outputs + */ + private function __construct( + public string $input, + public array $outputs, + ) + { + } + + /** + * Acts as static factory, and returns a new Response instance. + * + * @param array{task: ?string, language: ?string, duration: ?float, segments: array, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}|string $attributes + */ + public static function from(array|string $attributes): self + { + $outputs = array_map( + fn (array $output) => match ($output['type']) { + 'image' => ThreadRunStepResponseCodeInterpreterOutputImage::from($output), + 'logs' => ThreadRunStepResponseCodeInterpreterOutputLogs::from($output), + }, + $attributes['outputs'], + ); + + return new self( + $attributes['input'], + $outputs, + ); + } + + /** + * {@inheritDoc} + */ + public function toArray(): array + { + return [ + 'input' => $this->input, + 'outputs' => array_map( + fn (ThreadRunStepResponseCodeInterpreterOutputImage|ThreadRunStepResponseCodeInterpreterOutputLogs $output) => $output->toArray(), + $this->outputs, + ), + ]; + } +} diff --git a/src/Responses/Threads/Runs/Steps/ThreadRunStepResponseCodeInterpreterOutputImage.php b/src/Responses/Threads/Runs/Steps/ThreadRunStepResponseCodeInterpreterOutputImage.php new file mode 100644 index 00000000..fed1f359 --- /dev/null +++ b/src/Responses/Threads/Runs/Steps/ThreadRunStepResponseCodeInterpreterOutputImage.php @@ -0,0 +1,57 @@ +, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> + */ +final class ThreadRunStepResponseCodeInterpreterOutputImage implements ResponseContract +{ + /** + * @use ArrayAccessible, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> + */ + use ArrayAccessible; + + use Fakeable; + + /** + * @param array $outputs + */ + private function __construct( + public string $type, + public ThreadRunStepResponseCodeInterpreterOutputImageImage $image, + ) + { + } + + /** + * Acts as static factory, and returns a new Response instance. + * + * @param array{task: ?string, language: ?string, duration: ?float, segments: array, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}|string $attributes + */ + public static function from(array|string $attributes): self + { + return new self( + $attributes['type'], + ThreadRunStepResponseCodeInterpreterOutputImageImage::from($attributes['image']), + ); + } + + /** + * {@inheritDoc} + */ + public function toArray(): array + { + return [ + 'type' => $this->type, + 'image' => $this->image->toArray(), + ]; + } +} diff --git a/src/Responses/Threads/Runs/Steps/ThreadRunStepResponseCodeInterpreterOutputImageImage.php b/src/Responses/Threads/Runs/Steps/ThreadRunStepResponseCodeInterpreterOutputImageImage.php new file mode 100644 index 00000000..085bdf3e --- /dev/null +++ b/src/Responses/Threads/Runs/Steps/ThreadRunStepResponseCodeInterpreterOutputImageImage.php @@ -0,0 +1,54 @@ +, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> + */ +final class ThreadRunStepResponseCodeInterpreterOutputImageImage implements ResponseContract +{ + /** + * @use ArrayAccessible, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> + */ + use ArrayAccessible; + + use Fakeable; + + /** + * @param array $outputs + */ + private function __construct( + public string $fileId, + ) + { + } + + /** + * Acts as static factory, and returns a new Response instance. + * + * @param array{task: ?string, language: ?string, duration: ?float, segments: array, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}|string $attributes + */ + public static function from(array|string $attributes): self + { + return new self( + $attributes['file_id'], + ); + } + + /** + * {@inheritDoc} + */ + public function toArray(): array + { + return [ + 'file_id' => $this->fileId, + ]; + } +} diff --git a/src/Responses/Threads/Runs/Steps/ThreadRunStepResponseCodeInterpreterOutputLogs.php b/src/Responses/Threads/Runs/Steps/ThreadRunStepResponseCodeInterpreterOutputLogs.php new file mode 100644 index 00000000..84ff8b1d --- /dev/null +++ b/src/Responses/Threads/Runs/Steps/ThreadRunStepResponseCodeInterpreterOutputLogs.php @@ -0,0 +1,57 @@ +, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> + */ +final class ThreadRunStepResponseCodeInterpreterOutputLogs implements ResponseContract +{ + /** + * @use ArrayAccessible, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> + */ + use ArrayAccessible; + + use Fakeable; + + /** + * @param array $outputs + */ + private function __construct( + public string $type, + public string $logs, + ) + { + } + + /** + * Acts as static factory, and returns a new Response instance. + * + * @param array{task: ?string, language: ?string, duration: ?float, segments: array, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}|string $attributes + */ + public static function from(array|string $attributes): self + { + return new self( + $attributes['type'], + $attributes['logs'], + ); + } + + /** + * {@inheritDoc} + */ + public function toArray(): array + { + return [ + 'type' => $this->type, + 'logs' => $this->logs, + ]; + } +} diff --git a/src/Responses/Threads/Runs/Steps/ThreadRunStepResponseCodeToolCall.php b/src/Responses/Threads/Runs/Steps/ThreadRunStepResponseCodeToolCall.php new file mode 100644 index 00000000..5682da8e --- /dev/null +++ b/src/Responses/Threads/Runs/Steps/ThreadRunStepResponseCodeToolCall.php @@ -0,0 +1,60 @@ +, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> + */ +final class ThreadRunStepResponseCodeToolCall implements ResponseContract +{ + /** + * @use ArrayAccessible, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> + */ + use ArrayAccessible; + + use Fakeable; + + /** + * @param array $tools + */ + private function __construct( + public string $id, + public string $type, + public ThreadRunStepResponseCodeInterpreter $codeInterpreter, + ) + { + } + + /** + * Acts as static factory, and returns a new Response instance. + * + * @param array{task: ?string, language: ?string, duration: ?float, segments: array, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}|string $attributes + */ + public static function from(array|string $attributes): self + { + return new self( + $attributes['id'], + $attributes['type'], + ThreadRunStepResponseCodeInterpreter::from($attributes['code_interpreter']), + ); + } + + /** + * {@inheritDoc} + */ + public function toArray(): array + { + return [ + 'id' => $this->id, + 'type' => $this->type, + 'code_interpreter' => $this->codeInterpreter->toArray(), + ]; + } +} diff --git a/src/Responses/Threads/Runs/Steps/ThreadRunStepResponseFunction.php b/src/Responses/Threads/Runs/Steps/ThreadRunStepResponseFunction.php new file mode 100644 index 00000000..844b0160 --- /dev/null +++ b/src/Responses/Threads/Runs/Steps/ThreadRunStepResponseFunction.php @@ -0,0 +1,60 @@ +, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> + */ +final class ThreadRunStepResponseFunction implements ResponseContract +{ + /** + * @use ArrayAccessible, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> + */ + use ArrayAccessible; + + use Fakeable; + + /** + * @param array $tools + */ + private function __construct( + public string $name, + public string $arguments, + public ?string $output, + ) + { + } + + /** + * Acts as static factory, and returns a new Response instance. + * + * @param array{task: ?string, language: ?string, duration: ?float, segments: array, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}|string $attributes + */ + public static function from(array|string $attributes): self + { + return new self( + $attributes['name'], + $attributes['arguments'], + $attributes['output'], + ); + } + + /** + * {@inheritDoc} + */ + public function toArray(): array + { + return [ + 'name' => $this->name, + 'arguments' => $this->arguments, + 'output' => $this->output, + ]; + } +} diff --git a/src/Responses/Threads/Runs/Steps/ThreadRunStepResponseFunctionToolCall.php b/src/Responses/Threads/Runs/Steps/ThreadRunStepResponseFunctionToolCall.php new file mode 100644 index 00000000..2333930c --- /dev/null +++ b/src/Responses/Threads/Runs/Steps/ThreadRunStepResponseFunctionToolCall.php @@ -0,0 +1,60 @@ +, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> + */ +final class ThreadRunStepResponseFunctionToolCall implements ResponseContract +{ + /** + * @use ArrayAccessible, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> + */ + use ArrayAccessible; + + use Fakeable; + + /** + * @param array $tools + */ + private function __construct( + public string $id, + public string $type, + public ThreadRunStepResponseFunction $function, + ) + { + } + + /** + * Acts as static factory, and returns a new Response instance. + * + * @param array{task: ?string, language: ?string, duration: ?float, segments: array, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}|string $attributes + */ + public static function from(array|string $attributes): self + { + return new self( + $attributes['id'], + $attributes['type'], + ThreadRunStepResponseFunction::from($attributes['function']), + ); + } + + /** + * {@inheritDoc} + */ + public function toArray(): array + { + return [ + 'id' => $this->id, + 'type' => $this->type, + 'function' => $this->function->toArray(), + ]; + } +} diff --git a/src/Responses/Threads/Runs/Steps/ThreadRunStepResponseMessageCreation.php b/src/Responses/Threads/Runs/Steps/ThreadRunStepResponseMessageCreation.php new file mode 100644 index 00000000..325b3a39 --- /dev/null +++ b/src/Responses/Threads/Runs/Steps/ThreadRunStepResponseMessageCreation.php @@ -0,0 +1,57 @@ +, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> + */ +final class ThreadRunStepResponseMessageCreation implements ResponseContract +{ + /** + * @use ArrayAccessible, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> + */ + use ArrayAccessible; + + use Fakeable; + + /** + * @param array $tools + */ + private function __construct( + public string $messageId, + ) + { + } + + /** + * Acts as static factory, and returns a new Response instance. + * + * @param array{task: ?string, language: ?string, duration: ?float, segments: array, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}|string $attributes + */ + public static function from(array|string $attributes): self + { + return new self( + $attributes['message_id'], + ); + } + + /** + * {@inheritDoc} + */ + public function toArray(): array + { + return [ + 'message_id' => $this->messageId, + ]; + } +} diff --git a/src/Responses/Threads/Runs/Steps/ThreadRunStepResponseMessageCreationStepDetails.php b/src/Responses/Threads/Runs/Steps/ThreadRunStepResponseMessageCreationStepDetails.php new file mode 100644 index 00000000..a836a8ae --- /dev/null +++ b/src/Responses/Threads/Runs/Steps/ThreadRunStepResponseMessageCreationStepDetails.php @@ -0,0 +1,57 @@ +, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> + */ +final class ThreadRunStepResponseMessageCreationStepDetails implements ResponseContract +{ + /** + * @use ArrayAccessible, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> + */ + use ArrayAccessible; + + use Fakeable; + + /** + * @param array $tools + */ + private function __construct( + public string $type, + public ThreadRunStepResponseMessageCreation $messageCreation, + ) + { + } + + /** + * Acts as static factory, and returns a new Response instance. + * + * @param array{task: ?string, language: ?string, duration: ?float, segments: array, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}|string $attributes + */ + public static function from(array|string $attributes): self + { + return new self( + $attributes['type'], + ThreadRunStepResponseMessageCreation::from($attributes['message_creation']), + ); + } + + /** + * {@inheritDoc} + */ + public function toArray(): array + { + return [ + 'type' => $this->type, + 'message_creation' => $this->messageCreation->toArray(), + ]; + } +} diff --git a/src/Responses/Threads/Runs/Steps/ThreadRunStepResponseRetrievalToolCall.php b/src/Responses/Threads/Runs/Steps/ThreadRunStepResponseRetrievalToolCall.php new file mode 100644 index 00000000..683a9904 --- /dev/null +++ b/src/Responses/Threads/Runs/Steps/ThreadRunStepResponseRetrievalToolCall.php @@ -0,0 +1,60 @@ +, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> + */ +final class ThreadRunStepResponseRetrievalToolCall implements ResponseContract +{ + /** + * @use ArrayAccessible, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> + */ + use ArrayAccessible; + + use Fakeable; + + /** + * @param array $tools + */ + private function __construct( + public string $id, + public string $type, + public array $retrieval, + ) + { + } + + /** + * Acts as static factory, and returns a new Response instance. + * + * @param array{task: ?string, language: ?string, duration: ?float, segments: array, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}|string $attributes + */ + public static function from(array|string $attributes): self + { + return new self( + $attributes['id'], + $attributes['type'], + $attributes['retrieval'], + ); + } + + /** + * {@inheritDoc} + */ + public function toArray(): array + { + return [ + 'id' => $this->id, + 'type' => $this->type, + 'retrieval' => $this->retrieval, + ]; + } +} diff --git a/src/Responses/Threads/Runs/Steps/ThreadRunStepResponseToolCallsStepDetails.php b/src/Responses/Threads/Runs/Steps/ThreadRunStepResponseToolCallsStepDetails.php new file mode 100644 index 00000000..d6ca8df2 --- /dev/null +++ b/src/Responses/Threads/Runs/Steps/ThreadRunStepResponseToolCallsStepDetails.php @@ -0,0 +1,57 @@ +, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> + */ +final class ThreadRunStepResponseToolCallsStepDetails implements ResponseContract +{ + /** + * @use ArrayAccessible, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> + */ + use ArrayAccessible; + + use Fakeable; + + /** + * @param array $tools + */ + private function __construct( + public string $type, + public array $toolCalls, + ) + { + } + + /** + * Acts as static factory, and returns a new Response instance. + * + * @param array{task: ?string, language: ?string, duration: ?float, segments: array, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}|string $attributes + */ + public static function from(array|string $attributes): self + { + return new self( + $attributes['type'], + ThreadRunStepResponseMessageCreation::from($attributes['message_creation']), + ); + } + + /** + * {@inheritDoc} + */ + public function toArray(): array + { + return [ + 'type' => $this->type, + 'message_creation' => $this->messageCreation->toArray(), + ]; + } +} diff --git a/src/Responses/Threads/Runs/ThreadRunListResponse.php b/src/Responses/Threads/Runs/ThreadRunListResponse.php new file mode 100644 index 00000000..fdcb5bf8 --- /dev/null +++ b/src/Responses/Threads/Runs/ThreadRunListResponse.php @@ -0,0 +1,78 @@ +, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int}>, has_more: bool}> + */ +final class ThreadRunListResponse implements ResponseContract, ResponseHasMetaInformationContract +{ + /** + * @use ArrayAccessible, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int}>, has_more: bool}> + */ + use ArrayAccessible; + + use Fakeable; + use HasMetaInformation; + + /** + * @param array $data + */ + private function __construct( + public readonly string $object, + public readonly array $data, + public readonly ?string $firstId, + public readonly ?string $lastId, + public readonly bool $hasMore, + private readonly MetaInformation $meta, + ) { + } + + /** + * Acts as static factory, and returns a new Response instance. + * + * @param array{object: string, data: array, status: string, validation_file: ?string, training_file: string, trained_tokens: ?int}>, has_more: bool} $attributes + */ + public static function from(array $attributes, MetaInformation $meta): self + { + $data = array_map(fn (array $result): ThreadRunResponse => ThreadRunResponse::from( + $result, + $meta, + ), $attributes['data']); + + return new self( + $attributes['object'], + $data, + $attributes['first_id'], + $attributes['last_id'], + $attributes['has_more'], + $meta, + ); + } + + /** + * {@inheritDoc} + */ + public function toArray(): array + { + return [ + 'object' => $this->object, + 'data' => array_map( + static fn (ThreadRunResponse $response): array => $response->toArray(), + $this->data, + ), + 'first_id' => $this->firstId, + 'last_id' => $this->lastId, + 'has_more' => $this->hasMore, + ]; + } +} diff --git a/src/Responses/Threads/Runs/ThreadRunResponse.php b/src/Responses/Threads/Runs/ThreadRunResponse.php new file mode 100644 index 00000000..a9e9ab49 --- /dev/null +++ b/src/Responses/Threads/Runs/ThreadRunResponse.php @@ -0,0 +1,122 @@ +, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> + */ +final class ThreadRunResponse implements ResponseContract, ResponseHasMetaInformationContract +{ + /** + * @use ArrayAccessible, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> + */ + use ArrayAccessible; + + use Fakeable; + use HasMetaInformation; + + /** + * @param array $tools + */ + private function __construct( + public string $id, + public string $object, + public int $createdAt, + public string $threadId, + public string $assistantId, + public string $status, + public ?ThreadRunResponseRequiredAction $requiredAction, + public ?ThreadRunResponseLastError $lastError, + public ?int $expiresAt, + public ?int $startedAt, + public ?int $cancelledAt, + public ?int $failedAt, + public ?int $completedAt, + public string $model, + public string $instructions, + public array $tools, + public array $fileIds, + public array $metadata, + private readonly MetaInformation $meta, + ) + { + } + + /** + * Acts as static factory, and returns a new Response instance. + * + * @param array{task: ?string, language: ?string, duration: ?float, segments: array, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}|string $attributes + */ + public static function from(array|string $attributes, MetaInformation $meta): self + { + $tools = array_map( + fn (array $tool) => match ($tool['type']) { + 'code_interpreter' => ThreadRunResponseToolCodeInterpreter::from($tool), + 'retrieval' => ThreadRunResponseToolRetrieval::from($tool), + 'function' => ThreadRunResponseToolFunction::from($tool), + }, + $attributes['tools'], + ); + + return new self( + $attributes['id'], + $attributes['object'], + $attributes['created_at'], + $attributes['thread_id'], + $attributes['assistant_id'], + $attributes['status'], + isset($attributes['required_action']) ? ThreadRunResponseRequiredAction::from($attributes['required_action']) : null, + isset($attributes['last_error']) ? ThreadRunResponseLastError::from($attributes['last_error']) : null, + $attributes['expires_at'], + $attributes['started_at'], + $attributes['cancelled_at'], + $attributes['failed_at'], + $attributes['completed_at'], + $attributes['model'], + $attributes['instructions'], + $tools, + $attributes['file_ids'], + $attributes['metadata'], + $meta, + ); + } + + /** + * {@inheritDoc} + */ + public function toArray(): array + { + return [ + 'id' => $this->id, + 'object' => $this->object, + 'created_at' => $this->createdAt, + 'thread_id' => $this->threadId, + 'assistant_id' => $this->assistantId, + 'status' => $this->status, + 'required_action' => $this->requiredAction?->toArray(), + 'last_error' => $this->lastError?->toArray(), + 'expires_at' => $this->expiresAt, + 'started_at' => $this->startedAt, + 'cancelled_at' => $this->cancelledAt, + 'failed_at' => $this->failedAt, + 'completed_at' => $this->completedAt, + 'model' => $this->model, + 'instructions' => $this->instructions, + 'tools' => array_map( + fn (ThreadRunResponseToolCodeInterpreter|ThreadRunResponseToolRetrieval|ThreadRunResponseToolFunction $tool) => $tool->toArray(), + $this->tools, + ), + 'file_ids' => $this->fileIds, + 'metadata' => $this->metadata, + ]; + } +} diff --git a/src/Responses/Threads/Runs/ThreadRunResponseLastError.php b/src/Responses/Threads/Runs/ThreadRunResponseLastError.php new file mode 100644 index 00000000..f431f37e --- /dev/null +++ b/src/Responses/Threads/Runs/ThreadRunResponseLastError.php @@ -0,0 +1,56 @@ +, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> + */ +final class ThreadRunResponseLastError implements ResponseContract +{ + /** + * @use ArrayAccessible, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> + */ + use ArrayAccessible; + + use Fakeable; + + /** + * @param array $segments + */ + private function __construct( + public string $code, + public string $message, + ) + { + } + + /** + * Acts as static factory, and returns a new Response instance. + * + * @param array{task: ?string, language: ?string, duration: ?float, segments: array, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}|string $attributes + */ + public static function from(array|string $attributes): self + { + return new self( + $attributes['code'], + $attributes['message'], + ); + } + + /** + * {@inheritDoc} + */ + public function toArray(): array + { + return [ + 'code' => $this->code, + 'message' => $this->message, + ]; + } +} diff --git a/src/Responses/Threads/Runs/ThreadRunResponseRequiredAction.php b/src/Responses/Threads/Runs/ThreadRunResponseRequiredAction.php new file mode 100644 index 00000000..7499892f --- /dev/null +++ b/src/Responses/Threads/Runs/ThreadRunResponseRequiredAction.php @@ -0,0 +1,58 @@ +, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> + */ +final class ThreadRunResponseRequiredAction implements ResponseContract +{ + /** + * @use ArrayAccessible, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> + */ + use ArrayAccessible; + + use Fakeable; + + /** + * @param array $segments + */ + private function __construct( + public string $type, + public ThreadRunResponseRequiredActionSubmitToolOutputs $submitToolOutputs, + ) + { + } + + /** + * Acts as static factory, and returns a new Response instance. + * + * @param array{task: ?string, language: ?string, duration: ?float, segments: array, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}|string $attributes + */ + public static function from(array|string $attributes): self + { + return new self( + $attributes['type'], + ThreadRunResponseRequiredActionSubmitToolOutputs::from($attributes['submit_tool_outputs']), + + ); + } + + /** + * {@inheritDoc} + */ + public function toArray(): array + { + return [ + 'type' => $this->type, + 'submit_tool_outputs' => $this->submitToolOutputs->toArray(), + ]; + } +} diff --git a/src/Responses/Threads/Runs/ThreadRunResponseRequiredActionFunctionToolCall.php b/src/Responses/Threads/Runs/ThreadRunResponseRequiredActionFunctionToolCall.php new file mode 100644 index 00000000..d045ed62 --- /dev/null +++ b/src/Responses/Threads/Runs/ThreadRunResponseRequiredActionFunctionToolCall.php @@ -0,0 +1,59 @@ +, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> + */ +final class ThreadRunResponseRequiredActionFunctionToolCall implements ResponseContract +{ + /** + * @use ArrayAccessible, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> + */ + use ArrayAccessible; + + use Fakeable; + + /** + * @param array $toolCalls + */ + private function __construct( + public string $id, + public string $type, + public ThreadRunResponseRequiredActionFunctionToolCallFunction $function, + ) + { + } + + /** + * Acts as static factory, and returns a new Response instance. + * + * @param array{task: ?string, language: ?string, duration: ?float, segments: array, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}|string $attributes + */ + public static function from(array|string $attributes): self + { + return new self( + $attributes['id'], + $attributes['type'], + ThreadRunResponseRequiredActionFunctionToolCallFunction::from($attributes['function']), + ); + } + + /** + * {@inheritDoc} + */ + public function toArray(): array + { + return [ + 'id' => $this->id, + 'type' => $this->type, + 'function' => $this->function->toArray(), + ]; + } +} diff --git a/src/Responses/Threads/Runs/ThreadRunResponseRequiredActionFunctionToolCallFunction.php b/src/Responses/Threads/Runs/ThreadRunResponseRequiredActionFunctionToolCallFunction.php new file mode 100644 index 00000000..39703b00 --- /dev/null +++ b/src/Responses/Threads/Runs/ThreadRunResponseRequiredActionFunctionToolCallFunction.php @@ -0,0 +1,56 @@ +, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> + */ +final class ThreadRunResponseRequiredActionFunctionToolCallFunction implements ResponseContract +{ + /** + * @use ArrayAccessible, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> + */ + use ArrayAccessible; + + use Fakeable; + + /** + * @param array $toolCalls + */ + private function __construct( + public string $name, + public string $arguments, + ) + { + } + + /** + * Acts as static factory, and returns a new Response instance. + * + * @param array{task: ?string, language: ?string, duration: ?float, segments: array, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}|string $attributes + */ + public static function from(array|string $attributes): self + { + return new self( + $attributes['name'], + $attributes['arguments'], + ); + } + + /** + * {@inheritDoc} + */ + public function toArray(): array + { + return [ + 'name' => $this->name, + 'arguments' => $this->arguments, + ]; + } +} diff --git a/src/Responses/Threads/Runs/ThreadRunResponseRequiredActionSubmitToolOutputs.php b/src/Responses/Threads/Runs/ThreadRunResponseRequiredActionSubmitToolOutputs.php new file mode 100644 index 00000000..f4d2027e --- /dev/null +++ b/src/Responses/Threads/Runs/ThreadRunResponseRequiredActionSubmitToolOutputs.php @@ -0,0 +1,55 @@ +, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> + */ +final class ThreadRunResponseRequiredActionSubmitToolOutputs implements ResponseContract +{ + /** + * @use ArrayAccessible, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> + */ + use ArrayAccessible; + + use Fakeable; + + /** + * @param array $toolCalls + */ + private function __construct( + public array $toolCalls, + ) + { + } + + /** + * Acts as static factory, and returns a new Response instance. + * + * @param array{task: ?string, language: ?string, duration: ?float, segments: array, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}|string $attributes + */ + public static function from(array|string $attributes): self + { + $toolCalls = array_map(fn(array $toolCall) => ThreadRunResponseRequiredActionFunctionToolCall::from($toolCall), $attributes['tool_calls']); + + return new self( + $toolCalls, + ); + } + + /** + * {@inheritDoc} + */ + public function toArray(): array + { + return [ + 'tool_calls' => array_map(fn(ThreadRunResponseRequiredActionFunctionToolCall $toolCall) => $toolCall->toArray(), $this->toolCalls), + ]; + } +} diff --git a/src/Responses/Threads/Runs/ThreadRunResponseToolCodeInterpreter.php b/src/Responses/Threads/Runs/ThreadRunResponseToolCodeInterpreter.php new file mode 100644 index 00000000..7895bf9e --- /dev/null +++ b/src/Responses/Threads/Runs/ThreadRunResponseToolCodeInterpreter.php @@ -0,0 +1,53 @@ +, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> + */ +final class ThreadRunResponseToolCodeInterpreter implements ResponseContract +{ + /** + * @use ArrayAccessible, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> + */ + use ArrayAccessible; + + use Fakeable; + + /** + * @param array $segments + */ + private function __construct( + public string $type, + ) + { + } + + /** + * Acts as static factory, and returns a new Response instance. + * + * @param array{task: ?string, language: ?string, duration: ?float, segments: array, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}|string $attributes + */ + public static function from(array|string $attributes): self + { + return new self( + $attributes['type'], + ); + } + + /** + * {@inheritDoc} + */ + public function toArray(): array + { + return [ + 'type' => $this->type, + ]; + } +} diff --git a/src/Responses/Threads/Runs/ThreadRunResponseToolFunction.php b/src/Responses/Threads/Runs/ThreadRunResponseToolFunction.php new file mode 100644 index 00000000..b28c4ae5 --- /dev/null +++ b/src/Responses/Threads/Runs/ThreadRunResponseToolFunction.php @@ -0,0 +1,56 @@ +, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> + */ +final class ThreadRunResponseToolFunction implements ResponseContract +{ + /** + * @use ArrayAccessible, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> + */ + use ArrayAccessible; + + use Fakeable; + + /** + * @param array $segments + */ + private function __construct( + public string $type, + public ThreadRunResponseToolFunctionFunction $function, + ) + { + } + + /** + * Acts as static factory, and returns a new Response instance. + * + * @param array{task: ?string, language: ?string, duration: ?float, segments: array, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}|string $attributes + */ + public static function from(array|string $attributes): self + { + return new self( + $attributes['type'], + ThreadRunResponseToolFunctionFunction::from($attributes['function']), + ); + } + + /** + * {@inheritDoc} + */ + public function toArray(): array + { + return [ + 'type' => $this->type, + 'function' => $this->function->toArray(), + ]; + } +} diff --git a/src/Responses/Threads/Runs/ThreadRunResponseToolFunctionFunction.php b/src/Responses/Threads/Runs/ThreadRunResponseToolFunctionFunction.php new file mode 100644 index 00000000..a8d44dc7 --- /dev/null +++ b/src/Responses/Threads/Runs/ThreadRunResponseToolFunctionFunction.php @@ -0,0 +1,59 @@ +, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> + */ +final class ThreadRunResponseToolFunctionFunction implements ResponseContract +{ + /** + * @use ArrayAccessible, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> + */ + use ArrayAccessible; + + use Fakeable; + + /** + * @param array $segments + */ + private function __construct( + public string $description, + public string $name, + public string $parameters, + ) + { + } + + /** + * Acts as static factory, and returns a new Response instance. + * + * @param array{task: ?string, language: ?string, duration: ?float, segments: array, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}|string $attributes + */ + public static function from(array|string $attributes): self + { + return new self( + $attributes['description'], + $attributes['name'], + $attributes['parameters'], + ); + } + + /** + * {@inheritDoc} + */ + public function toArray(): array + { + return [ + 'description' => $this->description, + 'name' => $this->name, + 'parameters' => $this->parameters, + ]; + } +} diff --git a/src/Responses/Threads/Runs/ThreadRunResponseToolRetrieval.php b/src/Responses/Threads/Runs/ThreadRunResponseToolRetrieval.php new file mode 100644 index 00000000..ce0941ed --- /dev/null +++ b/src/Responses/Threads/Runs/ThreadRunResponseToolRetrieval.php @@ -0,0 +1,53 @@ +, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> + */ +final class ThreadRunResponseToolRetrieval implements ResponseContract +{ + /** + * @use ArrayAccessible, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}> + */ + use ArrayAccessible; + + use Fakeable; + + /** + * @param array $segments + */ + private function __construct( + public string $type, + ) + { + } + + /** + * Acts as static factory, and returns a new Response instance. + * + * @param array{task: ?string, language: ?string, duration: ?float, segments: array, temperature: float, avg_logprob: float, compression_ratio: float, no_speech_prob: float, transient: bool}>, text: string}|string $attributes + */ + public static function from(array|string $attributes): self + { + return new self( + $attributes['type'], + ); + } + + /** + * {@inheritDoc} + */ + public function toArray(): array + { + return [ + 'type' => $this->type, + ]; + } +}