├── src ├── Testing │ ├── Responses │ │ ├── Fixtures │ │ │ ├── Audio │ │ │ │ ├── speech-streamed.mp3 │ │ │ │ ├── TranslationResponseFixture.php │ │ │ │ └── TranscriptionResponseFixture.php │ │ │ ├── Files │ │ │ │ ├── DeleteResponseFixture.php │ │ │ │ ├── CreateResponseFixture.php │ │ │ │ ├── RetrieveResponseFixture.php │ │ │ │ └── ListResponseFixture.php │ │ │ ├── Models │ │ │ │ ├── DeleteResponseFixture.php │ │ │ │ ├── ListResponseFixture.php │ │ │ │ └── RetrieveResponseFixture.php │ │ │ ├── FineTunes │ │ │ │ ├── ListResponseFixture.php │ │ │ │ ├── ListEventsResponseFixture.php │ │ │ │ ├── RetrieveStreamedResponseEventFixture.txt │ │ │ │ └── RetrieveResponseFixture.php │ │ │ ├── Threads │ │ │ │ ├── ThreadDeleteResponseFixture.php │ │ │ │ ├── ThreadResponseFixture.php │ │ │ │ ├── Messages │ │ │ │ │ ├── ThreadMessageDeleteResponseFixture.php │ │ │ │ │ └── ThreadMessageResponseFixture.php │ │ │ │ └── Runs │ │ │ │ │ └── Steps │ │ │ │ │ └── ThreadRunStepResponseFixture.php │ │ │ ├── Responses │ │ │ │ ├── DeleteResponseFixture.php │ │ │ │ └── ListInputItemsFixture.php │ │ │ ├── Assistants │ │ │ │ ├── AssistantDeleteResponseFixture.php │ │ │ │ ├── AssistantResponseFixture.php │ │ │ │ └── AssistantListResponseFixture.php │ │ │ ├── VectorStores │ │ │ │ ├── Search │ │ │ │ │ ├── VectorStoreSearchResponseContentFixture.php │ │ │ │ │ ├── VectorStoreSearchResponseFileFixture.php │ │ │ │ │ └── VectorStoreSearchResponseFixture.php │ │ │ │ ├── VectorStoreDeleteResponseFixture.php │ │ │ │ ├── Files │ │ │ │ │ ├── VectorStoreFileDeleteResponseFixture.php │ │ │ │ │ ├── VectorStoreFileResponseFixture.php │ │ │ │ │ └── VectorStoreFileListResponseFixture.php │ │ │ │ └── VectorStoreResponseFixture.php │ │ │ ├── FineTuning │ │ │ │ ├── ListJobsResponseFixture.php │ │ │ │ ├── ListJobEventsResponseFixture.php │ │ │ │ └── RetrieveJobResponseFixture.php │ │ │ ├── Images │ │ │ │ ├── EditResponseFixture.php │ │ │ │ ├── CreateResponseFixture.php │ │ │ │ └── VariationResponseFixture.php │ │ │ ├── Edits │ │ │ │ └── CreateResponseFixture.php │ │ │ ├── Embeddings │ │ │ │ └── CreateResponseFixture.php │ │ │ ├── Realtime │ │ │ │ ├── TranscriptionSessionResponseFixture.php │ │ │ │ └── SessionResponseFixture.php │ │ │ ├── Completions │ │ │ │ └── CreateResponseFixture.php │ │ │ ├── Chat │ │ │ │ └── CreateResponseFixture.php │ │ │ └── Batches │ │ │ │ └── BatchResponseFixture.php │ │ └── Concerns │ │ │ └── FakeableForStreamedResponse.php │ ├── Resources │ │ ├── EditsTestResource.php │ │ ├── EmbeddingsTestResource.php │ │ ├── ModerationsTestResource.php │ │ ├── ChatTestResource.php │ │ ├── CompletionsTestResource.php │ │ ├── RealtimeTestResource.php │ │ ├── ModelsTestResource.php │ │ ├── ThreadsRunsStepsTestResource.php │ │ ├── ImagesTestResource.php │ │ ├── Concerns │ │ │ └── Testable.php │ │ ├── BatchesTestResource.php │ │ ├── FilesTestResource.php │ │ ├── AssistantsTestResource.php │ │ ├── AudioTestResource.php │ │ ├── FineTuningTestResource.php │ │ ├── VectorStoresFilesTestResource.php │ │ ├── VectorStoresFileBatchesTestResource.php │ │ └── FineTunesTestResource.php │ └── Requests │ │ └── TestRequest.php ├── Exceptions │ ├── UnknownEventException.php │ ├── InvalidArgumentException.php │ ├── UnserializableResponse.php │ ├── TransporterException.php │ └── ErrorException.php ├── Enums │ ├── FineTuning │ │ └── FineTuningEventLevel.php │ ├── Moderations │ │ ├── CategoryAppliedInputType.php │ │ └── Category.php │ └── Transporter │ │ ├── Method.php │ │ └── ContentType.php ├── Contracts │ ├── ResponseHasMetaInformationContract.php │ ├── StringableContract.php │ ├── ResponseStreamContract.php │ ├── Resources │ │ ├── EmbeddingsContract.php │ │ ├── ModerationsContract.php │ │ ├── EditsContract.php │ │ ├── ThreadsRunsStepsContract.php │ │ ├── ChatContract.php │ │ ├── RealtimeContract.php │ │ ├── CompletionsContract.php │ │ ├── ModelsContract.php │ │ ├── ImagesContract.php │ │ └── BatchesContract.php │ ├── TransporterContract.php │ ├── ResponseContract.php │ └── MetaInformationContract.php ├── Responses │ ├── Concerns │ │ ├── HasMetaInformation.php │ │ └── ArrayAccessible.php │ ├── Meta │ │ ├── MetaInformationRateLimit.php │ │ └── MetaInformationOpenAI.php │ ├── Moderations │ │ └── CreateResponseCategory.php │ ├── Edits │ │ ├── CreateResponseChoice.php │ │ └── CreateResponseUsage.php │ ├── Chat │ │ ├── CreateResponseToolCallFunction.php │ │ ├── CreateResponseFunctionCall.php │ │ ├── CreateStreamedResponseToolCallFunction.php │ │ ├── CreateResponseChoiceAnnotations.php │ │ ├── CreateResponseUsagePromptTokensDetails.php │ │ ├── CreateStreamedResponseFunctionCall.php │ │ ├── CreateResponseToolCall.php │ │ ├── CreateResponseChoiceAnnotationsUrlCitations.php │ │ ├── CreateResponseChoiceLogprobsContent.php │ │ ├── CreateStreamedResponseChoice.php │ │ ├── CreateStreamedResponseToolCall.php │ │ └── CreateResponseChoiceLogprobs.php │ ├── Embeddings │ │ ├── CreateResponseUsage.php │ │ └── CreateResponseEmbedding.php │ ├── Images │ │ ├── ImageResponseUsageInputTokensDetails.php │ │ ├── EditResponseData.php │ │ ├── VariationResponseData.php │ │ └── ImageResponseUsage.php │ ├── Completions │ │ └── CreateResponseUsage.php │ ├── Threads │ │ ├── Runs │ │ │ ├── ThreadRunResponseUsage.php │ │ │ ├── ThreadRunResponseFileSearch.php │ │ │ ├── ThreadRunResponseToolChoiceFunction.php │ │ │ ├── ThreadRunResponseIncompleteDetails.php │ │ │ ├── ThreadRunResponseToolCodeInterpreter.php │ │ │ ├── Steps │ │ │ │ ├── ThreadRunStepResponseMessageCreation.php │ │ │ │ ├── ThreadRunStepResponseCodeInterpreterOutputImageImage.php │ │ │ │ ├── ThreadRunStepResponseCodeInterpreterOutputLogs.php │ │ │ │ └── ThreadRunStepResponseFunction.php │ │ │ ├── ThreadRunResponseLastError.php │ │ │ ├── ThreadRunResponseTruncationStrategy.php │ │ │ └── ThreadRunResponseRequiredActionFunctionToolCallFunction.php │ │ └── Messages │ │ │ ├── ThreadMessageResponseIncompleteDetails.php │ │ │ ├── ThreadMessageResponseContentTextAnnotationFilePath.php │ │ │ ├── ThreadMessageResponseAttachmentFileSearchTool.php │ │ │ ├── ThreadMessageResponseAttachmentCodeInterpreterTool.php │ │ │ ├── ThreadMessageResponseContentImageUrl.php │ │ │ ├── ThreadMessageResponseContentImageFile.php │ │ │ └── ThreadMessageResponseContentTextAnnotationFileCitation.php │ ├── Assistants │ │ ├── AssistantResponseToolFileSearch.php │ │ ├── AssistantResponseResponseFormatText.php │ │ ├── AssistantResponseResponseFormat.php │ │ ├── AssistantResponseToolCodeInterpreter.php │ │ ├── AssistantResponseToolResourceCodeInterpreter.php │ │ └── AssistantResponseToolResourceFileSearch.php │ ├── Responses │ │ ├── Format │ │ │ ├── TextFormat.php │ │ │ └── JsonObjectFormat.php │ │ ├── CreateResponseIncompleteDetails.php │ │ ├── Output │ │ │ ├── ComputerAction │ │ │ │ ├── OutputComputerActionWait.php │ │ │ │ ├── OutputComputerActionScreenshot.php │ │ │ │ ├── OutputComputerDragPath.php │ │ │ │ ├── OutputComputerActionType.php │ │ │ │ ├── OutputComputerActionKeyPress.php │ │ │ │ ├── OutputComputerActionMove.php │ │ │ │ ├── OutputComputerActionDoubleClick.php │ │ │ │ └── OutputComputerPendingSafetyCheck.php │ │ │ ├── CodeInterpreter │ │ │ │ ├── CodeFileObject.php │ │ │ │ └── CodeTextOutput.php │ │ │ ├── OutputReasoningSummary.php │ │ │ ├── OutputMessageContentRefusal.php │ │ │ ├── OutputMessageContentOutputTextAnnotationsFilePath.php │ │ │ └── OutputWebSearchToolCall.php │ │ ├── CreateResponseUsageInputTokenDetails.php │ │ ├── CreateResponseUsageOutputTokenDetails.php │ │ ├── CreateResponseError.php │ │ ├── Tool │ │ │ ├── McpToolNamesFilter.php │ │ │ ├── FileSearchRankingOption.php │ │ │ ├── ImageGenerationInputImageMask.php │ │ │ ├── CodeInterpreterContainerAuto.php │ │ │ └── FileSearchComparisonFilter.php │ │ ├── ToolChoice │ │ │ ├── HostedToolChoice.php │ │ │ └── FunctionToolChoice.php │ │ ├── CreateResponseReasoning.php │ │ ├── Input │ │ │ ├── InputMessageContentInputText.php │ │ │ └── AcknowledgedSafetyCheck.php │ │ └── Streaming │ │ │ ├── McpCall.php │ │ │ └── McpListTools.php │ ├── Realtime │ │ └── Session │ │ │ ├── InputAudioTranscription.php │ │ │ └── ClientSecret.php │ ├── VectorStores │ │ ├── Files │ │ │ ├── VectorStoreFileResponseChunkingStrategyOther.php │ │ │ └── VectorStoreFileResponseLastError.php │ │ ├── VectorStoreResponseExpiresAfter.php │ │ └── Search │ │ │ └── VectorStoreSearchResponseContent.php │ ├── Audio │ │ └── TranscriptionResponseWord.php │ ├── Batches │ │ ├── BatchResponseRequestCounts.php │ │ └── BatchResponseErrorsData.php │ └── FineTuning │ │ ├── RetrieveJobResponseError.php │ │ └── ListJobEventsResponseEventData.php ├── Resources │ ├── Concerns │ │ ├── Transportable.php │ │ └── Streamable.php │ ├── Embeddings.php │ ├── Moderations.php │ └── Edits.php ├── ValueObjects │ ├── ApiKey.php │ └── Transporter │ │ ├── BaseUri.php │ │ ├── QueryParams.php │ │ └── Response.php └── OpenAI.php └── LICENSE.md /src/Testing/Responses/Fixtures/Audio/speech-streamed.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/infomaniak/openai-php-client/main/src/Testing/Responses/Fixtures/Audio/speech-streamed.mp3 -------------------------------------------------------------------------------- /src/Exceptions/UnknownEventException.php: -------------------------------------------------------------------------------- 1 | 13 | * 14 | * @internal 15 | */ 16 | interface ResponseStreamContract extends IteratorAggregate {} 17 | -------------------------------------------------------------------------------- /src/Enums/Transporter/ContentType.php: -------------------------------------------------------------------------------- 1 | meta; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Resources/Concerns/Transportable.php: -------------------------------------------------------------------------------- 1 | 'file-XjGxS3KTG0uNmNOK362iJua3', 9 | 'object' => 'file', 10 | 'deleted' => true, 11 | ]; 12 | } 13 | -------------------------------------------------------------------------------- /src/Testing/Responses/Fixtures/Models/DeleteResponseFixture.php: -------------------------------------------------------------------------------- 1 | 'curie:ft-acmeco-2021-03-03-21-44-20', 9 | 'object' => 'model', 10 | 'deleted' => true, 11 | ]; 12 | } 13 | -------------------------------------------------------------------------------- /src/Testing/Responses/Fixtures/Models/ListResponseFixture.php: -------------------------------------------------------------------------------- 1 | 'list', 9 | 'data' => [ 10 | RetrieveResponseFixture::ATTRIBUTES, 11 | ], 12 | ]; 13 | } 14 | -------------------------------------------------------------------------------- /src/Testing/Responses/Fixtures/FineTunes/ListResponseFixture.php: -------------------------------------------------------------------------------- 1 | 'list', 9 | 'data' => [ 10 | RetrieveResponseFixture::ATTRIBUTES, 11 | ], 12 | ]; 13 | } 14 | -------------------------------------------------------------------------------- /src/Testing/Responses/Fixtures/Threads/ThreadDeleteResponseFixture.php: -------------------------------------------------------------------------------- 1 | 'thread_agvtHUGezjTCt4SKgQg0NJ2Y', 9 | 'object' => 'thread.deleted', 10 | 'deleted' => true, 11 | ]; 12 | } 13 | -------------------------------------------------------------------------------- /src/Testing/Responses/Fixtures/Models/RetrieveResponseFixture.php: -------------------------------------------------------------------------------- 1 | 'text-babbage:001', 9 | 'object' => 'model', 10 | 'created' => 1_642_018_370, 11 | 'owned_by' => 'openai', 12 | ]; 13 | } 14 | -------------------------------------------------------------------------------- /src/Testing/Responses/Fixtures/Responses/DeleteResponseFixture.php: -------------------------------------------------------------------------------- 1 | 'resp_67ccf18ef5fc8190b16dbee19bc54e5f087bb177ab789d5c', 9 | 'object' => 'response', 10 | 'deleted' => true, 11 | ]; 12 | } 13 | -------------------------------------------------------------------------------- /src/Testing/Responses/Fixtures/Assistants/AssistantDeleteResponseFixture.php: -------------------------------------------------------------------------------- 1 | 'asst_SMzoVX8XmCZEg1EbMHoAm8tc', 9 | 'object' => 'assistant.deleted', 10 | 'deleted' => true, 11 | ]; 12 | } 13 | -------------------------------------------------------------------------------- /src/Testing/Responses/Fixtures/VectorStores/Search/VectorStoreSearchResponseContentFixture.php: -------------------------------------------------------------------------------- 1 | 'text', 9 | 'text' => 'Sample text content from the vector store.', 10 | ]; 11 | } 12 | -------------------------------------------------------------------------------- /src/Testing/Responses/Fixtures/VectorStores/VectorStoreDeleteResponseFixture.php: -------------------------------------------------------------------------------- 1 | 'vs_xzlnkCbIQE50B9A8RzmcFmtP', 9 | 'object' => 'vector_store.deleted', 10 | 'deleted' => true, 11 | ]; 12 | } 13 | -------------------------------------------------------------------------------- /src/Testing/Responses/Fixtures/Threads/ThreadResponseFixture.php: -------------------------------------------------------------------------------- 1 | 'thread_agvtHUGezjTCt4SKgQg0NJ2Y', 9 | 'object' => 'thread', 10 | 'created_at' => 1_699_621_778, 11 | 'metadata' => [], 12 | ]; 13 | } 14 | -------------------------------------------------------------------------------- /src/Testing/Responses/Fixtures/FineTuning/ListJobsResponseFixture.php: -------------------------------------------------------------------------------- 1 | 'list', 9 | 'data' => [ 10 | RetrieveJobResponseFixture::ATTRIBUTES, 11 | ], 12 | 'has_more' => false, 13 | ]; 14 | } 15 | -------------------------------------------------------------------------------- /src/Testing/Responses/Fixtures/Threads/Messages/ThreadMessageDeleteResponseFixture.php: -------------------------------------------------------------------------------- 1 | 'msg_KNsDDwE41BUAHhcPNpDkdHWZ', 9 | 'object' => 'thread.message.deleted', 10 | 'deleted' => true, 11 | ]; 12 | } 13 | -------------------------------------------------------------------------------- /src/Testing/Responses/Fixtures/Images/EditResponseFixture.php: -------------------------------------------------------------------------------- 1 | 1_664_136_088, 9 | 'data' => [ 10 | [ 11 | 'url' => 'https://openai.com/fake-image.png', 12 | ], 13 | ], 14 | ]; 15 | } 16 | -------------------------------------------------------------------------------- /src/Testing/Responses/Fixtures/Images/CreateResponseFixture.php: -------------------------------------------------------------------------------- 1 | 1_664_136_088, 9 | 'data' => [ 10 | [ 11 | 'url' => 'https://openai.com/fake-image.png', 12 | ], 13 | ], 14 | ]; 15 | } 16 | -------------------------------------------------------------------------------- /src/Testing/Responses/Fixtures/Images/VariationResponseFixture.php: -------------------------------------------------------------------------------- 1 | 1_664_136_088, 9 | 'data' => [ 10 | [ 11 | 'url' => 'https://openai.com/fake-image.png', 12 | ], 13 | ], 14 | ]; 15 | } 16 | -------------------------------------------------------------------------------- /src/Testing/Responses/Fixtures/VectorStores/Files/VectorStoreFileDeleteResponseFixture.php: -------------------------------------------------------------------------------- 1 | 'file-HuwUghQzWasTZeX3uRRawY5R', 9 | 'object' => 'vector_store.file.deleted', 10 | 'deleted' => true, 11 | ]; 12 | } 13 | -------------------------------------------------------------------------------- /src/Exceptions/UnserializableResponse.php: -------------------------------------------------------------------------------- 1 | getMessage(), 0, $exception); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Exceptions/TransporterException.php: -------------------------------------------------------------------------------- 1 | getMessage(), 0, $exception); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Contracts/Resources/EmbeddingsContract.php: -------------------------------------------------------------------------------- 1 | $parameters 15 | */ 16 | public function create(array $parameters): CreateResponse; 17 | } 18 | -------------------------------------------------------------------------------- /src/Contracts/Resources/ModerationsContract.php: -------------------------------------------------------------------------------- 1 | $parameters 15 | */ 16 | public function create(array $parameters): CreateResponse; 17 | } 18 | -------------------------------------------------------------------------------- /src/Testing/Responses/Fixtures/Files/CreateResponseFixture.php: -------------------------------------------------------------------------------- 1 | 'file-XjGxS3KTG0uNmNOK362iJua3', 9 | 'object' => 'file', 10 | 'bytes' => 140, 11 | 'created_at' => 1_613_779_121, 12 | 'filename' => 'fake-file.jsonl', 13 | 'purpose' => 'fine-tune', 14 | 'status' => 'succeeded', 15 | 'status_details' => null, 16 | ]; 17 | } 18 | -------------------------------------------------------------------------------- /src/Testing/Responses/Fixtures/Files/RetrieveResponseFixture.php: -------------------------------------------------------------------------------- 1 | 'file-XjGxS3KTG0uNmNOK362iJua3', 9 | 'object' => 'file', 10 | 'bytes' => 140, 11 | 'created_at' => 1_613_779_121, 12 | 'filename' => 'fake-file.jsonl', 13 | 'purpose' => 'fine-tune', 14 | 'status' => 'succeeded', 15 | 'status_details' => null, 16 | ]; 17 | } 18 | -------------------------------------------------------------------------------- /src/Testing/Responses/Fixtures/Edits/CreateResponseFixture.php: -------------------------------------------------------------------------------- 1 | 'edit', 9 | 'created' => 1_664_135_921, 10 | 'choices' => [[ 11 | 'text' => "This is a fake edit response.\n", 12 | 'index' => 0, 13 | ]], 14 | 'usage' => [ 15 | 'prompt_tokens' => 25, 16 | 'completion_tokens' => 30, 17 | 'total_tokens' => 55, 18 | ], 19 | ]; 20 | } 21 | -------------------------------------------------------------------------------- /src/Testing/Responses/Fixtures/FineTunes/ListEventsResponseFixture.php: -------------------------------------------------------------------------------- 1 | 'list', 9 | 'data' => [ 10 | [ 11 | 'object' => 'fine-tune-event', 12 | 'created_at' => 1_614_807_352, 13 | 'level' => 'info', 14 | 'message' => 'Job enqueued. Waiting for jobs ahead to complete. Queue number => 0.', 15 | ], 16 | ], 17 | ]; 18 | } 19 | -------------------------------------------------------------------------------- /src/Testing/Responses/Fixtures/VectorStores/Files/VectorStoreFileResponseFixture.php: -------------------------------------------------------------------------------- 1 | 'file-HuwUghQzWasTZeX3uRRawY5R', 9 | 'object' => 'vector_store.file', 10 | 'usage_bytes' => 29882, 11 | 'created_at' => 1_715_956_697, 12 | 'vector_store_id' => 'vs_xds05V7ep0QMGI5JmYnWsJwb', 13 | 'status' => 'completed', 14 | 'attributes' => [], 15 | 'last_error' => null, 16 | ]; 17 | } 18 | -------------------------------------------------------------------------------- /src/Testing/Responses/Fixtures/VectorStores/Search/VectorStoreSearchResponseFileFixture.php: -------------------------------------------------------------------------------- 1 | 'file_abc123', 9 | 'filename' => 'document.pdf', 10 | 'score' => 0.95, 11 | 'attributes' => [ 12 | 'author' => 'John Doe', 13 | 'date' => '2023-01-01', 14 | ], 15 | 'content' => [ 16 | VectorStoreSearchResponseContentFixture::ATTRIBUTES, 17 | ], 18 | ]; 19 | } 20 | -------------------------------------------------------------------------------- /src/Testing/Resources/EditsTestResource.php: -------------------------------------------------------------------------------- 1 | record(__FUNCTION__, func_get_args()); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Testing/Resources/EmbeddingsTestResource.php: -------------------------------------------------------------------------------- 1 | record(__FUNCTION__, func_get_args()); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Testing/Resources/ModerationsTestResource.php: -------------------------------------------------------------------------------- 1 | record(__FUNCTION__, func_get_args()); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Testing/Responses/Fixtures/Embeddings/CreateResponseFixture.php: -------------------------------------------------------------------------------- 1 | 'list', 9 | 'data' => [ 10 | [ 11 | 'object' => 'embedding', 12 | 'index' => 0, 13 | 'embedding' => [ 14 | -0.008906792, 15 | -0.013743395, 16 | ], 17 | ], 18 | ], 19 | 'usage' => [ 20 | 'prompt_tokens' => 8, 21 | 'total_tokens' => 8, 22 | ], 23 | ]; 24 | } 25 | -------------------------------------------------------------------------------- /src/Responses/Meta/MetaInformationRateLimit.php: -------------------------------------------------------------------------------- 1 | $args 9 | */ 10 | public function __construct(protected string $resource, protected string $method, protected array $args) {} 11 | 12 | public function resource(): string 13 | { 14 | return $this->resource; 15 | } 16 | 17 | public function method(): string 18 | { 19 | return $this->method; 20 | } 21 | 22 | /** 23 | * @return array 24 | */ 25 | public function args(): array 26 | { 27 | return $this->args; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Testing/Responses/Fixtures/Files/ListResponseFixture.php: -------------------------------------------------------------------------------- 1 | 'list', 9 | 'data' => [ 10 | [ 11 | 'id' => 'file-XjGxS3KTG0uNmNOK362iJua3', 12 | 'object' => 'file', 13 | 'bytes' => 140, 14 | 'created_at' => 1_613_779_121, 15 | 'filename' => 'fake-file.jsonl', 16 | 'purpose' => 'fine-tune', 17 | 'status' => 'succeeded', 18 | 'status_details' => null, 19 | ], 20 | ], 21 | ]; 22 | } 23 | -------------------------------------------------------------------------------- /src/Contracts/Resources/EditsContract.php: -------------------------------------------------------------------------------- 1 | $parameters 15 | * 16 | * @deprecated OpenAI has deprecated this endpoint and will stop working by January 4, 2024. 17 | * https://openai.com/blog/gpt-4-api-general-availability#deprecation-of-the-edits-api 18 | */ 19 | public function create(array $parameters): CreateResponse; 20 | } 21 | -------------------------------------------------------------------------------- /src/ValueObjects/ApiKey.php: -------------------------------------------------------------------------------- 1 | apiKey; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Enums/Moderations/Category.php: -------------------------------------------------------------------------------- 1 | 'asst_SMzoVX8XmCZEg1EbMHoAm8tc', 9 | 'object' => 'assistant', 10 | 'created_at' => 1_699_619_403, 11 | 'name' => 'Math Tutor', 12 | 'description' => null, 13 | 'model' => 'gpt-4', 14 | 'instructions' => 'You are a personal math tutor.', 15 | 'tools' => [], 16 | 'tool_resources' => [], 17 | 'metadata' => [], 18 | 'temperature' => 0.7, 19 | 'top_p' => 1.0, 20 | 'response_format' => 'text', 21 | ]; 22 | } 23 | -------------------------------------------------------------------------------- /src/Testing/Responses/Fixtures/Realtime/TranscriptionSessionResponseFixture.php: -------------------------------------------------------------------------------- 1 | [ 9 | 'expires_at' => 1735680000, 10 | 'value' => 'ek_secret_123', 11 | ], 12 | 'input_audio_format' => 'pcm16', 13 | 'input_audio_transcription' => null, 14 | 'modalities' => null, 15 | 'turn_detection' => [ 16 | 'prefix_padding_ms' => 300, 17 | 'silence_duration_ms' => 200, 18 | 'threshold' => 0.5, 19 | 'type' => 'server_vad', 20 | ], 21 | ]; 22 | } 23 | -------------------------------------------------------------------------------- /src/Testing/Responses/Fixtures/FineTuning/ListJobEventsResponseFixture.php: -------------------------------------------------------------------------------- 1 | 'list', 9 | 'data' => [ 10 | [ 11 | 'object' => 'fine_tuning.job.event', 12 | 'id' => 'ft-event-ddTJfwuMVpfLXseO0Am0Gqjm', 13 | 'created_at' => 1_692_407_401, 14 | 'level' => 'info', 15 | 'message' => 'Fine tuning job successfully completed', 16 | 'data' => null, 17 | 'type' => 'message', 18 | ], 19 | ], 20 | 'has_more' => false, 21 | ]; 22 | } 23 | -------------------------------------------------------------------------------- /src/Responses/Moderations/CreateResponseCategory.php: -------------------------------------------------------------------------------- 1 | withApiKey($apiKey) 17 | ->withOrganization($organization) 18 | ->withProject($project) 19 | ->withHttpHeader('OpenAI-Beta', 'assistants=v2') 20 | ->make(); 21 | } 22 | 23 | /** 24 | * Creates a new factory instance to configure a custom Open AI Client 25 | */ 26 | public static function factory(): Factory 27 | { 28 | return new Factory; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Testing/Resources/ChatTestResource.php: -------------------------------------------------------------------------------- 1 | record(__FUNCTION__, func_get_args()); 23 | } 24 | 25 | public function createStreamed(array $parameters): StreamResponse 26 | { 27 | return $this->record(__FUNCTION__, func_get_args()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Testing/Responses/Fixtures/Completions/CreateResponseFixture.php: -------------------------------------------------------------------------------- 1 | 'cmpl-uqkvlQyYK7bGYrRHQ0eXlWi7', 9 | 'object' => 'text_completion', 10 | 'created' => 1_589_478_378, 11 | 'model' => 'gpt-3.5-turbo-instruct', 12 | 'choices' => [ 13 | [ 14 | 'text' => "\n\nThis is a fake completion response.", 15 | 'index' => 0, 16 | 'logprobs' => null, 17 | 'finish_reason' => 'length', 18 | ], 19 | ], 20 | 'usage' => [ 21 | 'prompt_tokens' => 5, 22 | 'completion_tokens' => 7, 23 | 'total_tokens' => 12, 24 | ], 25 | ]; 26 | } 27 | -------------------------------------------------------------------------------- /src/Testing/Responses/Fixtures/VectorStores/VectorStoreResponseFixture.php: -------------------------------------------------------------------------------- 1 | 'vs_8VE2cQq1jTFlH7FizhYCzUz0', 9 | 'object' => 'vector_store', 10 | 'name' => 'Product Knowledge Base', 11 | 'status' => 'in_progress', 12 | 'usage_bytes' => 0, 13 | 'created_at' => 1_715_953_317, 14 | 'file_counts' => [ 15 | 'in_progress' => 1, 16 | 'completed' => 0, 17 | 'failed' => 0, 18 | 'cancelled' => 0, 19 | 'total' => 1, 20 | ], 21 | 'metadata' => [], 22 | 'expires_after' => null, 23 | 'expires_at' => null, 24 | 'last_active_at' => 1_715_953_317, 25 | ]; 26 | } 27 | -------------------------------------------------------------------------------- /src/Responses/Edits/CreateResponseChoice.php: -------------------------------------------------------------------------------- 1 | $this->text, 32 | 'index' => $this->index, 33 | ]; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Testing/Resources/CompletionsTestResource.php: -------------------------------------------------------------------------------- 1 | record(__FUNCTION__, func_get_args()); 23 | } 24 | 25 | public function createStreamed(array $parameters): StreamResponse 26 | { 27 | return $this->record(__FUNCTION__, func_get_args()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Contracts/Resources/ThreadsRunsStepsContract.php: -------------------------------------------------------------------------------- 1 | $parameters 23 | */ 24 | public function list(string $threadId, string $runId, array $parameters = []): ThreadRunStepListResponse; 25 | } 26 | -------------------------------------------------------------------------------- /src/Testing/Resources/RealtimeTestResource.php: -------------------------------------------------------------------------------- 1 | record(__FUNCTION__, func_get_args()); 23 | } 24 | 25 | public function transcribeToken(array $parameters = []): TranscriptionSessionResponse 26 | { 27 | return $this->record(__FUNCTION__, func_get_args()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Responses/Chat/CreateResponseToolCallFunction.php: -------------------------------------------------------------------------------- 1 | $this->name, 32 | 'arguments' => $this->arguments, 33 | ]; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Testing/Responses/Fixtures/VectorStores/Files/VectorStoreFileListResponseFixture.php: -------------------------------------------------------------------------------- 1 | 'list', 9 | 'data' => [ 10 | [ 11 | 'id' => 'file-HuwUghQzWasTZeX3uRRawY5R', 12 | 'object' => 'vector_store.file', 13 | 'usage_bytes' => 29882, 14 | 'created_at' => 1_715_956_697, 15 | 'vector_store_id' => 'vs_xds05V7ep0QMGI5JmYnWsJwb', 16 | 'status' => 'completed', 17 | 'attributes' => [], 18 | 'last_error' => null, 19 | ], 20 | ], 21 | 'first_id' => 'file-HuwUghQzWasTZeX3uRRawY5R', 22 | 'last_id' => 'file-HuwUghQzWasTZeX3uRRawY5R', 23 | 'has_more' => false, 24 | ]; 25 | } 26 | -------------------------------------------------------------------------------- /src/Contracts/Resources/ChatContract.php: -------------------------------------------------------------------------------- 1 | $parameters 17 | */ 18 | public function create(array $parameters): CreateResponse; 19 | 20 | /** 21 | * Creates a streamed completion for the chat message 22 | * 23 | * @see https://platform.openai.com/docs/api-reference/chat/create 24 | * 25 | * @param array $parameters 26 | * @return StreamResponse 27 | */ 28 | public function createStreamed(array $parameters): StreamResponse; 29 | } 30 | -------------------------------------------------------------------------------- /src/Responses/Chat/CreateResponseFunctionCall.php: -------------------------------------------------------------------------------- 1 | $this->name, 35 | 'arguments' => $this->arguments, 36 | ]; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Responses/Embeddings/CreateResponseUsage.php: -------------------------------------------------------------------------------- 1 | $this->promptTokens, 32 | 'total_tokens' => $this->totalTokens, 33 | ]; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Responses/Images/ImageResponseUsageInputTokensDetails.php: -------------------------------------------------------------------------------- 1 | $this->textTokens, 32 | 'image_tokens' => $this->imageTokens, 33 | ]; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Contracts/Resources/RealtimeContract.php: -------------------------------------------------------------------------------- 1 | $parameters 18 | */ 19 | public function token(array $parameters = []): SessionResponse; 20 | 21 | /** 22 | * Create an ephemeral API token for real time transcription sessions. 23 | * 24 | * @see https://platform.openai.com/docs/api-reference/realtime-sessions/create-transcription 25 | * 26 | * @param array $parameters 27 | */ 28 | public function transcribeToken(array $parameters = []): TranscriptionSessionResponse; 29 | } 30 | -------------------------------------------------------------------------------- /src/Responses/Chat/CreateStreamedResponseToolCallFunction.php: -------------------------------------------------------------------------------- 1 | $this->name, 32 | 'arguments' => $this->arguments, 33 | ], fn (?string $value): bool => ! is_null($value)); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Testing/Resources/ModelsTestResource.php: -------------------------------------------------------------------------------- 1 | record(__FUNCTION__); 24 | } 25 | 26 | public function retrieve(string $model): RetrieveResponse 27 | { 28 | return $this->record(__FUNCTION__, func_get_args()); 29 | } 30 | 31 | public function delete(string $model): DeleteResponse 32 | { 33 | return $this->record(__FUNCTION__, func_get_args()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Testing/Resources/ThreadsRunsStepsTestResource.php: -------------------------------------------------------------------------------- 1 | record(__FUNCTION__, func_get_args()); 23 | } 24 | 25 | public function list(string $threadId, string $runId, array $parameters = []): ThreadRunStepListResponse 26 | { 27 | return $this->record(__FUNCTION__, func_get_args()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Testing/Responses/Concerns/FakeableForStreamedResponse.php: -------------------------------------------------------------------------------- 1 | createStreamFromResource($resource); 24 | 25 | $response = Psr17FactoryDiscovery::findResponseFactory() 26 | ->createResponse() 27 | ->withBody($stream); 28 | 29 | return new StreamResponse(static::class, $response); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Testing/Responses/Fixtures/Responses/ListInputItemsFixture.php: -------------------------------------------------------------------------------- 1 | 'list', 9 | 'data' => [ 10 | [ 11 | 'content' => [ 12 | [ 13 | 'text' => 'What was a positive news story from today?', 14 | 'type' => 'input_text', 15 | 'annotations' => [], 16 | ], 17 | ], 18 | 'id' => 'msg_67ccf190ca3881909d433c50b1f6357e087bb177ab789d5c', 19 | 'role' => 'user', 20 | 'status' => 'completed', 21 | 'type' => 'message', 22 | ], 23 | ], 24 | 'first_id' => 'msg_67ccf190ca3881909d433c50b1f6357e087bb177ab789d5c', 25 | 'last_id' => 'msg_67ccf190ca3881909d433c50b1f6357e087bb177ab789d5c', 26 | 'has_more' => false, 27 | ]; 28 | } 29 | -------------------------------------------------------------------------------- /src/Contracts/Resources/CompletionsContract.php: -------------------------------------------------------------------------------- 1 | $parameters 17 | */ 18 | public function create(array $parameters): CreateResponse; 19 | 20 | /** 21 | * Creates a streamed completion for the provided prompt and parameters 22 | * 23 | * @see https://platform.openai.com/docs/api-reference/completions/create-completion 24 | * 25 | * @param array $parameters 26 | * @return StreamResponse 27 | */ 28 | public function createStreamed(array $parameters): StreamResponse; 29 | } 30 | -------------------------------------------------------------------------------- /src/ValueObjects/Transporter/BaseUri.php: -------------------------------------------------------------------------------- 1 | baseUri, $protocol)) { 37 | return "{$this->baseUri}/"; 38 | } 39 | } 40 | 41 | return "https://{$this->baseUri}/"; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Testing/Resources/ImagesTestResource.php: -------------------------------------------------------------------------------- 1 | record(__FUNCTION__, func_get_args()); 24 | } 25 | 26 | public function edit(array $parameters): EditResponse 27 | { 28 | return $this->record(__FUNCTION__, func_get_args()); 29 | } 30 | 31 | public function variation(array $parameters): VariationResponse 32 | { 33 | return $this->record(__FUNCTION__, func_get_args()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Resources/Concerns/Streamable.php: -------------------------------------------------------------------------------- 1 | $parameters 11 | */ 12 | private function ensureNotStreamed(array $parameters, string $fallbackFunction = 'createStreamed'): void 13 | { 14 | if (! isset($parameters['stream'])) { 15 | return; 16 | } 17 | 18 | if ($parameters['stream'] !== true) { 19 | return; 20 | } 21 | 22 | throw new InvalidArgumentException("Stream option is not supported. Please use the $fallbackFunction() method instead."); 23 | } 24 | 25 | /** 26 | * Set the stream parameter to true. 27 | * 28 | * @param array $parameters 29 | * @return array 30 | */ 31 | private function setStreamParameter(array $parameters): array 32 | { 33 | $parameters['stream'] = true; 34 | 35 | return $parameters; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Testing/Responses/Fixtures/FineTuning/RetrieveJobResponseFixture.php: -------------------------------------------------------------------------------- 1 | 'ftjob-AF1WoRqd3aJAHsqc9NY7iL8F', 9 | 'object' => 'fine_tuning.job', 10 | 'model' => 'gpt-3.5-turbo-0613', 11 | 'created_at' => 1_614_807_352, 12 | 'finished_at' => 1_692_819_450, 13 | 'fine_tuned_model' => 'ft:gpt-3.5-turbo-0613:gehri-dev::7qnxQ0sQ', 14 | 'hyperparameters' => [ 15 | 'n_epochs' => 9, 16 | 'batch_size' => 1, 17 | 'learning_rate_multiplier' => 2, 18 | ], 19 | 'organization_id' => 'org-jwe45798ASN82s', 20 | 'result_files' => [ 21 | 'file-1bl05WrhsKDDEdg8XSP617QF', 22 | ], 23 | 'status' => 'succeeded', 24 | 'validation_file' => null, 25 | 'training_file' => 'file-abc123', 26 | 'trained_tokens' => 5049, 27 | 'error' => null, 28 | ]; 29 | } 30 | -------------------------------------------------------------------------------- /src/Testing/Responses/Fixtures/Chat/CreateResponseFixture.php: -------------------------------------------------------------------------------- 1 | 'chatcmpl-123', 9 | 'object' => 'chat.completion', 10 | 'created' => 1_677_652_288, 11 | 'model' => 'gpt-3.5-turbo', 12 | 'system_fingerprint' => null, 13 | 'choices' => [ 14 | [ 15 | 'index' => 0, 16 | 'message' => [ 17 | 'role' => 'assistant', 18 | 'content' => "\n\nHello there, this is a fake chat response.", 19 | 'function_call' => null, 20 | 'tool_calls' => [], 21 | ], 22 | 'logprobs' => null, 23 | 'finish_reason' => 'stop', 24 | ], 25 | ], 26 | 'usage' => [ 27 | 'prompt_tokens' => 9, 28 | 'completion_tokens' => 12, 29 | 'total_tokens' => 21, 30 | ], 31 | ]; 32 | } 33 | -------------------------------------------------------------------------------- /src/Testing/Resources/Concerns/Testable.php: -------------------------------------------------------------------------------- 1 | $args 18 | */ 19 | protected function record(string $method, array $args = []): ResponseContract|ResponseStreamContract|string 20 | { 21 | return $this->fake->record(new TestRequest($this->resource(), $method, $args)); 22 | } 23 | 24 | public function assertSent(callable|int|null $callback = null): void 25 | { 26 | $this->fake->assertSent($this->resource(), $callback); 27 | } 28 | 29 | public function assertNotSent(callable|int|null $callback = null): void 30 | { 31 | $this->fake->assertNotSent($this->resource(), $callback); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Testing/Responses/Fixtures/Realtime/SessionResponseFixture.php: -------------------------------------------------------------------------------- 1 | [ 9 | 'expires_at' => 1735680000, 10 | 'value' => 'ek_secret_123', 11 | ], 12 | 'input_audio_format' => 'pcm16', 13 | 'input_audio_transcription' => null, 14 | 'instructions' => 'Your knowledge cutoff is 2023-10. You are a helpful assistant.', 15 | 'max_response_output_tokens' => 'inf', 16 | 'modalities' => [ 17 | 'audio', 18 | 'text', 19 | ], 20 | 'output_audio_format' => 'pcm16', 21 | 'temperature' => 0.7, 22 | 'tool_choice' => 'auto', 23 | 'tools' => [], 24 | 'turn_detection' => [ 25 | 'prefix_padding_ms' => 100, 26 | 'silence_duration_ms' => 500, 27 | 'threshold' => 0.5, 28 | 'type' => 'server_vad', 29 | ], 30 | 'voice' => 'alloy', 31 | ]; 32 | } 33 | -------------------------------------------------------------------------------- /src/Testing/Responses/Fixtures/Assistants/AssistantListResponseFixture.php: -------------------------------------------------------------------------------- 1 | 'list', 9 | 'data' => [ 10 | [ 11 | 'id' => 'asst_SMzoVX8XmCZEg1EbMHoAm8tc', 12 | 'object' => 'assistant', 13 | 'created_at' => 1_699_619_403, 14 | 'name' => 'Math Tutor', 15 | 'description' => null, 16 | 'model' => 'gpt-4', 17 | 'instructions' => 'You are a personal math tutor.', 18 | 'tools' => [], 19 | 'tool_resources' => [], 20 | 'metadata' => [], 21 | 'temperature' => 0.7, 22 | 'top_p' => 1.0, 23 | 'response_format' => 'text', 24 | ], 25 | ], 26 | 'first_id' => 'asst_SMzoVX8XmCZEg1EbMHoAm8tc', 27 | 'last_id' => 'asst_SMzoVX8XmCZEg1EbMHoAm8tc', 28 | 'has_more' => false, 29 | ]; 30 | } 31 | -------------------------------------------------------------------------------- /src/Responses/Chat/CreateResponseChoiceAnnotations.php: -------------------------------------------------------------------------------- 1 | $this->type, 30 | 'url_citation' => $this->urlCitations->toArray(), 31 | ]; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Responses/Chat/CreateResponseUsagePromptTokensDetails.php: -------------------------------------------------------------------------------- 1 | $this->cachedTokens, 32 | ]; 33 | 34 | if (! is_null($this->audioTokens)) { 35 | $result['audio_tokens'] = $this->audioTokens; 36 | } 37 | 38 | return $result; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Responses/Concerns/ArrayAccessible.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | trait ArrayAccessible 15 | { 16 | /** 17 | * {@inheritDoc} 18 | */ 19 | public function offsetExists(mixed $offset): bool 20 | { 21 | return array_key_exists($offset, $this->toArray()); 22 | } 23 | 24 | /** 25 | * {@inheritDoc} 26 | */ 27 | public function offsetGet(mixed $offset): mixed 28 | { 29 | return $this->toArray()[$offset]; // @phpstan-ignore-line 30 | } 31 | 32 | /** 33 | * {@inheritDoc} 34 | */ 35 | public function offsetSet(mixed $offset, mixed $value): never 36 | { 37 | throw new BadMethodCallException('Cannot set response attributes.'); 38 | } 39 | 40 | /** 41 | * {@inheritDoc} 42 | */ 43 | public function offsetUnset(mixed $offset): never 44 | { 45 | throw new BadMethodCallException('Cannot unset response attributes.'); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Testing/Responses/Fixtures/VectorStores/Search/VectorStoreSearchResponseFixture.php: -------------------------------------------------------------------------------- 1 | 'vector_store.search_results.page', 9 | 'search_query' => 'What is the return policy?', 10 | 'data' => [ 11 | VectorStoreSearchResponseFileFixture::ATTRIBUTES, 12 | [ 13 | 'file_id' => 'file_xyz789', 14 | 'filename' => 'notes.txt', 15 | 'score' => 0.89, 16 | 'attributes' => [ 17 | 'author' => 'Jane Smith', 18 | 'date' => '2023-01-02', 19 | ], 20 | 'content' => [ 21 | [ 22 | 'type' => 'text', 23 | 'text' => 'Sample text content from the vector store.', 24 | ], 25 | ], 26 | ], 27 | ], 28 | 'has_more' => false, 29 | 'next_page' => null, 30 | ]; 31 | } 32 | -------------------------------------------------------------------------------- /src/Responses/Chat/CreateStreamedResponseFunctionCall.php: -------------------------------------------------------------------------------- 1 | name)) { 36 | $data['name'] = $this->name; 37 | } 38 | 39 | if (! is_null($this->arguments)) { 40 | $data['arguments'] = $this->arguments; 41 | } 42 | 43 | return $data; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Contracts/Resources/ModelsContract.php: -------------------------------------------------------------------------------- 1 | $this->promptTokens, 34 | 'completion_tokens' => $this->completionTokens, 35 | 'total_tokens' => $this->totalTokens, 36 | ]; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Testing/Resources/BatchesTestResource.php: -------------------------------------------------------------------------------- 1 | record(__FUNCTION__, func_get_args()); 23 | } 24 | 25 | public function retrieve(string $id): BatchResponse 26 | { 27 | return $this->record(__FUNCTION__, func_get_args()); 28 | } 29 | 30 | public function cancel(string $id): BatchResponse 31 | { 32 | return $this->record(__FUNCTION__, func_get_args()); 33 | } 34 | 35 | public function list(array $parameters = []): BatchListResponse 36 | { 37 | return $this->record(__FUNCTION__, func_get_args()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/ValueObjects/Transporter/QueryParams.php: -------------------------------------------------------------------------------- 1 | $params 16 | */ 17 | private function __construct(private readonly array $params) 18 | { 19 | // .. 20 | } 21 | 22 | /** 23 | * Creates a new Query Params value object 24 | */ 25 | public static function create(): self 26 | { 27 | return new self([]); 28 | } 29 | 30 | /** 31 | * Creates a new Query Params value object, with the newly added param, and the existing params. 32 | */ 33 | public function withParam(string $name, string|int $value): self 34 | { 35 | return new self([ 36 | ...$this->params, 37 | $name => $value, 38 | ]); 39 | } 40 | 41 | /** 42 | * @return array 43 | */ 44 | public function toArray(): array 45 | { 46 | return $this->params; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Responses/Chat/CreateResponseToolCall.php: -------------------------------------------------------------------------------- 1 | $this->id, 34 | 'type' => $this->type, 35 | 'function' => $this->function->toArray(), 36 | ]; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Nuno Maduro 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/Contracts/TransporterContract.php: -------------------------------------------------------------------------------- 1 | |string> 23 | * 24 | * @throws ErrorException|UnserializableResponse|TransporterException 25 | */ 26 | public function requestObject(Payload $payload): Response; 27 | 28 | /** 29 | * Sends a content request to a server. 30 | * 31 | * @throws ErrorException|TransporterException 32 | */ 33 | public function requestContent(Payload $payload): string; 34 | 35 | /** 36 | * Sends a stream request to a server. 37 | ** 38 | * @throws ErrorException 39 | */ 40 | public function requestStream(Payload $payload): ResponseInterface; 41 | } 42 | -------------------------------------------------------------------------------- /src/Resources/Embeddings.php: -------------------------------------------------------------------------------- 1 | $parameters 22 | */ 23 | public function create(array $parameters): CreateResponse 24 | { 25 | $payload = Payload::create('embeddings', $parameters); 26 | 27 | /** @var Response, index: int}>, usage: array{prompt_tokens: int, total_tokens: int}}> $response */ 28 | $response = $this->transporter->requestObject($payload); 29 | 30 | return CreateResponse::from($response->data(), $response->meta()); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Responses/Completions/CreateResponseUsage.php: -------------------------------------------------------------------------------- 1 | $this->promptTokens, 34 | 'completion_tokens' => $this->completionTokens, 35 | 'total_tokens' => $this->totalTokens, 36 | ]; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Responses/Threads/Runs/ThreadRunResponseUsage.php: -------------------------------------------------------------------------------- 1 | $this->promptTokens, 34 | 'completion_tokens' => $this->completionTokens, 35 | 'total_tokens' => $this->totalTokens, 36 | ]; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Testing/Responses/Fixtures/Batches/BatchResponseFixture.php: -------------------------------------------------------------------------------- 1 | 'batch_abc123', 9 | 'object' => 'batch', 10 | 'endpoint' => '/v1/chat/completions', 11 | 'errors' => null, 12 | 'input_file_id' => 'file-abc123', 13 | 'completion_window' => '24h', 14 | 'status' => 'validating', 15 | 'output_file_id' => null, 16 | 'error_file_id' => null, 17 | 'created_at' => 1_711_471_533, 18 | 'in_progress_at' => null, 19 | 'expires_at' => null, 20 | 'finalizing_at' => null, 21 | 'completed_at' => null, 22 | 'failed_at' => null, 23 | 'expired_at' => null, 24 | 'cancelling_at' => null, 25 | 'cancelled_at' => null, 26 | 'request_counts' => [ 27 | 'total' => 0, 28 | 'completed' => 0, 29 | 'failed' => 0, 30 | ], 31 | 'metadata' => [ 32 | 'customer_id' => 'user_123456789', 33 | 'batch_description' => 'Nightly eval job', 34 | ], 35 | ]; 36 | } 37 | -------------------------------------------------------------------------------- /src/Responses/Assistants/AssistantResponseToolFileSearch.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | final class AssistantResponseToolFileSearch implements ResponseContract 15 | { 16 | /** 17 | * @use ArrayAccessible 18 | */ 19 | use ArrayAccessible; 20 | 21 | use Fakeable; 22 | 23 | private function __construct( 24 | public string $type, 25 | ) {} 26 | 27 | /** 28 | * Acts as static factory, and returns a new Response instance. 29 | * 30 | * @param array{type: 'file_search'} $attributes 31 | */ 32 | public static function from(array $attributes): self 33 | { 34 | return new self( 35 | $attributes['type'], 36 | ); 37 | } 38 | 39 | /** 40 | * {@inheritDoc} 41 | */ 42 | public function toArray(): array 43 | { 44 | return [ 45 | 'type' => $this->type, 46 | ]; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Responses/Chat/CreateResponseChoiceAnnotationsUrlCitations.php: -------------------------------------------------------------------------------- 1 | $this->endIndex, 34 | 'start_index' => $this->startIndex, 35 | 'title' => $this->title, 36 | 'url' => $this->url, 37 | ]; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Responses/Threads/Runs/ThreadRunResponseFileSearch.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | final class ThreadRunResponseFileSearch implements ResponseContract 15 | { 16 | /** 17 | * @use ArrayAccessible 18 | */ 19 | use ArrayAccessible; 20 | 21 | use Fakeable; 22 | 23 | private function __construct( 24 | public string $type, 25 | ) {} 26 | 27 | /** 28 | * Acts as static factory, and returns a new Response instance. 29 | * 30 | * @param array{type: 'file_search'} $attributes 31 | */ 32 | public static function from(array $attributes): self 33 | { 34 | return new self( 35 | $attributes['type'], 36 | ); 37 | } 38 | 39 | /** 40 | * {@inheritDoc} 41 | */ 42 | public function toArray(): array 43 | { 44 | return [ 45 | 'type' => $this->type, 46 | ]; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Contracts/Resources/ImagesContract.php: -------------------------------------------------------------------------------- 1 | $parameters 17 | */ 18 | public function create(array $parameters): CreateResponse; 19 | 20 | /** 21 | * Creates an edited or extended image given an original image and a prompt. 22 | * 23 | * @see https://platform.openai.com/docs/api-reference/images/create-edit 24 | * 25 | * @param array $parameters 26 | */ 27 | public function edit(array $parameters): EditResponse; 28 | 29 | /** 30 | * Creates a variation of a given image. 31 | * 32 | * @see https://platform.openai.com/docs/api-reference/images/create-variation 33 | * 34 | * @param array $parameters 35 | */ 36 | public function variation(array $parameters): VariationResponse; 37 | } 38 | -------------------------------------------------------------------------------- /src/Responses/Assistants/AssistantResponseResponseFormatText.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | final class AssistantResponseResponseFormatText implements ResponseContract 15 | { 16 | /** 17 | * @use ArrayAccessible 18 | */ 19 | use ArrayAccessible; 20 | 21 | use Fakeable; 22 | 23 | private function __construct( 24 | public string $type, 25 | ) {} 26 | 27 | /** 28 | * Acts as static factory, and returns a new Response instance. 29 | * 30 | * @param array{type: 'text'} $attributes 31 | */ 32 | public static function from(array $attributes): self 33 | { 34 | return new self( 35 | $attributes['type'], 36 | ); 37 | } 38 | 39 | /** 40 | * {@inheritDoc} 41 | */ 42 | public function toArray(): array 43 | { 44 | return [ 45 | 'type' => $this->type, 46 | ]; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Responses/Responses/Format/TextFormat.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | final class TextFormat implements ResponseContract 17 | { 18 | /** 19 | * @use ArrayAccessible 20 | */ 21 | use ArrayAccessible; 22 | 23 | use Fakeable; 24 | 25 | /** 26 | * @param 'text' $type 27 | */ 28 | private function __construct( 29 | public readonly string $type, 30 | ) {} 31 | 32 | /** 33 | * @param TextFormatType $attributes 34 | */ 35 | public static function from(array $attributes): self 36 | { 37 | return new self( 38 | type: $attributes['type'], 39 | ); 40 | } 41 | 42 | /** 43 | * {@inheritDoc} 44 | */ 45 | public function toArray(): array 46 | { 47 | return [ 48 | 'type' => $this->type, 49 | ]; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Responses/Threads/Runs/ThreadRunResponseToolChoiceFunction.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | final class ThreadRunResponseToolChoiceFunction implements ResponseContract 15 | { 16 | /** 17 | * @use ArrayAccessible 18 | */ 19 | use ArrayAccessible; 20 | 21 | use Fakeable; 22 | 23 | private function __construct( 24 | public string $name, 25 | ) {} 26 | 27 | /** 28 | * Acts as static factory, and returns a new Response instance. 29 | * 30 | * @param array{name: string} $attributes 31 | */ 32 | public static function from(array $attributes): self 33 | { 34 | return new self( 35 | $attributes['name'], 36 | ); 37 | } 38 | 39 | /** 40 | * {@inheritDoc} 41 | */ 42 | public function toArray(): array 43 | { 44 | return [ 45 | 'name' => $this->name, 46 | ]; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Responses/Assistants/AssistantResponseResponseFormat.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | final class AssistantResponseResponseFormat implements ResponseContract 15 | { 16 | /** 17 | * @use ArrayAccessible 18 | */ 19 | use ArrayAccessible; 20 | 21 | use Fakeable; 22 | 23 | private function __construct( 24 | public string $type, 25 | ) {} 26 | 27 | /** 28 | * Acts as static factory, and returns a new Response instance. 29 | * 30 | * @param array{type: 'text'|'json_object'} $attributes 31 | */ 32 | public static function from(array $attributes): self 33 | { 34 | return new self( 35 | $attributes['type'], 36 | ); 37 | } 38 | 39 | /** 40 | * {@inheritDoc} 41 | */ 42 | public function toArray(): array 43 | { 44 | return [ 45 | 'type' => $this->type, 46 | ]; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Testing/Responses/Fixtures/Threads/Runs/Steps/ThreadRunStepResponseFixture.php: -------------------------------------------------------------------------------- 1 | 'step_1spQXgbAabXFm1YXrwiGIMUz', 9 | 'object' => 'thread.run.step', 10 | 'created_at' => 1_699_564_106, 11 | 'run_id' => 'run_fYijubpOJsKDnvtACWBS8C8r', 12 | 'assistant_id' => 'asst_EopvUEMh90bxkNRYEYM81Orc', 13 | 'thread_id' => 'thread_3WdOgtVuhD8aUIEx774Whkvo', 14 | 'type' => 'message_creation', 15 | 'status' => 'completed', 16 | 'cancelled_at' => null, 17 | 'completed_at' => 1_699_564_119, 18 | 'expires_at' => null, 19 | 'failed_at' => null, 20 | 'last_error' => null, 21 | 'step_details' => [ 22 | 'type' => 'message_creation', 23 | 'message_creation' => [ 24 | 'message_id' => 'msg_i404PxKbB92d0JAmdOIcX7vA', 25 | ], 26 | ], 27 | 'usage' => [ 28 | 'prompt_tokens' => 123, 29 | 'completion_tokens' => 456, 30 | 'total_tokens' => 579, 31 | ], 32 | ]; 33 | } 34 | -------------------------------------------------------------------------------- /src/Responses/Assistants/AssistantResponseToolCodeInterpreter.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | final class AssistantResponseToolCodeInterpreter implements ResponseContract 15 | { 16 | /** 17 | * @use ArrayAccessible 18 | */ 19 | use ArrayAccessible; 20 | 21 | use Fakeable; 22 | 23 | private function __construct( 24 | public string $type, 25 | ) {} 26 | 27 | /** 28 | * Acts as static factory, and returns a new Response instance. 29 | * 30 | * @param array{type: 'code_interpreter'} $attributes 31 | */ 32 | public static function from(array $attributes): self 33 | { 34 | return new self( 35 | $attributes['type'], 36 | ); 37 | } 38 | 39 | /** 40 | * {@inheritDoc} 41 | */ 42 | public function toArray(): array 43 | { 44 | return [ 45 | 'type' => $this->type, 46 | ]; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Responses/Responses/CreateResponseIncompleteDetails.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | final class CreateResponseIncompleteDetails implements ResponseContract 17 | { 18 | /** 19 | * @use ArrayAccessible 20 | */ 21 | use ArrayAccessible; 22 | 23 | use Fakeable; 24 | 25 | private function __construct( 26 | public readonly string $reason, 27 | ) {} 28 | 29 | /** 30 | * @param IncompleteDetailsType $attributes 31 | */ 32 | public static function from(array $attributes): self 33 | { 34 | return new self( 35 | reason: $attributes['reason'], 36 | ); 37 | } 38 | 39 | /** 40 | * {@inheritDoc} 41 | */ 42 | public function toArray(): array 43 | { 44 | return [ 45 | 'reason' => $this->reason, 46 | ]; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Responses/Embeddings/CreateResponseEmbedding.php: -------------------------------------------------------------------------------- 1 | $embedding 11 | */ 12 | private function __construct( 13 | public readonly string $object, 14 | public readonly ?int $index, 15 | public readonly array $embedding, 16 | ) {} 17 | 18 | /** 19 | * @param array{object: string, index?: int, embedding: array} $attributes 20 | */ 21 | public static function from(array $attributes): self 22 | { 23 | return new self( 24 | $attributes['object'], 25 | $attributes['index'] ?? null, 26 | $attributes['embedding'], 27 | ); 28 | } 29 | 30 | /** 31 | * @return array{object: string, index?: int, embedding: array} 32 | */ 33 | public function toArray(): array 34 | { 35 | return array_filter([ 36 | 'object' => $this->object, 37 | 'index' => $this->index, 38 | 'embedding' => $this->embedding, 39 | ], fn (mixed $value): bool => ! is_null($value)); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Responses/Threads/Runs/ThreadRunResponseIncompleteDetails.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | final class ThreadRunResponseIncompleteDetails implements ResponseContract 15 | { 16 | /** 17 | * @use ArrayAccessible 18 | */ 19 | use ArrayAccessible; 20 | 21 | use Fakeable; 22 | 23 | private function __construct( 24 | public string $reason, 25 | ) {} 26 | 27 | /** 28 | * Acts as static factory, and returns a new Response instance. 29 | * 30 | * @param array{reason: string} $attributes 31 | */ 32 | public static function from(array $attributes): self 33 | { 34 | return new self( 35 | $attributes['reason'], 36 | ); 37 | } 38 | 39 | /** 40 | * {@inheritDoc} 41 | */ 42 | public function toArray(): array 43 | { 44 | return [ 45 | 'reason' => $this->reason, 46 | ]; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Responses/Threads/Runs/ThreadRunResponseToolCodeInterpreter.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | final class ThreadRunResponseToolCodeInterpreter implements ResponseContract 15 | { 16 | /** 17 | * @use ArrayAccessible 18 | */ 19 | use ArrayAccessible; 20 | 21 | use Fakeable; 22 | 23 | private function __construct( 24 | public string $type, 25 | ) {} 26 | 27 | /** 28 | * Acts as static factory, and returns a new Response instance. 29 | * 30 | * @param array{type: 'code_interpreter'} $attributes 31 | */ 32 | public static function from(array $attributes): self 33 | { 34 | return new self( 35 | $attributes['type'], 36 | ); 37 | } 38 | 39 | /** 40 | * {@inheritDoc} 41 | */ 42 | public function toArray(): array 43 | { 44 | return [ 45 | 'type' => $this->type, 46 | ]; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Testing/Responses/Fixtures/Audio/TranslationResponseFixture.php: -------------------------------------------------------------------------------- 1 | 'translate', 9 | 'language' => 'english', 10 | 'duration' => 2.95, 11 | 'segments' => [ 12 | [ 13 | 'id' => 0, 14 | 'seek' => 0, 15 | 'start' => 0.0, 16 | 'end' => 4.0, 17 | 'text' => ' Hello, this is a fake translation response.', 18 | 'tokens' => [ 19 | 50364, 20 | 2425, 21 | 11, 22 | 577, 23 | 366, 24 | 291, 25 | 30, 26 | 50564, 27 | ], 28 | 'temperature' => 0.0, 29 | 'avg_logprob' => -0.45045216878255206, 30 | 'compression_ratio' => 0.7037037037037037, 31 | 'no_speech_prob' => 0.1076972484588623, 32 | 'transient' => false, 33 | ], 34 | ], 35 | 'text' => 'Hello, how are you?', 36 | ]; 37 | } 38 | -------------------------------------------------------------------------------- /src/Resources/Moderations.php: -------------------------------------------------------------------------------- 1 | $parameters 22 | */ 23 | public function create(array $parameters): CreateResponse 24 | { 25 | $payload = Payload::create('moderations', $parameters); 26 | 27 | /** @var Response, category_scores: array, flagged: bool,category_applied_input_types?: array>}>}> $response */ 28 | $response = $this->transporter->requestObject($payload); 29 | 30 | return CreateResponse::from($response->data(), $response->meta()); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Testing/Responses/Fixtures/Audio/TranscriptionResponseFixture.php: -------------------------------------------------------------------------------- 1 | 'transcribe', 9 | 'language' => 'english', 10 | 'duration' => 2.95, 11 | 'segments' => [ 12 | [ 13 | 'id' => 0, 14 | 'seek' => 0, 15 | 'start' => 0.0, 16 | 'end' => 4.0, 17 | 'text' => ' Hello, this is a fake transcription response.', 18 | 'tokens' => [ 19 | 50364, 20 | 2425, 21 | 11, 22 | 577, 23 | 366, 24 | 291, 25 | 30, 26 | 50564, 27 | ], 28 | 'temperature' => 0.0, 29 | 'avg_logprob' => -0.45045216878255206, 30 | 'compression_ratio' => 0.7037037037037037, 31 | 'no_speech_prob' => 0.1076972484588623, 32 | 'transient' => false, 33 | ], 34 | ], 35 | 'text' => 'Hello, how are you?', 36 | ]; 37 | } 38 | -------------------------------------------------------------------------------- /src/Responses/Threads/Messages/ThreadMessageResponseIncompleteDetails.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | final class ThreadMessageResponseIncompleteDetails implements ResponseContract 15 | { 16 | /** 17 | * @use ArrayAccessible 18 | */ 19 | use ArrayAccessible; 20 | 21 | use Fakeable; 22 | 23 | private function __construct( 24 | public string $reason, 25 | ) {} 26 | 27 | /** 28 | * Acts as static factory, and returns a new Response instance. 29 | * 30 | * @param array{reason: string} $attributes 31 | */ 32 | public static function from(array $attributes): self 33 | { 34 | return new self( 35 | $attributes['reason'], 36 | ); 37 | } 38 | 39 | /** 40 | * {@inheritDoc} 41 | */ 42 | public function toArray(): array 43 | { 44 | return [ 45 | 'reason' => $this->reason, 46 | ]; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Responses/Responses/Output/ComputerAction/OutputComputerActionWait.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | final class OutputComputerActionWait implements ResponseContract 17 | { 18 | /** 19 | * @use ArrayAccessible 20 | */ 21 | use ArrayAccessible; 22 | 23 | use Fakeable; 24 | 25 | /** 26 | * @param 'wait' $type 27 | */ 28 | private function __construct( 29 | public readonly string $type, 30 | ) {} 31 | 32 | /** 33 | * @param WaitType $attributes 34 | */ 35 | public static function from(array $attributes): self 36 | { 37 | return new self( 38 | type: $attributes['type'], 39 | ); 40 | } 41 | 42 | /** 43 | * {@inheritDoc} 44 | */ 45 | public function toArray(): array 46 | { 47 | return [ 48 | 'type' => $this->type, 49 | ]; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Responses/Responses/CreateResponseUsageInputTokenDetails.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | final class CreateResponseUsageInputTokenDetails implements ResponseContract 17 | { 18 | /** 19 | * @use ArrayAccessible 20 | */ 21 | use ArrayAccessible; 22 | 23 | use Fakeable; 24 | 25 | private function __construct( 26 | public readonly int $cachedTokens, 27 | ) {} 28 | 29 | /** 30 | * @param InputTokenDetailsType $attributes 31 | */ 32 | public static function from(array $attributes): self 33 | { 34 | return new self( 35 | cachedTokens: $attributes['cached_tokens'], 36 | ); 37 | } 38 | 39 | /** 40 | * {@inheritDoc} 41 | */ 42 | public function toArray(): array 43 | { 44 | return [ 45 | 'cached_tokens' => $this->cachedTokens, 46 | ]; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Responses/Responses/Format/JsonObjectFormat.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | final class JsonObjectFormat implements ResponseContract 17 | { 18 | /** 19 | * @use ArrayAccessible 20 | */ 21 | use ArrayAccessible; 22 | 23 | use Fakeable; 24 | 25 | /** 26 | * @param 'json_object' $type 27 | */ 28 | private function __construct( 29 | public readonly string $type, 30 | ) {} 31 | 32 | /** 33 | * @param JsonObjectFormatType $attributes 34 | */ 35 | public static function from(array $attributes): self 36 | { 37 | return new self( 38 | type: $attributes['type'], 39 | ); 40 | } 41 | 42 | /** 43 | * {@inheritDoc} 44 | */ 45 | public function toArray(): array 46 | { 47 | return [ 48 | 'type' => $this->type, 49 | ]; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Responses/Threads/Runs/Steps/ThreadRunStepResponseMessageCreation.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | final class ThreadRunStepResponseMessageCreation implements ResponseContract 15 | { 16 | /** 17 | * @use ArrayAccessible 18 | */ 19 | use ArrayAccessible; 20 | 21 | use Fakeable; 22 | 23 | private function __construct( 24 | public string $messageId, 25 | ) {} 26 | 27 | /** 28 | * Acts as static factory, and returns a new Response instance. 29 | * 30 | * @param array{message_id: string} $attributes 31 | */ 32 | public static function from(array $attributes): self 33 | { 34 | return new self( 35 | $attributes['message_id'], 36 | ); 37 | } 38 | 39 | /** 40 | * {@inheritDoc} 41 | */ 42 | public function toArray(): array 43 | { 44 | return [ 45 | 'message_id' => $this->messageId, 46 | ]; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Testing/Responses/Fixtures/Threads/Messages/ThreadMessageResponseFixture.php: -------------------------------------------------------------------------------- 1 | 'msg_KNsDDwE41BUAHhcPNpDkdHWZ', 9 | 'object' => 'thread.message', 10 | 'created_at' => 1_699_623_839, 11 | 'thread_id' => 'thread_agvtHUGezjTCt4SKgQg0NJ2Y', 12 | 'status' => 'in_progress', 13 | 'incomplete_details' => null, 14 | 'completed_at' => null, 15 | 'incomplete_at' => null, 16 | 'role' => 'user', 17 | 'content' => [ 18 | [ 19 | 'type' => 'text', 20 | 'text' => [ 21 | 'value' => 'How does AI work? Explain it in simple terms.', 22 | 'annotations' => [ 23 | ], 24 | ], 25 | ], 26 | ], 27 | 'attachments' => [ 28 | [ 29 | 'file_id' => 'file-DhxjnFCaSHc4ZELRGKwTMFtI', 30 | 'tools' => [['type' => 'file_search']], 31 | ], 32 | ], 33 | 'assistant_id' => null, 34 | 'run_id' => null, 35 | 'metadata' => [], 36 | ]; 37 | } 38 | -------------------------------------------------------------------------------- /src/Responses/Chat/CreateResponseChoiceLogprobsContent.php: -------------------------------------------------------------------------------- 1 | $bytes 11 | */ 12 | private function __construct( 13 | public readonly string $token, 14 | public readonly float $logprob, 15 | public readonly ?array $bytes, 16 | ) {} 17 | 18 | /** 19 | * @param array{ 20 | * token: string, 21 | * logprob: float, 22 | * bytes: ?array 23 | * } $attributes 24 | */ 25 | public static function from(array $attributes): self 26 | { 27 | return new self( 28 | $attributes['token'], 29 | $attributes['logprob'], 30 | $attributes['bytes'], 31 | ); 32 | } 33 | 34 | /** 35 | * @return array{ 36 | * token: string, 37 | * logprob: float, 38 | * bytes: ?array 39 | * } 40 | */ 41 | public function toArray(): array 42 | { 43 | return [ 44 | 'token' => $this->token, 45 | 'logprob' => $this->logprob, 46 | 'bytes' => $this->bytes, 47 | ]; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Responses/Threads/Messages/ThreadMessageResponseContentTextAnnotationFilePath.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | final class ThreadMessageResponseContentTextAnnotationFilePath implements ResponseContract 15 | { 16 | /** 17 | * @use ArrayAccessible 18 | */ 19 | use ArrayAccessible; 20 | 21 | use Fakeable; 22 | 23 | private function __construct( 24 | public string $fileId, 25 | ) {} 26 | 27 | /** 28 | * Acts as static factory, and returns a new Response instance. 29 | * 30 | * @param array{file_id: string} $attributes 31 | */ 32 | public static function from(array $attributes): self 33 | { 34 | return new self( 35 | $attributes['file_id'], 36 | 37 | ); 38 | } 39 | 40 | /** 41 | * {@inheritDoc} 42 | */ 43 | public function toArray(): array 44 | { 45 | return [ 46 | 'file_id' => $this->fileId, 47 | ]; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Responses/Threads/Runs/Steps/ThreadRunStepResponseCodeInterpreterOutputImageImage.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | final class ThreadRunStepResponseCodeInterpreterOutputImageImage implements ResponseContract 15 | { 16 | /** 17 | * @use ArrayAccessible 18 | */ 19 | use ArrayAccessible; 20 | 21 | use Fakeable; 22 | 23 | private function __construct( 24 | public string $fileId, 25 | ) {} 26 | 27 | /** 28 | * Acts as static factory, and returns a new Response instance. 29 | * 30 | * @param array{file_id: string} $attributes 31 | */ 32 | public static function from(array $attributes): self 33 | { 34 | return new self( 35 | $attributes['file_id'], 36 | ); 37 | } 38 | 39 | /** 40 | * {@inheritDoc} 41 | */ 42 | public function toArray(): array 43 | { 44 | return [ 45 | 'file_id' => $this->fileId, 46 | ]; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Contracts/Resources/BatchesContract.php: -------------------------------------------------------------------------------- 1 | $parameters 16 | */ 17 | public function create(array $parameters): BatchResponse; 18 | 19 | /** 20 | * Retrieves a batch. 21 | * * 22 | * @see https://platform.openai.com/docs/api-reference/batch/retrieve 23 | */ 24 | public function retrieve(string $id): BatchResponse; 25 | 26 | /** 27 | * Cancels an in-progress batch. 28 | * * 29 | * @see https://platform.openai.com/docs/api-reference/batch/cancel 30 | */ 31 | public function cancel(string $id): BatchResponse; 32 | 33 | /** 34 | * List your organization's batches. 35 | * 36 | * @see https://platform.openai.com/docs/api-reference/batch/list 37 | * 38 | * @param array $parameters 39 | */ 40 | public function list(array $parameters = []): BatchListResponse; 41 | } 42 | -------------------------------------------------------------------------------- /src/Responses/Responses/CreateResponseUsageOutputTokenDetails.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | final class CreateResponseUsageOutputTokenDetails implements ResponseContract 17 | { 18 | /** 19 | * @use ArrayAccessible 20 | */ 21 | use ArrayAccessible; 22 | 23 | use Fakeable; 24 | 25 | private function __construct( 26 | public readonly int $reasoningTokens, 27 | ) {} 28 | 29 | /** 30 | * @param OutputTokenDetailsType $attributes 31 | */ 32 | public static function from(array $attributes): self 33 | { 34 | return new self( 35 | reasoningTokens: $attributes['reasoning_tokens'], 36 | ); 37 | } 38 | 39 | /** 40 | * {@inheritDoc} 41 | */ 42 | public function toArray(): array 43 | { 44 | return [ 45 | 'reasoning_tokens' => $this->reasoningTokens, 46 | ]; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Responses/Responses/CreateResponseError.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | final class CreateResponseError implements ResponseContract 17 | { 18 | /** 19 | * @use ArrayAccessible 20 | */ 21 | use ArrayAccessible; 22 | 23 | use Fakeable; 24 | 25 | private function __construct( 26 | public readonly string $code, 27 | public readonly string $message 28 | ) {} 29 | 30 | /** 31 | * @param ErrorType $attributes 32 | */ 33 | public static function from(array $attributes): self 34 | { 35 | return new self( 36 | code: $attributes['code'], 37 | message: $attributes['message'], 38 | ); 39 | } 40 | 41 | /** 42 | * {@inheritDoc} 43 | */ 44 | public function toArray(): array 45 | { 46 | return [ 47 | 'code' => $this->code, 48 | 'message' => $this->message, 49 | ]; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Responses/Responses/Output/ComputerAction/OutputComputerActionScreenshot.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | final class OutputComputerActionScreenshot implements ResponseContract 17 | { 18 | /** 19 | * @use ArrayAccessible 20 | */ 21 | use ArrayAccessible; 22 | 23 | use Fakeable; 24 | 25 | /** 26 | * @param 'screenshot' $type 27 | */ 28 | private function __construct( 29 | public readonly string $type, 30 | ) {} 31 | 32 | /** 33 | * @param ScreenshotType $attributes 34 | */ 35 | public static function from(array $attributes): self 36 | { 37 | return new self( 38 | type: $attributes['type'], 39 | ); 40 | } 41 | 42 | /** 43 | * {@inheritDoc} 44 | */ 45 | public function toArray(): array 46 | { 47 | return [ 48 | 'type' => $this->type, 49 | ]; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Responses/Responses/Output/ComputerAction/OutputComputerDragPath.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | final class OutputComputerDragPath implements ResponseContract 17 | { 18 | /** 19 | * @use ArrayAccessible 20 | */ 21 | use ArrayAccessible; 22 | 23 | use Fakeable; 24 | 25 | private function __construct( 26 | public readonly int $x, 27 | public readonly int $y, 28 | ) {} 29 | 30 | /** 31 | * @param DragPathType $attributes 32 | */ 33 | public static function from(array $attributes): self 34 | { 35 | return new self( 36 | x: $attributes['x'], 37 | y: $attributes['y'], 38 | ); 39 | } 40 | 41 | /** 42 | * {@inheritDoc} 43 | */ 44 | public function toArray(): array 45 | { 46 | return [ 47 | 'x' => $this->x, 48 | 'y' => $this->y, 49 | ]; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Contracts/ResponseContract.php: -------------------------------------------------------------------------------- 1 | , value-of> 13 | * 14 | * @internal 15 | */ 16 | interface ResponseContract extends ArrayAccess 17 | { 18 | /** 19 | * Returns the array representation of the Response. 20 | * 21 | * @return TArray 22 | */ 23 | public function toArray(): array; 24 | 25 | /** 26 | * @param key-of $offset 27 | */ 28 | public function offsetExists(mixed $offset): bool; 29 | 30 | /** 31 | * @template TOffsetKey of key-of 32 | * 33 | * @param TOffsetKey $offset 34 | * @return TArray[TOffsetKey] 35 | */ 36 | public function offsetGet(mixed $offset): mixed; 37 | 38 | /** 39 | * @template TOffsetKey of key-of 40 | * 41 | * @param TOffsetKey $offset 42 | * @param TArray[TOffsetKey] $value 43 | */ 44 | public function offsetSet(mixed $offset, mixed $value): never; 45 | 46 | /** 47 | * @template TOffsetKey of key-of 48 | * 49 | * @param TOffsetKey $offset 50 | */ 51 | public function offsetUnset(mixed $offset): never; 52 | } 53 | -------------------------------------------------------------------------------- /src/Responses/Realtime/Session/InputAudioTranscription.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | final class InputAudioTranscription implements ResponseContract 17 | { 18 | /** 19 | * @use ArrayAccessible 20 | */ 21 | use ArrayAccessible; 22 | 23 | use Fakeable; 24 | 25 | /** 26 | * @param "whisper-1" $model 27 | */ 28 | private function __construct( 29 | public readonly string $model 30 | ) {} 31 | 32 | /** 33 | * @param InputAudioTranscriptionType $attributes 34 | */ 35 | public static function from(array $attributes): self 36 | { 37 | return new self( 38 | model: $attributes['model'], 39 | ); 40 | } 41 | 42 | /** 43 | * {@inheritDoc} 44 | */ 45 | public function toArray(): array 46 | { 47 | return [ 48 | 'model' => $this->model, 49 | ]; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Responses/Responses/Tool/McpToolNamesFilter.php: -------------------------------------------------------------------------------- 1 | } 13 | * 14 | * @implements ResponseContract 15 | */ 16 | final class McpToolNamesFilter implements ResponseContract 17 | { 18 | /** 19 | * @use ArrayAccessible 20 | */ 21 | use ArrayAccessible; 22 | 23 | use Fakeable; 24 | 25 | /** 26 | * @param array $toolNames 27 | */ 28 | private function __construct( 29 | public readonly array $toolNames, 30 | ) {} 31 | 32 | /** 33 | * @param McpToolNamesFilterType $attributes 34 | */ 35 | public static function from(array $attributes): self 36 | { 37 | return new self( 38 | toolNames: $attributes['tool_names'], 39 | ); 40 | } 41 | 42 | /** 43 | * {@inheritDoc} 44 | */ 45 | public function toArray(): array 46 | { 47 | return [ 48 | 'tool_names' => $this->toolNames, 49 | ]; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Responses/VectorStores/Files/VectorStoreFileResponseChunkingStrategyOther.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | final class VectorStoreFileResponseChunkingStrategyOther implements ResponseContract 15 | { 16 | /** 17 | * @use ArrayAccessible 18 | */ 19 | use ArrayAccessible; 20 | 21 | use Fakeable; 22 | 23 | /** 24 | * @param 'other' $type 25 | */ 26 | private function __construct( 27 | public readonly string $type, 28 | ) {} 29 | 30 | /** 31 | * Acts as static factory, and returns a new Response instance. 32 | * 33 | * @param array{type: 'other'} $attributes 34 | */ 35 | public static function from(array $attributes): self 36 | { 37 | return new self( 38 | $attributes['type'], 39 | ); 40 | } 41 | 42 | /** 43 | * {@inheritDoc} 44 | */ 45 | public function toArray(): array 46 | { 47 | return [ 48 | 'type' => $this->type, 49 | ]; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Contracts/MetaInformationContract.php: -------------------------------------------------------------------------------- 1 | , value-of> 13 | * 14 | * @internal 15 | */ 16 | interface MetaInformationContract extends ArrayAccess 17 | { 18 | /** 19 | * Returns the array representation of the meta information. 20 | * 21 | * @return TArray 22 | */ 23 | public function toArray(): array; 24 | 25 | /** 26 | * @param key-of $offset 27 | */ 28 | public function offsetExists(mixed $offset): bool; 29 | 30 | /** 31 | * @template TOffsetKey of key-of 32 | * 33 | * @param TOffsetKey $offset 34 | * @return TArray[TOffsetKey] 35 | */ 36 | public function offsetGet(mixed $offset): mixed; 37 | 38 | /** 39 | * @template TOffsetKey of key-of 40 | * 41 | * @param TOffsetKey $offset 42 | * @param TArray[TOffsetKey] $value 43 | */ 44 | public function offsetSet(mixed $offset, mixed $value): never; 45 | 46 | /** 47 | * @template TOffsetKey of key-of 48 | * 49 | * @param TOffsetKey $offset 50 | */ 51 | public function offsetUnset(mixed $offset): never; 52 | } 53 | -------------------------------------------------------------------------------- /src/Responses/Chat/CreateStreamedResponseChoice.php: -------------------------------------------------------------------------------- 1 | $this->index, 34 | 'delta' => $this->delta->toArray(), 35 | 'finish_reason' => $this->finishReason, 36 | ]; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Responses/Images/EditResponseData.php: -------------------------------------------------------------------------------- 1 | 12 | */ 13 | final class EditResponseData implements ResponseContract 14 | { 15 | /** 16 | * @use ArrayAccessible 17 | */ 18 | use ArrayAccessible; 19 | 20 | private function __construct( 21 | public readonly string $url, 22 | public readonly string $b64_json, 23 | ) {} 24 | 25 | /** 26 | * Acts as static factory, and returns a new Response instance. 27 | * 28 | * @param array{url?: string, b64_json?: string} $attributes 29 | */ 30 | public static function from(array $attributes): self 31 | { 32 | return new self( 33 | $attributes['url'] ?? '', 34 | $attributes['b64_json'] ?? '', 35 | ); 36 | } 37 | 38 | /** 39 | * {@inheritDoc} 40 | */ 41 | public function toArray(): array 42 | { 43 | return $this->url !== '' && $this->url !== '0' ? 44 | ['url' => $this->url] : 45 | ['b64_json' => $this->b64_json]; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Responses/Threads/Messages/ThreadMessageResponseAttachmentFileSearchTool.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | final class ThreadMessageResponseAttachmentFileSearchTool implements ResponseContract 15 | { 16 | /** 17 | * @use ArrayAccessible 18 | */ 19 | use ArrayAccessible; 20 | 21 | use Fakeable; 22 | 23 | /** 24 | * @param 'file_search' $type 25 | */ 26 | private function __construct( 27 | public string $type, 28 | ) {} 29 | 30 | /** 31 | * Acts as static factory, and returns a new Response instance. 32 | * 33 | * @param array{type: 'file_search'} $attributes 34 | */ 35 | public static function from(array $attributes): self 36 | { 37 | return new self( 38 | $attributes['type'], 39 | ); 40 | } 41 | 42 | /** 43 | * {@inheritDoc} 44 | */ 45 | public function toArray(): array 46 | { 47 | return [ 48 | 'type' => $this->type, 49 | ]; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Responses/Realtime/Session/ClientSecret.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | final class ClientSecret implements ResponseContract 17 | { 18 | /** 19 | * @use ArrayAccessible 20 | */ 21 | use ArrayAccessible; 22 | 23 | use Fakeable; 24 | 25 | private function __construct( 26 | public readonly int $expiresAt, 27 | public readonly string $value, 28 | ) {} 29 | 30 | /** 31 | * @param ClientSecretType $attributes 32 | */ 33 | public static function from(array $attributes): self 34 | { 35 | return new self( 36 | expiresAt: $attributes['expires_at'], 37 | value: $attributes['value'], 38 | ); 39 | } 40 | 41 | /** 42 | * {@inheritDoc} 43 | */ 44 | public function toArray(): array 45 | { 46 | return [ 47 | 'expires_at' => $this->expiresAt, 48 | 'value' => $this->value, 49 | ]; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Responses/Images/VariationResponseData.php: -------------------------------------------------------------------------------- 1 | 12 | */ 13 | final class VariationResponseData implements ResponseContract 14 | { 15 | /** 16 | * @use ArrayAccessible 17 | */ 18 | use ArrayAccessible; 19 | 20 | private function __construct( 21 | public readonly string $url, 22 | public readonly string $b64_json, 23 | ) {} 24 | 25 | /** 26 | * Acts as static factory, and returns a new Response instance. 27 | * 28 | * @param array{url?: string, b64_json?: string} $attributes 29 | */ 30 | public static function from(array $attributes): self 31 | { 32 | return new self( 33 | $attributes['url'] ?? '', 34 | $attributes['b64_json'] ?? '', 35 | ); 36 | } 37 | 38 | /** 39 | * {@inheritDoc} 40 | */ 41 | public function toArray(): array 42 | { 43 | return $this->url !== '' && $this->url !== '0' ? 44 | ['url' => $this->url] : 45 | ['b64_json' => $this->b64_json]; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Responses/Responses/ToolChoice/HostedToolChoice.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | final class HostedToolChoice implements ResponseContract 17 | { 18 | /** 19 | * @use ArrayAccessible 20 | */ 21 | use ArrayAccessible; 22 | 23 | use Fakeable; 24 | 25 | /** 26 | * @param 'file_search'|'web_search_preview'|'computer_use_preview' $type 27 | */ 28 | private function __construct( 29 | public readonly string $type, 30 | ) {} 31 | 32 | /** 33 | * @param HostedToolChoiceType $attributes 34 | */ 35 | public static function from(array $attributes): self 36 | { 37 | return new self( 38 | type: $attributes['type'], 39 | ); 40 | } 41 | 42 | /** 43 | * {@inheritDoc} 44 | */ 45 | public function toArray(): array 46 | { 47 | return [ 48 | 'type' => $this->type, 49 | ]; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Responses/Assistants/AssistantResponseToolResourceCodeInterpreter.php: -------------------------------------------------------------------------------- 1 | }> 13 | */ 14 | final class AssistantResponseToolResourceCodeInterpreter implements ResponseContract 15 | { 16 | /** 17 | * @use ArrayAccessible}> 18 | */ 19 | use ArrayAccessible; 20 | 21 | use Fakeable; 22 | 23 | /** 24 | * @param array $fileIds 25 | */ 26 | private function __construct( 27 | public array $fileIds, 28 | ) {} 29 | 30 | /** 31 | * Acts as static factory, and returns a new Response instance. 32 | * 33 | * @param array{file_ids: array} $attributes 34 | */ 35 | public static function from(array $attributes): self 36 | { 37 | return new self( 38 | $attributes['file_ids'], 39 | ); 40 | } 41 | 42 | /** 43 | * {@inheritDoc} 44 | */ 45 | public function toArray(): array 46 | { 47 | return [ 48 | 'file_ids' => $this->fileIds, 49 | ]; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Responses/Threads/Messages/ThreadMessageResponseAttachmentCodeInterpreterTool.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | final class ThreadMessageResponseAttachmentCodeInterpreterTool implements ResponseContract 15 | { 16 | /** 17 | * @use ArrayAccessible 18 | */ 19 | use ArrayAccessible; 20 | 21 | use Fakeable; 22 | 23 | /** 24 | * @param 'code_interpreter' $type 25 | */ 26 | private function __construct( 27 | public string $type, 28 | ) {} 29 | 30 | /** 31 | * Acts as static factory, and returns a new Response instance. 32 | * 33 | * @param array{type: 'code_interpreter'} $attributes 34 | */ 35 | public static function from(array $attributes): self 36 | { 37 | return new self( 38 | $attributes['type'], 39 | ); 40 | } 41 | 42 | /** 43 | * {@inheritDoc} 44 | */ 45 | public function toArray(): array 46 | { 47 | return [ 48 | 'type' => $this->type, 49 | ]; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Resources/Edits.php: -------------------------------------------------------------------------------- 1 | $parameters 22 | * 23 | * @deprecated OpenAI has deprecated this endpoint and will stop working by January 4, 2024. 24 | * https://openai.com/blog/gpt-4-api-general-availability#deprecation-of-the-edits-api 25 | */ 26 | public function create(array $parameters): CreateResponse 27 | { 28 | $payload = Payload::create('edits', $parameters); 29 | 30 | /** @var Response, usage: array{prompt_tokens: int, completion_tokens: int, total_tokens: int}}> $response */ 31 | $response = $this->transporter->requestObject($payload); 32 | 33 | return CreateResponse::from($response->data(), $response->meta()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Responses/Threads/Runs/ThreadRunResponseLastError.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | final class ThreadRunResponseLastError implements ResponseContract 15 | { 16 | /** 17 | * @use ArrayAccessible 18 | */ 19 | use ArrayAccessible; 20 | 21 | use Fakeable; 22 | 23 | private function __construct( 24 | public string $code, 25 | public string $message, 26 | ) {} 27 | 28 | /** 29 | * Acts as static factory, and returns a new Response instance. 30 | * 31 | * @param array{code: string, message: string} $attributes 32 | */ 33 | public static function from(array $attributes): self 34 | { 35 | return new self( 36 | $attributes['code'], 37 | $attributes['message'], 38 | ); 39 | } 40 | 41 | /** 42 | * {@inheritDoc} 43 | */ 44 | public function toArray(): array 45 | { 46 | return [ 47 | 'code' => $this->code, 48 | 'message' => $this->message, 49 | ]; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Responses/VectorStores/VectorStoreResponseExpiresAfter.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | final class VectorStoreResponseExpiresAfter implements ResponseContract 15 | { 16 | /** 17 | * @use ArrayAccessible 18 | */ 19 | use ArrayAccessible; 20 | 21 | use Fakeable; 22 | 23 | private function __construct( 24 | public readonly string $anchor, 25 | public readonly int $days, 26 | ) {} 27 | 28 | /** 29 | * Acts as static factory, and returns a new Response instance. 30 | * 31 | * @param array{anchor: string, days: int} $attributes 32 | */ 33 | public static function from(array $attributes): self 34 | { 35 | return new self( 36 | $attributes['anchor'], 37 | $attributes['days'], 38 | ); 39 | } 40 | 41 | /** 42 | * {@inheritDoc} 43 | */ 44 | public function toArray(): array 45 | { 46 | return [ 47 | 'anchor' => $this->anchor, 48 | 'days' => $this->days, 49 | ]; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Testing/Resources/FilesTestResource.php: -------------------------------------------------------------------------------- 1 | record(__FUNCTION__, func_get_args()); 25 | } 26 | 27 | public function retrieve(string $file): RetrieveResponse 28 | { 29 | return $this->record(__FUNCTION__, func_get_args()); 30 | } 31 | 32 | public function download(string $file): string 33 | { 34 | return $this->record(__FUNCTION__, func_get_args()); 35 | } 36 | 37 | public function upload(array $parameters): CreateResponse 38 | { 39 | return $this->record(__FUNCTION__, func_get_args()); 40 | } 41 | 42 | public function delete(string $file): DeleteResponse 43 | { 44 | return $this->record(__FUNCTION__, func_get_args()); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Responses/Responses/Output/ComputerAction/OutputComputerActionType.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | final class OutputComputerActionType implements ResponseContract 17 | { 18 | /** 19 | * @use ArrayAccessible 20 | */ 21 | use ArrayAccessible; 22 | 23 | use Fakeable; 24 | 25 | /** 26 | * @param 'type' $type 27 | */ 28 | private function __construct( 29 | public readonly string $text, 30 | public readonly string $type, 31 | ) {} 32 | 33 | /** 34 | * @param TypeType $attributes 35 | */ 36 | public static function from(array $attributes): self 37 | { 38 | return new self( 39 | text: $attributes['text'], 40 | type: $attributes['type'], 41 | ); 42 | } 43 | 44 | /** 45 | * {@inheritDoc} 46 | */ 47 | public function toArray(): array 48 | { 49 | return [ 50 | 'text' => $this->text, 51 | 'type' => $this->type, 52 | ]; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Responses/Responses/Output/CodeInterpreter/CodeFileObject.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | final class CodeFileObject implements ResponseContract 17 | { 18 | /** 19 | * @use ArrayAccessible 20 | */ 21 | use ArrayAccessible; 22 | 23 | use Fakeable; 24 | 25 | private function __construct( 26 | public readonly string $fileId, 27 | public readonly string $mimeType, 28 | ) {} 29 | 30 | /** 31 | * @param CodeFileObjectType $attributes 32 | */ 33 | public static function from(array $attributes): self 34 | { 35 | return new self( 36 | fileId: $attributes['file_id'], 37 | mimeType: $attributes['mime_type'], 38 | ); 39 | } 40 | 41 | /** 42 | * {@inheritDoc} 43 | */ 44 | public function toArray(): array 45 | { 46 | return [ 47 | 'file_id' => $this->fileId, 48 | 'mime_type' => $this->mimeType, 49 | ]; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Responses/VectorStores/Search/VectorStoreSearchResponseContent.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | final class VectorStoreSearchResponseContent implements ResponseContract 15 | { 16 | /** 17 | * @use ArrayAccessible 18 | */ 19 | use ArrayAccessible; 20 | 21 | use Fakeable; 22 | 23 | private function __construct( 24 | public readonly string $type, 25 | public readonly string $text, 26 | ) {} 27 | 28 | /** 29 | * Acts as static factory, and returns a new Response instance. 30 | * 31 | * @param array{type: string, text: string} $attributes 32 | */ 33 | public static function from(array $attributes): self 34 | { 35 | return new self( 36 | $attributes['type'], 37 | $attributes['text'], 38 | ); 39 | } 40 | 41 | /** 42 | * {@inheritDoc} 43 | */ 44 | public function toArray(): array 45 | { 46 | return [ 47 | 'type' => $this->type, 48 | 'text' => $this->text, 49 | ]; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Responses/Responses/Tool/FileSearchRankingOption.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | final class FileSearchRankingOption implements ResponseContract 17 | { 18 | /** 19 | * @use ArrayAccessible 20 | */ 21 | use ArrayAccessible; 22 | 23 | use Fakeable; 24 | 25 | private function __construct( 26 | public readonly string $ranker, 27 | public readonly float $scoreThreshold, 28 | ) {} 29 | 30 | /** 31 | * @param RankingOptionType $attributes 32 | */ 33 | public static function from(array $attributes): self 34 | { 35 | return new self( 36 | ranker: $attributes['ranker'], 37 | scoreThreshold: $attributes['score_threshold'], 38 | ); 39 | } 40 | 41 | /** 42 | * {@inheritDoc} 43 | */ 44 | public function toArray(): array 45 | { 46 | return [ 47 | 'ranker' => $this->ranker, 48 | 'score_threshold' => $this->scoreThreshold, 49 | ]; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Responses/Responses/CreateResponseReasoning.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | final class CreateResponseReasoning implements ResponseContract 17 | { 18 | /** 19 | * @use ArrayAccessible 20 | */ 21 | use ArrayAccessible; 22 | 23 | use Fakeable; 24 | 25 | private function __construct( 26 | public readonly ?string $effort, 27 | public readonly ?string $generate_summary, 28 | ) {} 29 | 30 | /** 31 | * @param ReasoningType $attributes 32 | */ 33 | public static function from(array $attributes): self 34 | { 35 | return new self( 36 | effort: $attributes['effort'] ?? null, 37 | generate_summary: $attributes['generate_summary'] ?? null, 38 | ); 39 | } 40 | 41 | /** 42 | * {@inheritDoc} 43 | */ 44 | public function toArray(): array 45 | { 46 | return [ 47 | 'effort' => $this->effort, 48 | 'generate_summary' => $this->generate_summary, 49 | ]; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Responses/Responses/Output/CodeInterpreter/CodeTextOutput.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | final class CodeTextOutput implements ResponseContract 17 | { 18 | /** 19 | * @use ArrayAccessible 20 | */ 21 | use ArrayAccessible; 22 | 23 | use Fakeable; 24 | 25 | /** 26 | * @param 'logs' $type 27 | */ 28 | private function __construct( 29 | public readonly string $logs, 30 | public readonly string $type, 31 | ) {} 32 | 33 | /** 34 | * @param CodeTextOutputType $attributes 35 | */ 36 | public static function from(array $attributes): self 37 | { 38 | return new self( 39 | logs: $attributes['logs'], 40 | type: $attributes['type'], 41 | ); 42 | } 43 | 44 | /** 45 | * {@inheritDoc} 46 | */ 47 | public function toArray(): array 48 | { 49 | return [ 50 | 'type' => $this->type, 51 | 'logs' => $this->logs, 52 | ]; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Responses/Assistants/AssistantResponseToolResourceFileSearch.php: -------------------------------------------------------------------------------- 1 | }> 13 | */ 14 | final class AssistantResponseToolResourceFileSearch implements ResponseContract 15 | { 16 | /** 17 | * @use ArrayAccessible}> 18 | */ 19 | use ArrayAccessible; 20 | 21 | use Fakeable; 22 | 23 | /** 24 | * @param array $vectorStoreIds 25 | */ 26 | private function __construct( 27 | public array $vectorStoreIds, 28 | ) {} 29 | 30 | /** 31 | * Acts as static factory, and returns a new Response instance. 32 | * 33 | * @param array{vector_store_ids: array} $attributes 34 | */ 35 | public static function from(array $attributes): self 36 | { 37 | return new self( 38 | $attributes['vector_store_ids'], 39 | ); 40 | } 41 | 42 | /** 43 | * {@inheritDoc} 44 | */ 45 | public function toArray(): array 46 | { 47 | return [ 48 | 'vector_store_ids' => $this->vectorStoreIds, 49 | ]; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Responses/Responses/Tool/ImageGenerationInputImageMask.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | final class ImageGenerationInputImageMask implements ResponseContract 17 | { 18 | /** 19 | * @use ArrayAccessible 20 | */ 21 | use ArrayAccessible; 22 | 23 | use Fakeable; 24 | 25 | private function __construct( 26 | public readonly ?string $fileId, 27 | public readonly ?string $imageUrl, 28 | ) {} 29 | 30 | /** 31 | * @param InputImageMaskType $attributes 32 | */ 33 | public static function from(array $attributes): self 34 | { 35 | return new self( 36 | fileId: $attributes['file_id'] ?? null, 37 | imageUrl: $attributes['image_url'] ?? null, 38 | ); 39 | } 40 | 41 | /** 42 | * {@inheritDoc} 43 | */ 44 | public function toArray(): array 45 | { 46 | return [ 47 | 'file_id' => $this->fileId, 48 | 'image_url' => $this->imageUrl, 49 | ]; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Responses/VectorStores/Files/VectorStoreFileResponseLastError.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | final class VectorStoreFileResponseLastError implements ResponseContract 15 | { 16 | /** 17 | * @use ArrayAccessible 18 | */ 19 | use ArrayAccessible; 20 | 21 | use Fakeable; 22 | 23 | private function __construct( 24 | public readonly string $code, 25 | public readonly string $message, 26 | ) {} 27 | 28 | /** 29 | * Acts as static factory, and returns a new Response instance. 30 | * 31 | * @param array{code: string, message: string} $attributes 32 | */ 33 | public static function from(array $attributes): self 34 | { 35 | return new self( 36 | $attributes['code'], 37 | $attributes['message'], 38 | ); 39 | } 40 | 41 | /** 42 | * {@inheritDoc} 43 | */ 44 | public function toArray(): array 45 | { 46 | return [ 47 | 'code' => $this->code, 48 | 'message' => $this->message, 49 | ]; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Responses/Responses/Output/OutputReasoningSummary.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | final class OutputReasoningSummary implements ResponseContract 17 | { 18 | /** 19 | * @use ArrayAccessible 20 | */ 21 | use ArrayAccessible; 22 | 23 | use Fakeable; 24 | 25 | /** 26 | * @param 'summary_text' $type 27 | */ 28 | private function __construct( 29 | public readonly string $text, 30 | public readonly string $type, 31 | ) {} 32 | 33 | /** 34 | * @param ReasoningSummaryType $attributes 35 | */ 36 | public static function from(array $attributes): self 37 | { 38 | return new self( 39 | text: $attributes['text'], 40 | type: $attributes['type'], 41 | ); 42 | } 43 | 44 | /** 45 | * {@inheritDoc} 46 | */ 47 | public function toArray(): array 48 | { 49 | return [ 50 | 'text' => $this->text, 51 | 'type' => $this->type, 52 | ]; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Responses/Responses/ToolChoice/FunctionToolChoice.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | final class FunctionToolChoice implements ResponseContract 17 | { 18 | /** 19 | * @use ArrayAccessible 20 | */ 21 | use ArrayAccessible; 22 | 23 | use Fakeable; 24 | 25 | /** 26 | * @param 'function' $type 27 | */ 28 | private function __construct( 29 | public readonly string $name, 30 | public readonly string $type, 31 | ) {} 32 | 33 | /** 34 | * @param FunctionToolChoiceType $attributes 35 | */ 36 | public static function from(array $attributes): self 37 | { 38 | return new self( 39 | name: $attributes['name'], 40 | type: $attributes['type'], 41 | ); 42 | } 43 | 44 | /** 45 | * {@inheritDoc} 46 | */ 47 | public function toArray(): array 48 | { 49 | return [ 50 | 'name' => $this->name, 51 | 'type' => $this->type, 52 | ]; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Responses/Responses/Input/InputMessageContentInputText.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | final class InputMessageContentInputText implements ResponseContract 17 | { 18 | /** 19 | * @use ArrayAccessible 20 | */ 21 | use ArrayAccessible; 22 | 23 | use Fakeable; 24 | 25 | /** 26 | * @param 'input_text' $type 27 | */ 28 | private function __construct( 29 | public readonly string $text, 30 | public readonly string $type 31 | ) {} 32 | 33 | /** 34 | * @param ContentInputTextType $attributes 35 | */ 36 | public static function from(array $attributes): self 37 | { 38 | return new self( 39 | text: $attributes['text'], 40 | type: $attributes['type'], 41 | ); 42 | } 43 | 44 | /** 45 | * {@inheritDoc} 46 | */ 47 | public function toArray(): array 48 | { 49 | return [ 50 | 'text' => $this->text, 51 | 'type' => $this->type, 52 | ]; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Responses/Threads/Runs/ThreadRunResponseTruncationStrategy.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | final class ThreadRunResponseTruncationStrategy implements ResponseContract 15 | { 16 | /** 17 | * @use ArrayAccessible 18 | */ 19 | use ArrayAccessible; 20 | 21 | use Fakeable; 22 | 23 | private function __construct( 24 | public string $type, 25 | public ?int $lastMessages, 26 | ) {} 27 | 28 | /** 29 | * Acts as static factory, and returns a new Response instance. 30 | * 31 | * @param array{type: string, last_messages: ?int} $attributes 32 | */ 33 | public static function from(array $attributes): self 34 | { 35 | return new self( 36 | $attributes['type'], 37 | $attributes['last_messages'], 38 | ); 39 | } 40 | 41 | /** 42 | * {@inheritDoc} 43 | */ 44 | public function toArray(): array 45 | { 46 | return [ 47 | 'type' => $this->type, 48 | 'last_messages' => $this->lastMessages, 49 | ]; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Responses/Audio/TranscriptionResponseWord.php: -------------------------------------------------------------------------------- 1 | 12 | */ 13 | final class TranscriptionResponseWord implements ResponseContract 14 | { 15 | /** 16 | * @use ArrayAccessible 17 | */ 18 | use ArrayAccessible; 19 | 20 | private function __construct( 21 | public readonly string $word, 22 | public readonly float $start, 23 | public readonly float $end, 24 | ) {} 25 | 26 | /** 27 | * Acts as static factory, and returns a new Response instance. 28 | * 29 | * @param array{word: string, start: float, end: float} $attributes 30 | */ 31 | public static function from(array $attributes): self 32 | { 33 | return new self( 34 | $attributes['word'], 35 | $attributes['start'], 36 | $attributes['end'], 37 | ); 38 | } 39 | 40 | /** 41 | * {@inheritDoc} 42 | */ 43 | public function toArray(): array 44 | { 45 | return [ 46 | 'word' => $this->word, 47 | 'start' => $this->start, 48 | 'end' => $this->end, 49 | ]; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Responses/Chat/CreateStreamedResponseToolCall.php: -------------------------------------------------------------------------------- 1 | $this->index, 36 | 'id' => $this->id, 37 | 'type' => $this->type, 38 | 'function' => $this->function->toArray(), 39 | ], fn (mixed $value): bool => ! is_null($value)); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Responses/Responses/Output/OutputMessageContentRefusal.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | final class OutputMessageContentRefusal implements ResponseContract 17 | { 18 | /** 19 | * @use ArrayAccessible 20 | */ 21 | use ArrayAccessible; 22 | 23 | use Fakeable; 24 | 25 | /** 26 | * @param 'refusal' $type 27 | */ 28 | private function __construct( 29 | public readonly string $refusal, 30 | public readonly string $type, 31 | ) {} 32 | 33 | /** 34 | * @param ContentRefusalType $attributes 35 | */ 36 | public static function from(array $attributes): self 37 | { 38 | return new self( 39 | refusal: $attributes['refusal'], 40 | type: $attributes['type'], 41 | ); 42 | } 43 | 44 | /** 45 | * {@inheritDoc} 46 | */ 47 | public function toArray(): array 48 | { 49 | return [ 50 | 'refusal' => $this->refusal, 51 | 'type' => $this->type, 52 | ]; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Responses/Batches/BatchResponseRequestCounts.php: -------------------------------------------------------------------------------- 1 | 12 | */ 13 | final class BatchResponseRequestCounts implements ResponseContract 14 | { 15 | /** 16 | * @use ArrayAccessible 17 | */ 18 | use ArrayAccessible; 19 | 20 | private function __construct( 21 | public int $total, 22 | public int $completed, 23 | public int $failed, 24 | ) {} 25 | 26 | /** 27 | * Acts as static factory, and returns a new Response instance. 28 | * 29 | * @param array{total: int, completed: int, failed: int} $attributes 30 | */ 31 | public static function from(array $attributes): self 32 | { 33 | 34 | return new self( 35 | $attributes['total'], 36 | $attributes['completed'], 37 | $attributes['failed'], 38 | ); 39 | } 40 | 41 | /** 42 | * {@inheritDoc} 43 | */ 44 | public function toArray(): array 45 | { 46 | return [ 47 | 'total' => $this->total, 48 | 'completed' => $this->completed, 49 | 'failed' => $this->failed, 50 | ]; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Responses/Threads/Runs/ThreadRunResponseRequiredActionFunctionToolCallFunction.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | final class ThreadRunResponseRequiredActionFunctionToolCallFunction implements ResponseContract 15 | { 16 | /** 17 | * @use ArrayAccessible 18 | */ 19 | use ArrayAccessible; 20 | 21 | use Fakeable; 22 | 23 | private function __construct( 24 | public string $name, 25 | public string $arguments, 26 | ) {} 27 | 28 | /** 29 | * Acts as static factory, and returns a new Response instance. 30 | * 31 | * @param array{name: string, arguments: string} $attributes 32 | */ 33 | public static function from(array $attributes): self 34 | { 35 | return new self( 36 | $attributes['name'], 37 | $attributes['arguments'], 38 | ); 39 | } 40 | 41 | /** 42 | * {@inheritDoc} 43 | */ 44 | public function toArray(): array 45 | { 46 | return [ 47 | 'name' => $this->name, 48 | 'arguments' => $this->arguments, 49 | ]; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Testing/Resources/AssistantsTestResource.php: -------------------------------------------------------------------------------- 1 | record(__FUNCTION__, func_get_args()); 24 | } 25 | 26 | public function retrieve(string $id): AssistantResponse 27 | { 28 | return $this->record(__FUNCTION__, func_get_args()); 29 | } 30 | 31 | public function modify(string $id, array $parameters): AssistantResponse 32 | { 33 | return $this->record(__FUNCTION__, func_get_args()); 34 | } 35 | 36 | public function delete(string $id): AssistantDeleteResponse 37 | { 38 | return $this->record(__FUNCTION__, func_get_args()); 39 | } 40 | 41 | public function list(array $parameters = []): AssistantListResponse 42 | { 43 | return $this->record(__FUNCTION__, func_get_args()); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Testing/Resources/AudioTestResource.php: -------------------------------------------------------------------------------- 1 | record(__FUNCTION__, func_get_args()); 25 | } 26 | 27 | public function speechStreamed(array $parameters): SpeechStreamResponse 28 | { 29 | return $this->record(__FUNCTION__, func_get_args()); 30 | } 31 | 32 | public function transcribe(array $parameters): TranscriptionResponse 33 | { 34 | return $this->record(__FUNCTION__, func_get_args()); 35 | } 36 | 37 | public function transcribeStreamed(array $parameters): StreamResponse 38 | { 39 | return $this->record(__FUNCTION__, func_get_args()); 40 | } 41 | 42 | public function translate(array $parameters): TranslationResponse 43 | { 44 | return $this->record(__FUNCTION__, func_get_args()); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Testing/Responses/Fixtures/FineTunes/RetrieveStreamedResponseEventFixture.txt: -------------------------------------------------------------------------------- 1 | data: {"object": "fine-tune-event", "level": "info", "message": "Created fine-tune: ft-y3OpNlc8B5qBVGCCVsLZsDST", "created_at": 1668021917} 2 | data: {"object": "fine-tune-event", "level": "info", "message": "Fine-tune costs $0.00", "created_at": 1668021926} 3 | data: {"object": "fine-tune-event", "level": "info", "message": "Fine-tune enqueued. Queue number: 0", "created_at": 1668021927} 4 | data: {"object": "fine-tune-event", "level": "info", "message": "Fine-tune started", "created_at": 1668021929} 5 | data: {"object": "fine-tune-event", "level": "info", "message": "Completed epoch 1/4", "created_at": 1668021976} 6 | data: {"object": "fine-tune-event", "level": "info", "message": "Completed epoch 2/4", "created_at": 1668021977} 7 | data: {"object": "fine-tune-event", "level": "info", "message": "Completed epoch 3/4", "created_at": 1668021978} 8 | data: {"object": "fine-tune-event", "level": "info", "message": "Completed epoch 4/4", "created_at": 1668021978} 9 | data: {"object": "fine-tune-event", "level": "info", "message": "Uploaded model: curie:ft-gehri-dev-2022-11-09-19-26-40", "created_at": 1668022001} 10 | data: {"object": "fine-tune-event", "level": "info", "message": "Uploaded result file: file-ajLKUCMsFPrT633zqwr0eI4l", "created_at": 1668022002} 11 | data: {"object": "fine-tune-event", "level": "info", "message": "Fine-tune succeeded", "created_at": 1668022002} 12 | data: [DONE] 13 | -------------------------------------------------------------------------------- /src/Responses/Threads/Messages/ThreadMessageResponseContentImageUrl.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | final class ThreadMessageResponseContentImageUrl implements ResponseContract 15 | { 16 | /** 17 | * @use ArrayAccessible 18 | */ 19 | use ArrayAccessible; 20 | 21 | use Fakeable; 22 | 23 | private function __construct( 24 | public string $url, 25 | public ?string $detail, 26 | ) {} 27 | 28 | /** 29 | * Acts as static factory, and returns a new Response instance. 30 | * 31 | * @param array{url: string, detail?: string} $attributes 32 | */ 33 | public static function from(array $attributes): self 34 | { 35 | return new self( 36 | $attributes['url'], 37 | $attributes['detail'] ?? null, 38 | ); 39 | } 40 | 41 | /** 42 | * {@inheritDoc} 43 | */ 44 | public function toArray(): array 45 | { 46 | return array_filter([ 47 | 'url' => $this->url, 48 | 'detail' => $this->detail, 49 | ], fn (?string $value): bool => $value !== null); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Responses/Chat/CreateResponseChoiceLogprobs.php: -------------------------------------------------------------------------------- 1 | $content 11 | */ 12 | private function __construct( 13 | public readonly ?array $content, 14 | ) {} 15 | 16 | /** 17 | * @param array{content: ?array}>} $attributes 18 | */ 19 | public static function from(array $attributes): self 20 | { 21 | $content = null; 22 | if (isset($attributes['content'])) { 23 | $content = array_map(fn (array $result): CreateResponseChoiceLogprobsContent => CreateResponseChoiceLogprobsContent::from( 24 | $result 25 | ), $attributes['content']); 26 | } 27 | 28 | return new self( 29 | $content, 30 | ); 31 | } 32 | 33 | /** 34 | * @return array{content: ?array}>} 35 | */ 36 | public function toArray(): array 37 | { 38 | return [ 39 | 'content' => $this->content ? array_map( 40 | static fn (CreateResponseChoiceLogprobsContent $result): array => $result->toArray(), 41 | $this->content, 42 | ) : null, 43 | ]; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Responses/Threads/Runs/Steps/ThreadRunStepResponseCodeInterpreterOutputLogs.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | final class ThreadRunStepResponseCodeInterpreterOutputLogs implements ResponseContract 15 | { 16 | /** 17 | * @use ArrayAccessible 18 | */ 19 | use ArrayAccessible; 20 | 21 | use Fakeable; 22 | 23 | /** 24 | * @param 'logs' $type 25 | */ 26 | private function __construct( 27 | public string $type, 28 | public string $logs, 29 | ) {} 30 | 31 | /** 32 | * Acts as static factory, and returns a new Response instance. 33 | * 34 | * @param array{type: 'logs', logs: string} $attributes 35 | */ 36 | public static function from(array $attributes): self 37 | { 38 | return new self( 39 | $attributes['type'], 40 | $attributes['logs'], 41 | ); 42 | } 43 | 44 | /** 45 | * {@inheritDoc} 46 | */ 47 | public function toArray(): array 48 | { 49 | return [ 50 | 'type' => $this->type, 51 | 'logs' => $this->logs, 52 | ]; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Responses/FineTuning/RetrieveJobResponseError.php: -------------------------------------------------------------------------------- 1 | 12 | */ 13 | final class RetrieveJobResponseError implements ResponseContract 14 | { 15 | /** 16 | * @use ArrayAccessible 17 | */ 18 | use ArrayAccessible; 19 | 20 | private function __construct( 21 | public readonly string $code, 22 | public readonly ?string $param, 23 | public readonly string $message, 24 | ) {} 25 | 26 | /** 27 | * Acts as static factory, and returns a new Response instance. 28 | * 29 | * @param array{code: string, param: ?string, message: string} $attributes 30 | */ 31 | public static function from(array $attributes): ?self 32 | { 33 | return new self( 34 | $attributes['code'], 35 | $attributes['param'], 36 | $attributes['message'], 37 | ); 38 | } 39 | 40 | /** 41 | * {@inheritDoc} 42 | */ 43 | public function toArray(): array 44 | { 45 | return [ 46 | 'code' => $this->code, 47 | 'param' => $this->param, 48 | 'message' => $this->message, 49 | ]; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Testing/Resources/FineTuningTestResource.php: -------------------------------------------------------------------------------- 1 | record(__FUNCTION__, func_get_args()); 24 | } 25 | 26 | public function listJobs(array $parameters = []): ListJobsResponse 27 | { 28 | return $this->record(__FUNCTION__, func_get_args()); 29 | } 30 | 31 | public function retrieveJob(string $jobId): RetrieveJobResponse 32 | { 33 | return $this->record(__FUNCTION__, func_get_args()); 34 | } 35 | 36 | public function cancelJob(string $jobId): RetrieveJobResponse 37 | { 38 | return $this->record(__FUNCTION__, func_get_args()); 39 | } 40 | 41 | public function listJobEvents(string $jobId, array $parameters = []): ListJobEventsResponse 42 | { 43 | return $this->record(__FUNCTION__, func_get_args()); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Testing/Resources/VectorStoresFilesTestResource.php: -------------------------------------------------------------------------------- 1 | record(__FUNCTION__, func_get_args()); 24 | } 25 | 26 | public function delete(string $vectorStoreId, string $fileId): VectorStoreFileDeleteResponse 27 | { 28 | return $this->record(__FUNCTION__, func_get_args()); 29 | } 30 | 31 | public function create(string $vectorStoreId, array $parameters): VectorStoreFileResponse 32 | { 33 | return $this->record(__FUNCTION__, func_get_args()); 34 | } 35 | 36 | public function list(string $vectorStoreId, array $parameters = []): VectorStoreFileListResponse 37 | { 38 | return $this->record(__FUNCTION__, func_get_args()); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Responses/Responses/Output/ComputerAction/OutputComputerActionKeyPress.php: -------------------------------------------------------------------------------- 1 | , type: 'keypress'} 13 | * 14 | * @implements ResponseContract 15 | */ 16 | final class OutputComputerActionKeyPress implements ResponseContract 17 | { 18 | /** 19 | * @use ArrayAccessible 20 | */ 21 | use ArrayAccessible; 22 | 23 | use Fakeable; 24 | 25 | /** 26 | * @param array $keys 27 | * @param 'keypress' $type 28 | */ 29 | private function __construct( 30 | public readonly array $keys, 31 | public readonly string $type, 32 | ) {} 33 | 34 | /** 35 | * @param KeyPressType $attributes 36 | */ 37 | public static function from(array $attributes): self 38 | { 39 | return new self( 40 | keys: $attributes['keys'], 41 | type: $attributes['type'], 42 | ); 43 | } 44 | 45 | /** 46 | * {@inheritDoc} 47 | */ 48 | public function toArray(): array 49 | { 50 | return [ 51 | 'keys' => $this->keys, 52 | 'type' => $this->type, 53 | ]; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Responses/Responses/Output/ComputerAction/OutputComputerActionMove.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | final class OutputComputerActionMove implements ResponseContract 17 | { 18 | /** 19 | * @use ArrayAccessible 20 | */ 21 | use ArrayAccessible; 22 | 23 | use Fakeable; 24 | 25 | /** 26 | * @param 'move' $type 27 | */ 28 | private function __construct( 29 | public readonly string $type, 30 | public readonly int $x, 31 | public readonly int $y, 32 | ) {} 33 | 34 | /** 35 | * @param MoveType $attributes 36 | */ 37 | public static function from(array $attributes): self 38 | { 39 | return new self( 40 | type: $attributes['type'], 41 | x: $attributes['x'], 42 | y: $attributes['y'], 43 | ); 44 | } 45 | 46 | /** 47 | * {@inheritDoc} 48 | */ 49 | public function toArray(): array 50 | { 51 | return [ 52 | 'type' => $this->type, 53 | 'x' => $this->x, 54 | 'y' => $this->y, 55 | ]; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Responses/Threads/Messages/ThreadMessageResponseContentImageFile.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | final class ThreadMessageResponseContentImageFile implements ResponseContract 15 | { 16 | /** 17 | * @use ArrayAccessible 18 | */ 19 | use ArrayAccessible; 20 | 21 | use Fakeable; 22 | 23 | private function __construct( 24 | public string $fileId, 25 | public ?string $detail, 26 | ) {} 27 | 28 | /** 29 | * Acts as static factory, and returns a new Response instance. 30 | * 31 | * @param array{file_id: string, detail?: string} $attributes 32 | */ 33 | public static function from(array $attributes): self 34 | { 35 | return new self( 36 | $attributes['file_id'], 37 | $attributes['detail'] ?? null, 38 | ); 39 | } 40 | 41 | /** 42 | * {@inheritDoc} 43 | */ 44 | public function toArray(): array 45 | { 46 | return array_filter([ 47 | 'file_id' => $this->fileId, 48 | 'detail' => $this->detail, 49 | ], fn (?string $value): bool => $value !== null); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Testing/Resources/VectorStoresFileBatchesTestResource.php: -------------------------------------------------------------------------------- 1 | record(__FUNCTION__, func_get_args()); 23 | } 24 | 25 | public function cancel(string $vectorStoreId, string $fileBatchId): VectorStoreFileBatchResponse 26 | { 27 | return $this->record(__FUNCTION__, func_get_args()); 28 | } 29 | 30 | public function create(string $vectorStoreId, array $parameters): VectorStoreFileBatchResponse 31 | { 32 | return $this->record(__FUNCTION__, func_get_args()); 33 | } 34 | 35 | public function listFiles(string $vectorStoreId, string $fileBatchId, array $parameters = []): VectorStoreFileListResponse 36 | { 37 | return $this->record(__FUNCTION__, func_get_args()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/ValueObjects/Transporter/Response.php: -------------------------------------------------------------------------------- 1 | > $headers 33 | * @return Response 34 | */ 35 | public static function from(array|string $data, array $headers): self 36 | { 37 | // @phpstan-ignore-next-line 38 | $meta = MetaInformation::from($headers); 39 | 40 | return new self($data, $meta); 41 | } 42 | 43 | /** 44 | * Returns the response data. 45 | * 46 | * @return TData 47 | */ 48 | public function data(): array|string 49 | { 50 | return $this->data; 51 | } 52 | 53 | /** 54 | * Returns the meta information. 55 | */ 56 | public function meta(): MetaInformation 57 | { 58 | return $this->meta; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/Responses/Threads/Messages/ThreadMessageResponseContentTextAnnotationFileCitation.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | final class ThreadMessageResponseContentTextAnnotationFileCitation implements ResponseContract 15 | { 16 | /** 17 | * @use ArrayAccessible 18 | */ 19 | use ArrayAccessible; 20 | 21 | use Fakeable; 22 | 23 | private function __construct( 24 | public string $fileId, 25 | public ?string $quote, 26 | ) {} 27 | 28 | /** 29 | * Acts as static factory, and returns a new Response instance. 30 | * 31 | * @param array{file_id: string, quote?: string} $attributes 32 | */ 33 | public static function from(array $attributes): self 34 | { 35 | return new self( 36 | $attributes['file_id'], 37 | $attributes['quote'] ?? null, 38 | ); 39 | } 40 | 41 | /** 42 | * {@inheritDoc} 43 | */ 44 | public function toArray(): array 45 | { 46 | return array_filter([ 47 | 'file_id' => $this->fileId, 48 | 'quote' => $this->quote, 49 | ], fn (?string $value): bool => $value !== null); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Responses/Images/ImageResponseUsage.php: -------------------------------------------------------------------------------- 1 | $this->totalTokens, 36 | 'input_tokens' => $this->inputTokens, 37 | 'output_tokens' => $this->outputTokens, 38 | 'input_tokens_details' => $this->inputTokensDetails->toArray(), 39 | ]; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Responses/Responses/Input/AcknowledgedSafetyCheck.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | final class AcknowledgedSafetyCheck implements ResponseContract 17 | { 18 | /** 19 | * @use ArrayAccessible 20 | */ 21 | use ArrayAccessible; 22 | 23 | use Fakeable; 24 | 25 | private function __construct( 26 | public readonly string $code, 27 | public readonly string $id, 28 | public readonly string $message, 29 | ) {} 30 | 31 | /** 32 | * @param AcknowledgedSafetyCheckType $attributes 33 | */ 34 | public static function from(array $attributes): self 35 | { 36 | return new self( 37 | code: $attributes['code'], 38 | id: $attributes['id'], 39 | message: $attributes['message'], 40 | ); 41 | } 42 | 43 | /** 44 | * {@inheritDoc} 45 | */ 46 | public function toArray(): array 47 | { 48 | return [ 49 | 'code' => $this->code, 50 | 'id' => $this->id, 51 | 'message' => $this->message, 52 | ]; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Testing/Responses/Fixtures/FineTunes/RetrieveResponseFixture.php: -------------------------------------------------------------------------------- 1 | 'ft-AF1WoRqd3aJAHsqc9NY7iL8F', 11 | 'object' => 'fine-tune', 12 | 'model' => 'curie', 13 | 'created_at' => 1_614_807_352, 14 | 'events' => [ 15 | [ 16 | 'object' => 'fine-tune-event', 17 | 'created_at' => 1_614_807_352, 18 | 'level' => 'info', 19 | 'message' => 'Job enqueued. Waiting for jobs ahead to complete. Queue number => 0.', 20 | ], 21 | ], 22 | 'fine_tuned_model' => 'curie => ft-acmeco-2021-03-03-21-44-20', 23 | 'hyperparams' => [ 24 | 'batch_size' => 4, 25 | 'learning_rate_multiplier' => 0.1, 26 | 'n_epochs' => 4, 27 | 'prompt_loss_weight' => 0.1, 28 | ], 29 | 'organization_id' => 'org-jwe45798ASN82s', 30 | 'result_files' => [ 31 | CreateResponseFixture::ATTRIBUTES, 32 | ], 33 | 'status' => 'succeeded', 34 | 'validation_files' => [ 35 | CreateResponseFixture::ATTRIBUTES, 36 | ], 37 | 'training_files' => [ 38 | CreateResponseFixture::ATTRIBUTES, 39 | ], 40 | 'updated_at' => 1_614_807_865, 41 | ]; 42 | } 43 | -------------------------------------------------------------------------------- /src/Responses/Responses/Streaming/McpCall.php: -------------------------------------------------------------------------------- 1 | 18 | */ 19 | final class McpCall implements ResponseContract, ResponseHasMetaInformationContract 20 | { 21 | /** 22 | * @use ArrayAccessible 23 | */ 24 | use ArrayAccessible; 25 | 26 | use Fakeable; 27 | use HasMetaInformation; 28 | 29 | private function __construct( 30 | public readonly int $sequenceNumber, 31 | private readonly MetaInformation $meta, 32 | ) {} 33 | 34 | /** 35 | * @param McpCallType $attributes 36 | */ 37 | public static function from(array $attributes, MetaInformation $meta): self 38 | { 39 | return new self( 40 | sequenceNumber: $attributes['sequence_number'], 41 | meta: $meta, 42 | ); 43 | } 44 | 45 | /** 46 | * {@inheritDoc} 47 | */ 48 | public function toArray(): array 49 | { 50 | return [ 51 | 'sequence_number' => $this->sequenceNumber, 52 | ]; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Responses/Responses/Output/ComputerAction/OutputComputerActionDoubleClick.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | final class OutputComputerActionDoubleClick implements ResponseContract 17 | { 18 | /** 19 | * @use ArrayAccessible 20 | */ 21 | use ArrayAccessible; 22 | 23 | use Fakeable; 24 | 25 | /** 26 | * @param 'double_click' $type 27 | */ 28 | private function __construct( 29 | public readonly string $type, 30 | public readonly float $x, 31 | public readonly float $y, 32 | ) {} 33 | 34 | /** 35 | * @param DoubleClickType $attributes 36 | */ 37 | public static function from(array $attributes): self 38 | { 39 | return new self( 40 | type: $attributes['type'], 41 | x: $attributes['x'], 42 | y: $attributes['y'], 43 | ); 44 | } 45 | 46 | /** 47 | * {@inheritDoc} 48 | */ 49 | public function toArray(): array 50 | { 51 | return [ 52 | 'type' => $this->type, 53 | 'x' => $this->x, 54 | 'y' => $this->y, 55 | ]; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Responses/Responses/Output/ComputerAction/OutputComputerPendingSafetyCheck.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | final class OutputComputerPendingSafetyCheck implements ResponseContract 17 | { 18 | /** 19 | * @use ArrayAccessible 20 | */ 21 | use ArrayAccessible; 22 | 23 | use Fakeable; 24 | 25 | private function __construct( 26 | public readonly string $code, 27 | public readonly string $id, 28 | public readonly string $message, 29 | ) {} 30 | 31 | /** 32 | * @param PendingSafetyCheckType $attributes 33 | */ 34 | public static function from(array $attributes): self 35 | { 36 | return new self( 37 | code: $attributes['code'], 38 | id: $attributes['id'], 39 | message: $attributes['message'], 40 | ); 41 | } 42 | 43 | /** 44 | * {@inheritDoc} 45 | */ 46 | public function toArray(): array 47 | { 48 | return [ 49 | 'code' => $this->code, 50 | 'id' => $this->id, 51 | 'message' => $this->message, 52 | ]; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Responses/Responses/Tool/CodeInterpreterContainerAuto.php: -------------------------------------------------------------------------------- 1 | |null, type: 'auto'} 13 | * 14 | * @implements ResponseContract 15 | */ 16 | final class CodeInterpreterContainerAuto implements ResponseContract 17 | { 18 | /** 19 | * @use ArrayAccessible 20 | */ 21 | use ArrayAccessible; 22 | 23 | use Fakeable; 24 | 25 | /** 26 | * @param array|null $fileIds 27 | * @param 'auto' $type 28 | */ 29 | private function __construct( 30 | public readonly ?array $fileIds, 31 | public readonly string $type, 32 | ) {} 33 | 34 | /** 35 | * @param CodeInterpreterContainerAutoType $attributes 36 | */ 37 | public static function from(array $attributes): self 38 | { 39 | return new self( 40 | fileIds: $attributes['file_ids'] ?? null, 41 | type: $attributes['type'], 42 | ); 43 | } 44 | 45 | /** 46 | * {@inheritDoc} 47 | */ 48 | public function toArray(): array 49 | { 50 | return [ 51 | 'file_ids' => $this->fileIds, 52 | 'type' => $this->type, 53 | ]; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Responses/Responses/Streaming/McpListTools.php: -------------------------------------------------------------------------------- 1 | 18 | */ 19 | final class McpListTools implements ResponseContract, ResponseHasMetaInformationContract 20 | { 21 | /** 22 | * @use ArrayAccessible 23 | */ 24 | use ArrayAccessible; 25 | 26 | use Fakeable; 27 | use HasMetaInformation; 28 | 29 | private function __construct( 30 | public readonly int $sequenceNumber, 31 | private readonly MetaInformation $meta, 32 | ) {} 33 | 34 | /** 35 | * @param McpListToolsType $attributes 36 | */ 37 | public static function from(array $attributes, MetaInformation $meta): self 38 | { 39 | return new self( 40 | sequenceNumber: $attributes['sequence_number'], 41 | meta: $meta, 42 | ); 43 | } 44 | 45 | /** 46 | * {@inheritDoc} 47 | */ 48 | public function toArray(): array 49 | { 50 | return [ 51 | 'sequence_number' => $this->sequenceNumber, 52 | ]; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Responses/Responses/Output/OutputMessageContentOutputTextAnnotationsFilePath.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | final class OutputMessageContentOutputTextAnnotationsFilePath implements ResponseContract 17 | { 18 | /** 19 | * @use ArrayAccessible 20 | */ 21 | use ArrayAccessible; 22 | 23 | use Fakeable; 24 | 25 | /** 26 | * @param 'file_path' $type 27 | */ 28 | private function __construct( 29 | public readonly string $fileId, 30 | public readonly int $index, 31 | public readonly string $type, 32 | ) {} 33 | 34 | /** 35 | * @param FilePathType $attributes 36 | */ 37 | public static function from(array $attributes): self 38 | { 39 | return new self( 40 | fileId: $attributes['file_id'], 41 | index: $attributes['index'], 42 | type: $attributes['type'], 43 | ); 44 | } 45 | 46 | /** 47 | * {@inheritDoc} 48 | */ 49 | public function toArray(): array 50 | { 51 | return [ 52 | 'file_id' => $this->fileId, 53 | 'index' => $this->index, 54 | 'type' => $this->type, 55 | ]; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Testing/Resources/FineTunesTestResource.php: -------------------------------------------------------------------------------- 1 | record(__FUNCTION__, func_get_args()); 25 | } 26 | 27 | public function list(): ListResponse 28 | { 29 | return $this->record(__FUNCTION__); 30 | } 31 | 32 | public function retrieve(string $fineTuneId): RetrieveResponse 33 | { 34 | return $this->record(__FUNCTION__, func_get_args()); 35 | } 36 | 37 | public function cancel(string $fineTuneId): RetrieveResponse 38 | { 39 | return $this->record(__FUNCTION__, func_get_args()); 40 | } 41 | 42 | public function listEvents(string $fineTuneId): ListEventsResponse 43 | { 44 | return $this->record(__FUNCTION__, func_get_args()); 45 | } 46 | 47 | public function listEventsStreamed(string $fineTuneId): StreamResponse 48 | { 49 | return $this->record(__FUNCTION__, func_get_args()); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Exceptions/ErrorException.php: -------------------------------------------------------------------------------- 1 | , type: ?string, code: string|int|null} $contents 15 | */ 16 | public function __construct(private readonly array $contents, private readonly int $statusCode) 17 | { 18 | $message = ($contents['message'] ?: (string) $this->contents['code']) ?: 'Unknown error'; 19 | 20 | if (is_array($message)) { 21 | $message = implode(PHP_EOL, $message); 22 | } 23 | 24 | parent::__construct($message); 25 | } 26 | 27 | /** 28 | * Returns the HTTP status code. 29 | * 30 | * **Note: For streamed requests it might be 200 even in case of an error.** 31 | */ 32 | public function getStatusCode(): int 33 | { 34 | return $this->statusCode; 35 | } 36 | 37 | /** 38 | * Returns the error message. 39 | */ 40 | public function getErrorMessage(): string 41 | { 42 | return $this->getMessage(); 43 | } 44 | 45 | /** 46 | * Returns the error type. 47 | */ 48 | public function getErrorType(): ?string 49 | { 50 | return $this->contents['type']; 51 | } 52 | 53 | /** 54 | * Returns the error code. 55 | */ 56 | public function getErrorCode(): string|int|null 57 | { 58 | return $this->contents['code']; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/Responses/Batches/BatchResponseErrorsData.php: -------------------------------------------------------------------------------- 1 | 12 | */ 13 | final class BatchResponseErrorsData implements ResponseContract 14 | { 15 | /** 16 | * @use ArrayAccessible 17 | */ 18 | use ArrayAccessible; 19 | 20 | private function __construct( 21 | public string $code, 22 | public string $message, 23 | public ?string $param, 24 | public ?int $line, 25 | ) {} 26 | 27 | /** 28 | * Acts as static factory, and returns a new Response instance. 29 | * 30 | * @param array{code: string, message: string, param: ?string, line: ?int} $attributes 31 | */ 32 | public static function from(array $attributes): self 33 | { 34 | 35 | return new self( 36 | $attributes['code'], 37 | $attributes['message'], 38 | $attributes['param'], 39 | $attributes['line'], 40 | ); 41 | } 42 | 43 | /** 44 | * {@inheritDoc} 45 | */ 46 | public function toArray(): array 47 | { 48 | return [ 49 | 'code' => $this->code, 50 | 'message' => $this->message, 51 | 'param' => $this->param, 52 | 'line' => $this->line, 53 | ]; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Responses/Responses/Output/OutputWebSearchToolCall.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | final class OutputWebSearchToolCall implements ResponseContract 17 | { 18 | /** 19 | * @use ArrayAccessible 20 | */ 21 | use ArrayAccessible; 22 | 23 | use Fakeable; 24 | 25 | /** 26 | * @param 'web_search_call' $type 27 | */ 28 | private function __construct( 29 | public readonly string $id, 30 | public readonly string $status, 31 | public readonly string $type, 32 | ) {} 33 | 34 | /** 35 | * @param OutputWebSearchToolCallType $attributes 36 | */ 37 | public static function from(array $attributes): self 38 | { 39 | return new self( 40 | id: $attributes['id'], 41 | status: $attributes['status'], 42 | type: $attributes['type'], 43 | ); 44 | } 45 | 46 | /** 47 | * {@inheritDoc} 48 | */ 49 | public function toArray(): array 50 | { 51 | return [ 52 | 'id' => $this->id, 53 | 'status' => $this->status, 54 | 'type' => $this->type, 55 | ]; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Responses/Threads/Runs/Steps/ThreadRunStepResponseFunction.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | final class ThreadRunStepResponseFunction implements ResponseContract 15 | { 16 | /** 17 | * @use ArrayAccessible 18 | */ 19 | use ArrayAccessible; 20 | 21 | use Fakeable; 22 | 23 | private function __construct( 24 | public ?string $name, 25 | public string $arguments, 26 | public ?string $output, 27 | ) {} 28 | 29 | /** 30 | * Acts as static factory, and returns a new Response instance. 31 | * 32 | * @param array{name?: string, arguments: string, output?: ?string} $attributes 33 | */ 34 | public static function from(array $attributes): self 35 | { 36 | return new self( 37 | $attributes['name'] ?? null, 38 | $attributes['arguments'], 39 | $attributes['output'] ?? null, 40 | ); 41 | } 42 | 43 | /** 44 | * {@inheritDoc} 45 | */ 46 | public function toArray(): array 47 | { 48 | return [ 49 | 'name' => $this->name, 50 | 'arguments' => $this->arguments, 51 | 'output' => $this->output, 52 | ]; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Responses/FineTuning/ListJobEventsResponseEventData.php: -------------------------------------------------------------------------------- 1 | 12 | */ 13 | final class ListJobEventsResponseEventData implements ResponseContract 14 | { 15 | /** 16 | * @use ArrayAccessible 17 | */ 18 | use ArrayAccessible; 19 | 20 | private function __construct( 21 | public readonly int $step, 22 | public readonly float $trainLoss, 23 | public readonly float $trainMeanTokenAccuracy, 24 | ) {} 25 | 26 | /** 27 | * Acts as static factory, and returns a new Response instance. 28 | * 29 | * @param array{step: int, train_loss: float, train_mean_token_accuracy: float} $attributes 30 | */ 31 | public static function from(array $attributes): self 32 | { 33 | return new self( 34 | $attributes['step'], 35 | $attributes['train_loss'], 36 | $attributes['train_mean_token_accuracy'], 37 | ); 38 | } 39 | 40 | /** 41 | * {@inheritDoc} 42 | */ 43 | public function toArray(): array 44 | { 45 | return [ 46 | 'step' => $this->step, 47 | 'train_loss' => $this->trainLoss, 48 | 'train_mean_token_accuracy' => $this->trainMeanTokenAccuracy, 49 | ]; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Responses/Responses/Tool/FileSearchComparisonFilter.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | final class FileSearchComparisonFilter implements ResponseContract 17 | { 18 | /** 19 | * @use ArrayAccessible 20 | */ 21 | use ArrayAccessible; 22 | 23 | use Fakeable; 24 | 25 | /** 26 | * @param 'eq'|'ne'|'gt'|'gte'|'lt'|'lte' $type 27 | */ 28 | private function __construct( 29 | public readonly string $key, 30 | public readonly string $type, 31 | public readonly string|int|bool $value, 32 | ) {} 33 | 34 | /** 35 | * @param ComparisonFilterType $attributes 36 | */ 37 | public static function from(array $attributes): self 38 | { 39 | return new self( 40 | key: $attributes['key'], 41 | type: $attributes['type'], 42 | value: $attributes['value'], 43 | ); 44 | } 45 | 46 | /** 47 | * {@inheritDoc} 48 | */ 49 | public function toArray(): array 50 | { 51 | return [ 52 | 'key' => $this->key, 53 | 'type' => $this->type, 54 | 'value' => $this->value, 55 | ]; 56 | } 57 | } 58 | --------------------------------------------------------------------------------