-
-
Notifications
You must be signed in to change notification settings - Fork 541
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Threads Runs and Thread Runs Steps endpoints added
- Loading branch information
1 parent
b36c5a4
commit b8d62ce
Showing
30 changed files
with
1,872 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
namespace OpenAI\Contracts\Resources; | ||
|
||
use OpenAI\Responses\Threads\Messages\ThreadMessageDeleteResponse; | ||
use OpenAI\Responses\Threads\Messages\ThreadMessageListResponse; | ||
use OpenAI\Responses\Threads\Messages\ThreadMessageResponse; | ||
use OpenAI\Responses\Threads\Runs\ThreadRunListResponse; | ||
use OpenAI\Responses\Threads\Runs\ThreadRunResponse; | ||
|
||
interface ThreadsRunsContract | ||
{ | ||
/** | ||
* Create a run. | ||
* | ||
* @see https://platform.openai.com/docs/api-reference/runs/createRun | ||
* | ||
* @param array<string, mixed> $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<string, mixed> $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<string, mixed> $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<string, mixed> $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<string, mixed> $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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace OpenAI\Contracts\Resources; | ||
|
||
use OpenAI\Responses\Threads\Messages\Files\ThreadMessageFileListResponse; | ||
use OpenAI\Responses\Threads\Messages\Files\ThreadMessageFileResponse; | ||
use OpenAI\Responses\Threads\Runs\Steps\ThreadRunStepListResponse; | ||
use OpenAI\Responses\Threads\Runs\Steps\ThreadRunStepResponse; | ||
|
||
interface ThreadsRunsStepsContract | ||
{ | ||
/** | ||
* Retrieves a run step. | ||
* | ||
* @see https://platform.openai.com/docs/api-reference/runs/getRunStep | ||
*/ | ||
public function retrieve(string $threadId, string $runId, string $stepId): ThreadRunStepResponse; | ||
|
||
/** | ||
* Returns a list of run steps belonging to a run. | ||
* | ||
* @see https://platform.openai.com/docs/api-reference/runs/listRunSteps | ||
* | ||
* @param array<string, mixed> $parameters | ||
*/ | ||
public function list(string $threadId, string $runId, array $parameters = []): ThreadRunStepListResponse; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenAI\Resources; | ||
|
||
use OpenAI\Contracts\Resources\ListAssistantsResponse; | ||
use OpenAI\Contracts\Resources\ThreadsMessagesContract; | ||
use OpenAI\Contracts\Resources\ThreadsMessagesFilesContract; | ||
use OpenAI\Contracts\Resources\ThreadsRunsContract; | ||
use OpenAI\Contracts\Resources\ThreadsRunsStepsContract; | ||
use OpenAI\Responses\Threads\Messages\ThreadMessageDeleteResponse; | ||
use OpenAI\Responses\Threads\Messages\ThreadMessageListResponse; | ||
use OpenAI\Responses\Threads\Messages\ThreadMessageResponse; | ||
use OpenAI\Responses\Threads\Runs\ThreadRunListResponse; | ||
use OpenAI\Responses\Threads\Runs\ThreadRunResponse; | ||
use OpenAI\Responses\Threads\ThreadDeleteResponse; | ||
use OpenAI\ValueObjects\Transporter\Payload; | ||
use OpenAI\ValueObjects\Transporter\Response; | ||
|
||
final class ThreadsRuns implements ThreadsRunsContract | ||
{ | ||
use Concerns\Transportable; | ||
|
||
/** | ||
* Create a run. | ||
* | ||
* @see https://platform.openai.com/docs/api-reference/runs/createRun | ||
* | ||
* @param array<string, mixed> $parameters | ||
*/ | ||
public function create(string $threadId, array $parameters): ThreadRunResponse | ||
{ | ||
$payload = Payload::create('threads/'.$threadId.'/runs', $parameters); | ||
|
||
/** @var Response<array{created: int, data: array<int, array{url?: string, b64_json?: string}>}> $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<array{created: int, data: array<int, array{url?: string, b64_json?: string}>}> $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<string, mixed> $parameters | ||
*/ | ||
public function modify(string $threadId, string $runId, array $parameters): ThreadRunResponse | ||
{ | ||
$payload = Payload::modify('threads/'.$threadId.'/runs', $runId, $parameters); | ||
|
||
/** @var Response<array{created: int, data: array<int, array{url?: string, b64_json?: string}>}> $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<string, mixed> $parameters | ||
*/ | ||
public function submitToolOutputs(string $threadId, string $runId, array $parameters): ThreadRunResponse | ||
{ | ||
$payload = Payload::create('threads/'.$threadId.'/runs/'.$runId.'/submit_tool_outputs', $parameters); | ||
|
||
/** @var Response<array{created: int, data: array<int, array{url?: string, b64_json?: string}>}> $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<string, mixed> $parameters | ||
*/ | ||
public function cancel(string $threadId, string $runId): ThreadRunResponse | ||
{ | ||
$payload = Payload::cancel('threads/'.$threadId.'/runs', $runId); | ||
|
||
/** @var Response<array{created: int, data: array<int, array{url?: string, b64_json?: string}>}> $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<string, mixed> $parameters | ||
*/ | ||
public function list(string $threadId, array $parameters = []): ThreadRunListResponse | ||
{ | ||
$payload = Payload::list('threads/'.$threadId.'/runs', $parameters); | ||
|
||
/** @var Response<array{created: int, data: array<int, array{url?: string, b64_json?: string}>}> $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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenAI\Resources; | ||
|
||
use OpenAI\Contracts\Resources\ListAssistantsResponse; | ||
use OpenAI\Contracts\Resources\ThreadsMessagesFilesContract; | ||
use OpenAI\Contracts\Resources\ThreadsRunsStepsContract; | ||
use OpenAI\Responses\Threads\Messages\Files\ThreadMessageFileListResponse; | ||
use OpenAI\Responses\Threads\Messages\Files\ThreadMessageFileResponse; | ||
use OpenAI\Responses\Threads\Runs\Steps\ThreadRunStepListResponse; | ||
use OpenAI\Responses\Threads\Runs\Steps\ThreadRunStepResponse; | ||
use OpenAI\ValueObjects\Transporter\Payload; | ||
use OpenAI\ValueObjects\Transporter\Response; | ||
|
||
final class ThreadsRunsSteps implements ThreadsRunsStepsContract | ||
{ | ||
use Concerns\Transportable; | ||
|
||
/** | ||
* Retrieves a run step. | ||
* | ||
* @see https://platform.openai.com/docs/api-reference/runs/getRunStep | ||
*/ | ||
public function retrieve(string $threadId, string $runId, string $stepId): ThreadRunStepResponse | ||
{ | ||
$payload = Payload::retrieve('threads/'.$threadId.'/runs/'.$runId.'/steps', $stepId); | ||
|
||
/** @var Response<array{created: int, data: array<int, array{url?: string, b64_json?: string}>}> $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<string, mixed> $parameters | ||
*/ | ||
public function list(string $threadId, string $runId, array $parameters = []): ThreadRunStepListResponse | ||
{ | ||
$payload = Payload::list('threads/'.$threadId.'/runs/'.$runId.'/steps', $parameters); | ||
|
||
/** @var Response<array{created: int, data: array<int, array{url?: string, b64_json?: string}>}> $response */ | ||
$response = $this->transporter->requestObject($payload); | ||
|
||
return ThreadRunStepListResponse::from($response->data(), $response->meta()); | ||
} | ||
} |
Oops, something went wrong.