├── .editorconfig ├── .gitignore ├── .gitmodules ├── .jane-openapi ├── Dockerfile ├── LICENSE ├── Makefile ├── README.md ├── bin └── jane ├── build ├── GenerateCommand.php ├── JaneOpenApi.php └── ModelWithConstructorGenerator.php ├── composer.json ├── docker-compose.yaml ├── ecs.php ├── example-chat.php ├── example.php ├── generated ├── Client.php ├── Endpoint │ ├── CancelFineTune.php │ ├── CreateChatCompletion.php │ ├── CreateCompletion.php │ ├── CreateEdit.php │ ├── CreateEmbedding.php │ ├── CreateFile.php │ ├── CreateFineTune.php │ ├── CreateImage.php │ ├── CreateImageEdit.php │ ├── CreateImageVariation.php │ ├── CreateModeration.php │ ├── CreateTranscription.php │ ├── CreateTranslation.php │ ├── DeleteFile.php │ ├── DeleteModel.php │ ├── DownloadFile.php │ ├── ListFiles.php │ ├── ListFineTuneEvents.php │ ├── ListFineTunes.php │ ├── ListModels.php │ ├── RetrieveFile.php │ ├── RetrieveFineTune.php │ └── RetrieveModel.php ├── Model │ ├── ChatCompletionFunctions.php │ ├── ChatCompletionRequestMessage.php │ ├── ChatCompletionRequestMessageFunctionCall.php │ ├── ChatCompletionResponseMessage.php │ ├── ChatCompletionResponseMessageFunctionCall.php │ ├── CreateAnswerRequest.php │ ├── CreateAnswerResponse.php │ ├── CreateAnswerResponseSelectedDocumentsItem.php │ ├── CreateChatCompletionRequest.php │ ├── CreateChatCompletionResponse.php │ ├── CreateChatCompletionResponseChoicesItem.php │ ├── CreateChatCompletionResponseUsage.php │ ├── CreateClassificationRequest.php │ ├── CreateClassificationResponse.php │ ├── CreateClassificationResponseSelectedExamplesItem.php │ ├── CreateCompletionRequest.php │ ├── CreateCompletionResponse.php │ ├── CreateCompletionResponseChoicesItem.php │ ├── CreateCompletionResponseChoicesItemLogprobs.php │ ├── CreateCompletionResponseUsage.php │ ├── CreateEditRequest.php │ ├── CreateEditResponse.php │ ├── CreateEditResponseChoicesItem.php │ ├── CreateEditResponseChoicesItemLogprobs.php │ ├── CreateEditResponseUsage.php │ ├── CreateEmbeddingRequest.php │ ├── CreateEmbeddingResponse.php │ ├── CreateEmbeddingResponseDataItem.php │ ├── CreateEmbeddingResponseUsage.php │ ├── CreateFileRequest.php │ ├── CreateFineTuneRequest.php │ ├── CreateImageEditRequest.php │ ├── CreateImageRequest.php │ ├── CreateImageVariationRequest.php │ ├── CreateModerationRequest.php │ ├── CreateModerationResponse.php │ ├── CreateModerationResponseResultsItem.php │ ├── CreateModerationResponseResultsItemCategories.php │ ├── CreateModerationResponseResultsItemCategoryScores.php │ ├── CreateSearchRequest.php │ ├── CreateSearchResponse.php │ ├── CreateSearchResponseDataItem.php │ ├── CreateTranscriptionRequest.php │ ├── CreateTranscriptionResponse.php │ ├── CreateTranslationRequest.php │ ├── CreateTranslationResponse.php │ ├── DeleteFileResponse.php │ ├── DeleteModelResponse.php │ ├── Engine.php │ ├── Error.php │ ├── ErrorResponse.php │ ├── FineTune.php │ ├── FineTuneEvent.php │ ├── ImagesResponse.php │ ├── ImagesResponseDataItem.php │ ├── ListEnginesResponse.php │ ├── ListFilesResponse.php │ ├── ListFineTuneEventsResponse.php │ ├── ListFineTunesResponse.php │ ├── ListModelsResponse.php │ ├── Model.php │ └── OpenAIFile.php ├── Normalizer │ ├── ChatCompletionFunctionsNormalizer.php │ ├── ChatCompletionRequestMessageFunctionCallNormalizer.php │ ├── ChatCompletionRequestMessageNormalizer.php │ ├── ChatCompletionResponseMessageFunctionCallNormalizer.php │ ├── ChatCompletionResponseMessageNormalizer.php │ ├── CreateAnswerRequestNormalizer.php │ ├── CreateAnswerResponseNormalizer.php │ ├── CreateAnswerResponseSelectedDocumentsItemNormalizer.php │ ├── CreateChatCompletionRequestNormalizer.php │ ├── CreateChatCompletionResponseChoicesItemNormalizer.php │ ├── CreateChatCompletionResponseNormalizer.php │ ├── CreateChatCompletionResponseUsageNormalizer.php │ ├── CreateClassificationRequestNormalizer.php │ ├── CreateClassificationResponseNormalizer.php │ ├── CreateClassificationResponseSelectedExamplesItemNormalizer.php │ ├── CreateCompletionRequestNormalizer.php │ ├── CreateCompletionResponseChoicesItemLogprobsNormalizer.php │ ├── CreateCompletionResponseChoicesItemNormalizer.php │ ├── CreateCompletionResponseNormalizer.php │ ├── CreateCompletionResponseUsageNormalizer.php │ ├── CreateEditRequestNormalizer.php │ ├── CreateEditResponseChoicesItemLogprobsNormalizer.php │ ├── CreateEditResponseChoicesItemNormalizer.php │ ├── CreateEditResponseNormalizer.php │ ├── CreateEditResponseUsageNormalizer.php │ ├── CreateEmbeddingRequestNormalizer.php │ ├── CreateEmbeddingResponseDataItemNormalizer.php │ ├── CreateEmbeddingResponseNormalizer.php │ ├── CreateEmbeddingResponseUsageNormalizer.php │ ├── CreateFileRequestNormalizer.php │ ├── CreateFineTuneRequestNormalizer.php │ ├── CreateImageEditRequestNormalizer.php │ ├── CreateImageRequestNormalizer.php │ ├── CreateImageVariationRequestNormalizer.php │ ├── CreateModerationRequestNormalizer.php │ ├── CreateModerationResponseNormalizer.php │ ├── CreateModerationResponseResultsItemCategoriesNormalizer.php │ ├── CreateModerationResponseResultsItemCategoryScoresNormalizer.php │ ├── CreateModerationResponseResultsItemNormalizer.php │ ├── CreateSearchRequestNormalizer.php │ ├── CreateSearchResponseDataItemNormalizer.php │ ├── CreateSearchResponseNormalizer.php │ ├── CreateTranscriptionRequestNormalizer.php │ ├── CreateTranscriptionResponseNormalizer.php │ ├── CreateTranslationRequestNormalizer.php │ ├── CreateTranslationResponseNormalizer.php │ ├── DeleteFileResponseNormalizer.php │ ├── DeleteModelResponseNormalizer.php │ ├── EngineNormalizer.php │ ├── ErrorNormalizer.php │ ├── ErrorResponseNormalizer.php │ ├── FineTuneEventNormalizer.php │ ├── FineTuneNormalizer.php │ ├── ImagesResponseDataItemNormalizer.php │ ├── ImagesResponseNormalizer.php │ ├── JaneObjectNormalizer.php │ ├── ListEnginesResponseNormalizer.php │ ├── ListFilesResponseNormalizer.php │ ├── ListFineTuneEventsResponseNormalizer.php │ ├── ListFineTunesResponseNormalizer.php │ ├── ListModelsResponseNormalizer.php │ ├── ModelNormalizer.php │ └── OpenAIFileNormalizer.php └── Runtime │ ├── Client │ ├── BaseEndpoint.php │ ├── Client.php │ ├── CustomQueryResolver.php │ ├── Endpoint.php │ └── EndpointTrait.php │ └── Normalizer │ ├── CheckArray.php │ ├── ReferenceNormalizer.php │ ├── ValidationException.php │ └── ValidatorTrait.php ├── phpunit.xml ├── rector.php ├── src ├── Client.php └── Pricing │ ├── ModelPricing.php │ ├── ModelPricingRepository.php │ ├── ResponseCost.php │ ├── ResponseCostCalculator.php │ └── TokenPricing.php └── tests └── Pricing ├── ModelPricingRepositoryTest.php ├── ResponseCostCalculatorTest.php └── TokenPricingTest.php /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.{php,html,twig,yaml,yaml.dist,yml,yml.dist,neon,xml,xml.dist,neon,neon.dist}] 13 | indent_size = 4 14 | 15 | [Makefile] 16 | indent_size = 4 17 | indent_style = tab 18 | 19 | [{composer.json,composer.lock}] 20 | indent_size = 4 21 | 22 | [*.md] 23 | trim_trailing_whitespace = false 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor/ 2 | /composer.lock 3 | /var/ 4 | /.phpunit.cache 5 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "openai-openapi"] 2 | path = openai-openapi 3 | url = https://github.com/sourceability/openai-openapi.git 4 | -------------------------------------------------------------------------------- /.jane-openapi: -------------------------------------------------------------------------------- 1 | __DIR__ . '/var/openapi-no-deprecated.yaml', 5 | 'namespace' => 'Sourceability\OpenAIClient\Generated', 6 | 'directory' => __DIR__ . '/generated', 7 | ]; -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM thecodingmachine/php:8.1-v4-cli 2 | 3 | COPY --from=mikefarah/yq /usr/bin/yq /usr/bin/yq 4 | 5 | RUN sudo apt-get update ; sudo apt-get install -y make 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Sourceability 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 all 13 | 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 THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | SHELL = /bin/bash 2 | 3 | openai-openapi: 4 | git clone git@github.com:openai/openai-openapi.git 5 | 6 | var/openapi-no-deprecated.yaml: 7 | mkdir -p ./var 8 | yq eval 'del(.paths | .. | select(has("deprecated") and .deprecated == true))' ./openai-openapi/openapi.yaml > $@ 9 | 10 | generated: openai-openapi 11 | vendor/bin/jane-openapi generate 12 | 13 | .PHONY: php 14 | php: 15 | docker-compose run --build php bash 16 | 17 | .PHONY: rector-check 18 | rector-check: 19 | vendor/bin/rector process --clear-cache --dry-run 20 | 21 | .PHONY: rector 22 | rector: 23 | vendor/bin/rector process --clear-cache 24 | 25 | .PHONY: cs 26 | cs: 27 | vendor/bin/ecs --fix 28 | 29 | .PHONY: cs-check 30 | cs-check: 31 | vendor/bin/ecs 32 | 33 | .PHONY: phpunit 34 | phpunit: 35 | vendor/bin/phpunit 36 | 37 | .PHONY: pre-commit 38 | pre-commit: 39 | $(MAKE) -k rector cs phpunit 40 | 41 | .PHONY: build 42 | build: var/openapi-no-deprecated.yaml 43 | time (time bin/jane generate ; for in in {1..4} ; do time (vendor/bin/rector process ; vendor/bin/ecs --fix); done) 44 | -------------------------------------------------------------------------------- /bin/jane: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | add(new GenerateCommand($configLoader, new SchemaLoader(), new OpenApiMatcher())); 20 | $this->add(new DumpConfigCommand($configLoader)); 21 | } 22 | } 23 | 24 | return (new Application())->run(); 25 | -------------------------------------------------------------------------------- /build/GenerateCommand.php: -------------------------------------------------------------------------------- 1 | setOpenApiClass(JaneOpenApi::class); 18 | 19 | return $registry; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /build/JaneOpenApi.php: -------------------------------------------------------------------------------- 1 | create(ParserFactory::PREFER_PHP7); 20 | 21 | foreach (parent::generators($denormalizer, $options) as $generator) { 22 | if ($generator instanceof ModelGenerator) { 23 | yield new ModelWithConstructorGenerator($naming, $parser); 24 | 25 | continue; 26 | } 27 | 28 | yield $generator; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sourceability/openai-client", 3 | "description": "PHP 8.0+ OpenAI API client with fully typed/documented requests+responses models, guzzle and symfony/http-client support and async/parallel requests.", 4 | "keywords": ["php", "OpenAI", "GPT", "GPT-3", "guzzle", "sdk"], 5 | "type": "library", 6 | "license": "MIT", 7 | "autoload": { 8 | "psr-4": { 9 | "Sourceability\\OpenAIClient\\": "src/", 10 | "Sourceability\\OpenAIClient\\Generated\\": "generated/" 11 | } 12 | }, 13 | "autoload-dev": { 14 | "psr-4": { 15 | "Sourceability\\OpenAIClient\\Build\\": "build/", 16 | "Sourceability\\OpenAIClient\\Tests\\": "tests/" 17 | } 18 | }, 19 | "require": { 20 | "php": ">8.0", 21 | "php-http/httplug": "^2.0", 22 | "php-http/discovery": "^1.0", 23 | "php-http/message": "^1.0", 24 | "jane-php/open-api-runtime": "^7.0", 25 | "brick/money": "^0.8.0" 26 | }, 27 | "require-dev": { 28 | "guzzlehttp/psr7": "^2.4", 29 | "guzzlehttp/guzzle": "^7.5", 30 | "php-http/guzzle7-adapter": "^1.0", 31 | "jane-php/open-api-3": "^7.4", 32 | "rector/rector": "^0.15.16", 33 | "symplify/easy-coding-standard": "^11.2", 34 | "slevomat/coding-standard": "^8.8", 35 | "php-http/logger-plugin": "^1.3", 36 | "phpunit/phpunit": "^10.0" 37 | }, 38 | "config": { 39 | "allow-plugins": { 40 | "php-http/discovery": true, 41 | "dealerdirect/phpcodesniffer-composer-installer": false 42 | } 43 | }, 44 | "extra": { 45 | "symfony": { 46 | "allow-contrib": "true" 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /docker-compose.yaml: -------------------------------------------------------------------------------- 1 | services: 2 | php: 3 | build: . 4 | environment: 5 | PHP_EXTENSION_INTL: 1 6 | volumes: 7 | - .:/usr/src/app:cached 8 | -------------------------------------------------------------------------------- /ecs.php: -------------------------------------------------------------------------------- 1 | paths([ 9 | __DIR__ . '/build', 10 | __DIR__ . '/generated', 11 | __DIR__ . '/src', 12 | ]); 13 | 14 | // A. full sets 15 | $ecsConfig->sets([ 16 | SetList::PSR_12, 17 | SetList::CLEAN_CODE, 18 | SetList::ARRAY, 19 | SetList::COMMON, 20 | SetList::COMMENTS, 21 | SetList::CONTROL_STRUCTURES, 22 | SetList::DOCBLOCK, 23 | SetList::NAMESPACES, 24 | SetList::SPACES, 25 | ]); 26 | 27 | $ecsConfig->ruleWithConfiguration(ArraySyntaxFixer::class, [ 28 | 'syntax' => 'short', 29 | ]); 30 | }; -------------------------------------------------------------------------------- /example-chat.php: -------------------------------------------------------------------------------- 1 | createChatCompletions($requests); 47 | 48 | var_dump( 49 | array_map( 50 | fn (CreateChatCompletionResponse $response) => $response->getChoices()[0]->getMessage()->getContent(), 51 | $completionResponses 52 | ) 53 | ); 54 | -------------------------------------------------------------------------------- /example.php: -------------------------------------------------------------------------------- 1 | createCompletions($requests); 38 | 39 | var_dump( 40 | array_map( 41 | fn (CreateCompletionResponse $response) => $response->getChoices()[0]->getText(), 42 | $completionResponses 43 | ) 44 | ); 45 | -------------------------------------------------------------------------------- /generated/Endpoint/CancelFineTune.php: -------------------------------------------------------------------------------- 1 | fine_tune_id], '/fine-tunes/{fine_tune_id}/cancel'); 34 | } 35 | 36 | public function getBody(SerializerInterface $serializer, $streamFactory = null): array 37 | { 38 | return [[], null]; 39 | } 40 | 41 | /** 42 | * @return array{Accept: string[]} 43 | */ 44 | public function getExtraHeaders(): array 45 | { 46 | return [ 47 | 'Accept' => ['application/json'], 48 | ]; 49 | } 50 | 51 | public function getAuthenticationScopes(): array 52 | { 53 | return []; 54 | } 55 | 56 | /** 57 | * @return null|FineTune 58 | */ 59 | protected function transformResponseBody(ResponseInterface $response, SerializerInterface $serializer, ?string $contentType = null) 60 | { 61 | $status = $response->getStatusCode(); 62 | $body = (string) $response->getBody(); 63 | if (($contentType === null) === false && ($status === 200 && mb_strpos($contentType, 'application/json') !== false)) { 64 | return $serializer->deserialize($body, FineTune::class, 'json'); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /generated/Endpoint/CreateChatCompletion.php: -------------------------------------------------------------------------------- 1 | body = $requestBody; 22 | } 23 | 24 | public function getMethod(): string 25 | { 26 | return 'POST'; 27 | } 28 | 29 | public function getUri(): string 30 | { 31 | return '/chat/completions'; 32 | } 33 | 34 | public function getBody(SerializerInterface $serializer, $streamFactory = null): array 35 | { 36 | if ($this->body instanceof CreateChatCompletionRequest) { 37 | return [[ 38 | 'Content-Type' => ['application/json'], 39 | ], $serializer->serialize($this->body, 'json')]; 40 | } 41 | return [[], null]; 42 | } 43 | 44 | /** 45 | * @return array{Accept: string[]} 46 | */ 47 | public function getExtraHeaders(): array 48 | { 49 | return [ 50 | 'Accept' => ['application/json'], 51 | ]; 52 | } 53 | 54 | public function getAuthenticationScopes(): array 55 | { 56 | return []; 57 | } 58 | 59 | /** 60 | * @return null|CreateChatCompletionResponse 61 | */ 62 | protected function transformResponseBody(ResponseInterface $response, SerializerInterface $serializer, ?string $contentType = null) 63 | { 64 | $status = $response->getStatusCode(); 65 | $body = (string) $response->getBody(); 66 | if (($contentType === null) === false && ($status === 200 && mb_strpos($contentType, 'application/json') !== false)) { 67 | return $serializer->deserialize($body, CreateChatCompletionResponse::class, 'json'); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /generated/Endpoint/CreateCompletion.php: -------------------------------------------------------------------------------- 1 | body = $requestBody; 22 | } 23 | 24 | public function getMethod(): string 25 | { 26 | return 'POST'; 27 | } 28 | 29 | public function getUri(): string 30 | { 31 | return '/completions'; 32 | } 33 | 34 | public function getBody(SerializerInterface $serializer, $streamFactory = null): array 35 | { 36 | if ($this->body instanceof CreateCompletionRequest) { 37 | return [[ 38 | 'Content-Type' => ['application/json'], 39 | ], $serializer->serialize($this->body, 'json')]; 40 | } 41 | return [[], null]; 42 | } 43 | 44 | /** 45 | * @return array{Accept: string[]} 46 | */ 47 | public function getExtraHeaders(): array 48 | { 49 | return [ 50 | 'Accept' => ['application/json'], 51 | ]; 52 | } 53 | 54 | public function getAuthenticationScopes(): array 55 | { 56 | return []; 57 | } 58 | 59 | /** 60 | * @return null|CreateCompletionResponse 61 | */ 62 | protected function transformResponseBody(ResponseInterface $response, SerializerInterface $serializer, ?string $contentType = null) 63 | { 64 | $status = $response->getStatusCode(); 65 | $body = (string) $response->getBody(); 66 | if (($contentType === null) === false && ($status === 200 && mb_strpos($contentType, 'application/json') !== false)) { 67 | return $serializer->deserialize($body, CreateCompletionResponse::class, 'json'); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /generated/Endpoint/CreateEdit.php: -------------------------------------------------------------------------------- 1 | body = $requestBody; 22 | } 23 | 24 | public function getMethod(): string 25 | { 26 | return 'POST'; 27 | } 28 | 29 | public function getUri(): string 30 | { 31 | return '/edits'; 32 | } 33 | 34 | public function getBody(SerializerInterface $serializer, $streamFactory = null): array 35 | { 36 | if ($this->body instanceof CreateEditRequest) { 37 | return [[ 38 | 'Content-Type' => ['application/json'], 39 | ], $serializer->serialize($this->body, 'json')]; 40 | } 41 | return [[], null]; 42 | } 43 | 44 | /** 45 | * @return array{Accept: string[]} 46 | */ 47 | public function getExtraHeaders(): array 48 | { 49 | return [ 50 | 'Accept' => ['application/json'], 51 | ]; 52 | } 53 | 54 | public function getAuthenticationScopes(): array 55 | { 56 | return []; 57 | } 58 | 59 | /** 60 | * @return null|CreateEditResponse 61 | */ 62 | protected function transformResponseBody(ResponseInterface $response, SerializerInterface $serializer, ?string $contentType = null) 63 | { 64 | $status = $response->getStatusCode(); 65 | $body = (string) $response->getBody(); 66 | if (($contentType === null) === false && ($status === 200 && mb_strpos($contentType, 'application/json') !== false)) { 67 | return $serializer->deserialize($body, CreateEditResponse::class, 'json'); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /generated/Endpoint/CreateEmbedding.php: -------------------------------------------------------------------------------- 1 | body = $requestBody; 22 | } 23 | 24 | public function getMethod(): string 25 | { 26 | return 'POST'; 27 | } 28 | 29 | public function getUri(): string 30 | { 31 | return '/embeddings'; 32 | } 33 | 34 | public function getBody(SerializerInterface $serializer, $streamFactory = null): array 35 | { 36 | if ($this->body instanceof CreateEmbeddingRequest) { 37 | return [[ 38 | 'Content-Type' => ['application/json'], 39 | ], $serializer->serialize($this->body, 'json')]; 40 | } 41 | return [[], null]; 42 | } 43 | 44 | /** 45 | * @return array{Accept: string[]} 46 | */ 47 | public function getExtraHeaders(): array 48 | { 49 | return [ 50 | 'Accept' => ['application/json'], 51 | ]; 52 | } 53 | 54 | public function getAuthenticationScopes(): array 55 | { 56 | return []; 57 | } 58 | 59 | /** 60 | * @return null|CreateEmbeddingResponse 61 | */ 62 | protected function transformResponseBody(ResponseInterface $response, SerializerInterface $serializer, ?string $contentType = null) 63 | { 64 | $status = $response->getStatusCode(); 65 | $body = (string) $response->getBody(); 66 | if (($contentType === null) === false && ($status === 200 && mb_strpos($contentType, 'application/json') !== false)) { 67 | return $serializer->deserialize($body, CreateEmbeddingResponse::class, 'json'); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /generated/Endpoint/CreateFile.php: -------------------------------------------------------------------------------- 1 | body = $requestBody; 23 | } 24 | 25 | public function getMethod(): string 26 | { 27 | return 'POST'; 28 | } 29 | 30 | public function getUri(): string 31 | { 32 | return '/files'; 33 | } 34 | 35 | public function getBody(SerializerInterface $serializer, $streamFactory = null): array 36 | { 37 | if ($this->body instanceof CreateFileRequest) { 38 | $bodyBuilder = new MultipartStreamBuilder($streamFactory); 39 | $formParameters = $serializer->normalize($this->body, 'json'); 40 | foreach ($formParameters as $key => $value) { 41 | $value = is_int($value) ? (string) $value : $value; 42 | $bodyBuilder->addResource($key, $value); 43 | } 44 | return [[ 45 | 'Content-Type' => ['multipart/form-data; boundary="' . ($bodyBuilder->getBoundary() . '""')], 46 | ], $bodyBuilder->build()]; 47 | } 48 | return [[], null]; 49 | } 50 | 51 | /** 52 | * @return array{Accept: string[]} 53 | */ 54 | public function getExtraHeaders(): array 55 | { 56 | return [ 57 | 'Accept' => ['application/json'], 58 | ]; 59 | } 60 | 61 | public function getAuthenticationScopes(): array 62 | { 63 | return []; 64 | } 65 | 66 | /** 67 | * @return null|OpenAIFile 68 | */ 69 | protected function transformResponseBody(ResponseInterface $response, SerializerInterface $serializer, ?string $contentType = null) 70 | { 71 | $status = $response->getStatusCode(); 72 | $body = (string) $response->getBody(); 73 | if (($contentType === null) === false && ($status === 200 && mb_strpos($contentType, 'application/json') !== false)) { 74 | return $serializer->deserialize($body, OpenAIFile::class, 'json'); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /generated/Endpoint/CreateFineTune.php: -------------------------------------------------------------------------------- 1 | body = $requestBody; 22 | } 23 | 24 | public function getMethod(): string 25 | { 26 | return 'POST'; 27 | } 28 | 29 | public function getUri(): string 30 | { 31 | return '/fine-tunes'; 32 | } 33 | 34 | public function getBody(SerializerInterface $serializer, $streamFactory = null): array 35 | { 36 | if ($this->body instanceof CreateFineTuneRequest) { 37 | return [[ 38 | 'Content-Type' => ['application/json'], 39 | ], $serializer->serialize($this->body, 'json')]; 40 | } 41 | return [[], null]; 42 | } 43 | 44 | /** 45 | * @return array{Accept: string[]} 46 | */ 47 | public function getExtraHeaders(): array 48 | { 49 | return [ 50 | 'Accept' => ['application/json'], 51 | ]; 52 | } 53 | 54 | public function getAuthenticationScopes(): array 55 | { 56 | return []; 57 | } 58 | 59 | /** 60 | * @return null|FineTune 61 | */ 62 | protected function transformResponseBody(ResponseInterface $response, SerializerInterface $serializer, ?string $contentType = null) 63 | { 64 | $status = $response->getStatusCode(); 65 | $body = (string) $response->getBody(); 66 | if (($contentType === null) === false && ($status === 200 && mb_strpos($contentType, 'application/json') !== false)) { 67 | return $serializer->deserialize($body, FineTune::class, 'json'); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /generated/Endpoint/CreateImage.php: -------------------------------------------------------------------------------- 1 | body = $requestBody; 22 | } 23 | 24 | public function getMethod(): string 25 | { 26 | return 'POST'; 27 | } 28 | 29 | public function getUri(): string 30 | { 31 | return '/images/generations'; 32 | } 33 | 34 | public function getBody(SerializerInterface $serializer, $streamFactory = null): array 35 | { 36 | if ($this->body instanceof CreateImageRequest) { 37 | return [[ 38 | 'Content-Type' => ['application/json'], 39 | ], $serializer->serialize($this->body, 'json')]; 40 | } 41 | return [[], null]; 42 | } 43 | 44 | /** 45 | * @return array{Accept: string[]} 46 | */ 47 | public function getExtraHeaders(): array 48 | { 49 | return [ 50 | 'Accept' => ['application/json'], 51 | ]; 52 | } 53 | 54 | public function getAuthenticationScopes(): array 55 | { 56 | return []; 57 | } 58 | 59 | /** 60 | * @return null|ImagesResponse 61 | */ 62 | protected function transformResponseBody(ResponseInterface $response, SerializerInterface $serializer, ?string $contentType = null) 63 | { 64 | $status = $response->getStatusCode(); 65 | $body = (string) $response->getBody(); 66 | if (($contentType === null) === false && ($status === 200 && mb_strpos($contentType, 'application/json') !== false)) { 67 | return $serializer->deserialize($body, ImagesResponse::class, 'json'); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /generated/Endpoint/CreateImageEdit.php: -------------------------------------------------------------------------------- 1 | body = $requestBody; 23 | } 24 | 25 | public function getMethod(): string 26 | { 27 | return 'POST'; 28 | } 29 | 30 | public function getUri(): string 31 | { 32 | return '/images/edits'; 33 | } 34 | 35 | public function getBody(SerializerInterface $serializer, $streamFactory = null): array 36 | { 37 | if ($this->body instanceof CreateImageEditRequest) { 38 | $bodyBuilder = new MultipartStreamBuilder($streamFactory); 39 | $formParameters = $serializer->normalize($this->body, 'json'); 40 | foreach ($formParameters as $key => $value) { 41 | $value = is_int($value) ? (string) $value : $value; 42 | $bodyBuilder->addResource($key, $value); 43 | } 44 | return [[ 45 | 'Content-Type' => ['multipart/form-data; boundary="' . ($bodyBuilder->getBoundary() . '""')], 46 | ], $bodyBuilder->build()]; 47 | } 48 | return [[], null]; 49 | } 50 | 51 | /** 52 | * @return array{Accept: string[]} 53 | */ 54 | public function getExtraHeaders(): array 55 | { 56 | return [ 57 | 'Accept' => ['application/json'], 58 | ]; 59 | } 60 | 61 | public function getAuthenticationScopes(): array 62 | { 63 | return []; 64 | } 65 | 66 | /** 67 | * @return null|ImagesResponse 68 | */ 69 | protected function transformResponseBody(ResponseInterface $response, SerializerInterface $serializer, ?string $contentType = null) 70 | { 71 | $status = $response->getStatusCode(); 72 | $body = (string) $response->getBody(); 73 | if (($contentType === null) === false && ($status === 200 && mb_strpos($contentType, 'application/json') !== false)) { 74 | return $serializer->deserialize($body, ImagesResponse::class, 'json'); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /generated/Endpoint/CreateImageVariation.php: -------------------------------------------------------------------------------- 1 | body = $requestBody; 23 | } 24 | 25 | public function getMethod(): string 26 | { 27 | return 'POST'; 28 | } 29 | 30 | public function getUri(): string 31 | { 32 | return '/images/variations'; 33 | } 34 | 35 | public function getBody(SerializerInterface $serializer, $streamFactory = null): array 36 | { 37 | if ($this->body instanceof CreateImageVariationRequest) { 38 | $bodyBuilder = new MultipartStreamBuilder($streamFactory); 39 | $formParameters = $serializer->normalize($this->body, 'json'); 40 | foreach ($formParameters as $key => $value) { 41 | $value = is_int($value) ? (string) $value : $value; 42 | $bodyBuilder->addResource($key, $value); 43 | } 44 | return [[ 45 | 'Content-Type' => ['multipart/form-data; boundary="' . ($bodyBuilder->getBoundary() . '""')], 46 | ], $bodyBuilder->build()]; 47 | } 48 | return [[], null]; 49 | } 50 | 51 | /** 52 | * @return array{Accept: string[]} 53 | */ 54 | public function getExtraHeaders(): array 55 | { 56 | return [ 57 | 'Accept' => ['application/json'], 58 | ]; 59 | } 60 | 61 | public function getAuthenticationScopes(): array 62 | { 63 | return []; 64 | } 65 | 66 | /** 67 | * @return null|ImagesResponse 68 | */ 69 | protected function transformResponseBody(ResponseInterface $response, SerializerInterface $serializer, ?string $contentType = null) 70 | { 71 | $status = $response->getStatusCode(); 72 | $body = (string) $response->getBody(); 73 | if (($contentType === null) === false && ($status === 200 && mb_strpos($contentType, 'application/json') !== false)) { 74 | return $serializer->deserialize($body, ImagesResponse::class, 'json'); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /generated/Endpoint/CreateModeration.php: -------------------------------------------------------------------------------- 1 | body = $requestBody; 22 | } 23 | 24 | public function getMethod(): string 25 | { 26 | return 'POST'; 27 | } 28 | 29 | public function getUri(): string 30 | { 31 | return '/moderations'; 32 | } 33 | 34 | public function getBody(SerializerInterface $serializer, $streamFactory = null): array 35 | { 36 | if ($this->body instanceof CreateModerationRequest) { 37 | return [[ 38 | 'Content-Type' => ['application/json'], 39 | ], $serializer->serialize($this->body, 'json')]; 40 | } 41 | return [[], null]; 42 | } 43 | 44 | /** 45 | * @return array{Accept: string[]} 46 | */ 47 | public function getExtraHeaders(): array 48 | { 49 | return [ 50 | 'Accept' => ['application/json'], 51 | ]; 52 | } 53 | 54 | public function getAuthenticationScopes(): array 55 | { 56 | return []; 57 | } 58 | 59 | /** 60 | * @return null|CreateModerationResponse 61 | */ 62 | protected function transformResponseBody(ResponseInterface $response, SerializerInterface $serializer, ?string $contentType = null) 63 | { 64 | $status = $response->getStatusCode(); 65 | $body = (string) $response->getBody(); 66 | if (($contentType === null) === false && ($status === 200 && mb_strpos($contentType, 'application/json') !== false)) { 67 | return $serializer->deserialize($body, CreateModerationResponse::class, 'json'); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /generated/Endpoint/CreateTranscription.php: -------------------------------------------------------------------------------- 1 | body = $requestBody; 23 | } 24 | 25 | public function getMethod(): string 26 | { 27 | return 'POST'; 28 | } 29 | 30 | public function getUri(): string 31 | { 32 | return '/audio/transcriptions'; 33 | } 34 | 35 | public function getBody(SerializerInterface $serializer, $streamFactory = null): array 36 | { 37 | if ($this->body instanceof CreateTranscriptionRequest) { 38 | $bodyBuilder = new MultipartStreamBuilder($streamFactory); 39 | $formParameters = $serializer->normalize($this->body, 'json'); 40 | foreach ($formParameters as $key => $value) { 41 | $value = is_int($value) ? (string) $value : $value; 42 | $bodyBuilder->addResource($key, $value); 43 | } 44 | return [[ 45 | 'Content-Type' => ['multipart/form-data; boundary="' . ($bodyBuilder->getBoundary() . '""')], 46 | ], $bodyBuilder->build()]; 47 | } 48 | return [[], null]; 49 | } 50 | 51 | /** 52 | * @return array{Accept: string[]} 53 | */ 54 | public function getExtraHeaders(): array 55 | { 56 | return [ 57 | 'Accept' => ['application/json'], 58 | ]; 59 | } 60 | 61 | public function getAuthenticationScopes(): array 62 | { 63 | return []; 64 | } 65 | 66 | /** 67 | * @return null|CreateTranscriptionResponse 68 | */ 69 | protected function transformResponseBody(ResponseInterface $response, SerializerInterface $serializer, ?string $contentType = null) 70 | { 71 | $status = $response->getStatusCode(); 72 | $body = (string) $response->getBody(); 73 | if (($contentType === null) === false && ($status === 200 && mb_strpos($contentType, 'application/json') !== false)) { 74 | return $serializer->deserialize($body, CreateTranscriptionResponse::class, 'json'); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /generated/Endpoint/CreateTranslation.php: -------------------------------------------------------------------------------- 1 | body = $requestBody; 23 | } 24 | 25 | public function getMethod(): string 26 | { 27 | return 'POST'; 28 | } 29 | 30 | public function getUri(): string 31 | { 32 | return '/audio/translations'; 33 | } 34 | 35 | public function getBody(SerializerInterface $serializer, $streamFactory = null): array 36 | { 37 | if ($this->body instanceof CreateTranslationRequest) { 38 | $bodyBuilder = new MultipartStreamBuilder($streamFactory); 39 | $formParameters = $serializer->normalize($this->body, 'json'); 40 | foreach ($formParameters as $key => $value) { 41 | $value = is_int($value) ? (string) $value : $value; 42 | $bodyBuilder->addResource($key, $value); 43 | } 44 | return [[ 45 | 'Content-Type' => ['multipart/form-data; boundary="' . ($bodyBuilder->getBoundary() . '""')], 46 | ], $bodyBuilder->build()]; 47 | } 48 | return [[], null]; 49 | } 50 | 51 | /** 52 | * @return array{Accept: string[]} 53 | */ 54 | public function getExtraHeaders(): array 55 | { 56 | return [ 57 | 'Accept' => ['application/json'], 58 | ]; 59 | } 60 | 61 | public function getAuthenticationScopes(): array 62 | { 63 | return []; 64 | } 65 | 66 | /** 67 | * @return null|CreateTranslationResponse 68 | */ 69 | protected function transformResponseBody(ResponseInterface $response, SerializerInterface $serializer, ?string $contentType = null) 70 | { 71 | $status = $response->getStatusCode(); 72 | $body = (string) $response->getBody(); 73 | if (($contentType === null) === false && ($status === 200 && mb_strpos($contentType, 'application/json') !== false)) { 74 | return $serializer->deserialize($body, CreateTranslationResponse::class, 'json'); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /generated/Endpoint/DeleteFile.php: -------------------------------------------------------------------------------- 1 | file_id], '/files/{file_id}'); 34 | } 35 | 36 | public function getBody(SerializerInterface $serializer, $streamFactory = null): array 37 | { 38 | return [[], null]; 39 | } 40 | 41 | /** 42 | * @return array{Accept: string[]} 43 | */ 44 | public function getExtraHeaders(): array 45 | { 46 | return [ 47 | 'Accept' => ['application/json'], 48 | ]; 49 | } 50 | 51 | public function getAuthenticationScopes(): array 52 | { 53 | return []; 54 | } 55 | 56 | /** 57 | * @return null|DeleteFileResponse 58 | */ 59 | protected function transformResponseBody(ResponseInterface $response, SerializerInterface $serializer, ?string $contentType = null) 60 | { 61 | $status = $response->getStatusCode(); 62 | $body = (string) $response->getBody(); 63 | if (($contentType === null) === false && ($status === 200 && mb_strpos($contentType, 'application/json') !== false)) { 64 | return $serializer->deserialize($body, DeleteFileResponse::class, 'json'); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /generated/Endpoint/DeleteModel.php: -------------------------------------------------------------------------------- 1 | model], '/models/{model}'); 34 | } 35 | 36 | public function getBody(SerializerInterface $serializer, $streamFactory = null): array 37 | { 38 | return [[], null]; 39 | } 40 | 41 | /** 42 | * @return array{Accept: string[]} 43 | */ 44 | public function getExtraHeaders(): array 45 | { 46 | return [ 47 | 'Accept' => ['application/json'], 48 | ]; 49 | } 50 | 51 | public function getAuthenticationScopes(): array 52 | { 53 | return []; 54 | } 55 | 56 | /** 57 | * @return null|DeleteModelResponse 58 | */ 59 | protected function transformResponseBody(ResponseInterface $response, SerializerInterface $serializer, ?string $contentType = null) 60 | { 61 | $status = $response->getStatusCode(); 62 | $body = (string) $response->getBody(); 63 | if (($contentType === null) === false && ($status === 200 && mb_strpos($contentType, 'application/json') !== false)) { 64 | return $serializer->deserialize($body, DeleteModelResponse::class, 'json'); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /generated/Endpoint/DownloadFile.php: -------------------------------------------------------------------------------- 1 | file_id], '/files/{file_id}/content'); 33 | } 34 | 35 | public function getBody(SerializerInterface $serializer, $streamFactory = null): array 36 | { 37 | return [[], null]; 38 | } 39 | 40 | /** 41 | * @return array{Accept: string[]} 42 | */ 43 | public function getExtraHeaders(): array 44 | { 45 | return [ 46 | 'Accept' => ['application/json'], 47 | ]; 48 | } 49 | 50 | public function getAuthenticationScopes(): array 51 | { 52 | return []; 53 | } 54 | 55 | protected function transformResponseBody(ResponseInterface $response, SerializerInterface $serializer, ?string $contentType = null) 56 | { 57 | $status = $response->getStatusCode(); 58 | $body = (string) $response->getBody(); 59 | if (($contentType === null) === false && ($status === 200 && mb_strpos($contentType, 'application/json') !== false)) { 60 | return json_decode($body, null, 512, JSON_THROW_ON_ERROR); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /generated/Endpoint/ListFiles.php: -------------------------------------------------------------------------------- 1 | ['application/json'], 40 | ]; 41 | } 42 | 43 | public function getAuthenticationScopes(): array 44 | { 45 | return []; 46 | } 47 | 48 | /** 49 | * @return null|ListFilesResponse 50 | */ 51 | protected function transformResponseBody(ResponseInterface $response, SerializerInterface $serializer, ?string $contentType = null) 52 | { 53 | $status = $response->getStatusCode(); 54 | $body = (string) $response->getBody(); 55 | if (($contentType === null) === false && ($status === 200 && mb_strpos($contentType, 'application/json') !== false)) { 56 | return $serializer->deserialize($body, ListFilesResponse::class, 'json'); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /generated/Endpoint/ListFineTuneEvents.php: -------------------------------------------------------------------------------- 1 | queryParameters = $queryParameters; 31 | } 32 | 33 | public function getMethod(): string 34 | { 35 | return 'GET'; 36 | } 37 | 38 | public function getUri(): string 39 | { 40 | return str_replace(['{fine_tune_id}'], [$this->fine_tune_id], '/fine-tunes/{fine_tune_id}/events'); 41 | } 42 | 43 | public function getBody(SerializerInterface $serializer, $streamFactory = null): array 44 | { 45 | return [[], null]; 46 | } 47 | 48 | /** 49 | * @return array{Accept: string[]} 50 | */ 51 | public function getExtraHeaders(): array 52 | { 53 | return [ 54 | 'Accept' => ['application/json'], 55 | ]; 56 | } 57 | 58 | public function getAuthenticationScopes(): array 59 | { 60 | return []; 61 | } 62 | 63 | protected function getQueryOptionsResolver(): OptionsResolver 64 | { 65 | $optionsResolver = parent::getQueryOptionsResolver(); 66 | $optionsResolver->setDefined(['stream']); 67 | $optionsResolver->setRequired([]); 68 | $optionsResolver->setDefaults([ 69 | 'stream' => false, 70 | ]); 71 | $optionsResolver->addAllowedTypes('stream', ['bool']); 72 | return $optionsResolver; 73 | } 74 | 75 | /** 76 | * @return null|ListFineTuneEventsResponse 77 | */ 78 | protected function transformResponseBody(ResponseInterface $response, SerializerInterface $serializer, ?string $contentType = null) 79 | { 80 | $status = $response->getStatusCode(); 81 | $body = (string) $response->getBody(); 82 | if (($contentType === null) === false && ($status === 200 && mb_strpos($contentType, 'application/json') !== false)) { 83 | return $serializer->deserialize($body, ListFineTuneEventsResponse::class, 'json'); 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /generated/Endpoint/ListFineTunes.php: -------------------------------------------------------------------------------- 1 | ['application/json'], 40 | ]; 41 | } 42 | 43 | public function getAuthenticationScopes(): array 44 | { 45 | return []; 46 | } 47 | 48 | /** 49 | * @return null|ListFineTunesResponse 50 | */ 51 | protected function transformResponseBody(ResponseInterface $response, SerializerInterface $serializer, ?string $contentType = null) 52 | { 53 | $status = $response->getStatusCode(); 54 | $body = (string) $response->getBody(); 55 | if (($contentType === null) === false && ($status === 200 && mb_strpos($contentType, 'application/json') !== false)) { 56 | return $serializer->deserialize($body, ListFineTunesResponse::class, 'json'); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /generated/Endpoint/ListModels.php: -------------------------------------------------------------------------------- 1 | ['application/json'], 40 | ]; 41 | } 42 | 43 | public function getAuthenticationScopes(): array 44 | { 45 | return []; 46 | } 47 | 48 | /** 49 | * @return null|ListModelsResponse 50 | */ 51 | protected function transformResponseBody(ResponseInterface $response, SerializerInterface $serializer, ?string $contentType = null) 52 | { 53 | $status = $response->getStatusCode(); 54 | $body = (string) $response->getBody(); 55 | if (($contentType === null) === false && ($status === 200 && mb_strpos($contentType, 'application/json') !== false)) { 56 | return $serializer->deserialize($body, ListModelsResponse::class, 'json'); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /generated/Endpoint/RetrieveFile.php: -------------------------------------------------------------------------------- 1 | file_id], '/files/{file_id}'); 34 | } 35 | 36 | public function getBody(SerializerInterface $serializer, $streamFactory = null): array 37 | { 38 | return [[], null]; 39 | } 40 | 41 | /** 42 | * @return array{Accept: string[]} 43 | */ 44 | public function getExtraHeaders(): array 45 | { 46 | return [ 47 | 'Accept' => ['application/json'], 48 | ]; 49 | } 50 | 51 | public function getAuthenticationScopes(): array 52 | { 53 | return []; 54 | } 55 | 56 | /** 57 | * @return null|OpenAIFile 58 | */ 59 | protected function transformResponseBody(ResponseInterface $response, SerializerInterface $serializer, ?string $contentType = null) 60 | { 61 | $status = $response->getStatusCode(); 62 | $body = (string) $response->getBody(); 63 | if (($contentType === null) === false && ($status === 200 && mb_strpos($contentType, 'application/json') !== false)) { 64 | return $serializer->deserialize($body, OpenAIFile::class, 'json'); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /generated/Endpoint/RetrieveFineTune.php: -------------------------------------------------------------------------------- 1 | fine_tune_id], '/fine-tunes/{fine_tune_id}'); 34 | } 35 | 36 | public function getBody(SerializerInterface $serializer, $streamFactory = null): array 37 | { 38 | return [[], null]; 39 | } 40 | 41 | /** 42 | * @return array{Accept: string[]} 43 | */ 44 | public function getExtraHeaders(): array 45 | { 46 | return [ 47 | 'Accept' => ['application/json'], 48 | ]; 49 | } 50 | 51 | public function getAuthenticationScopes(): array 52 | { 53 | return []; 54 | } 55 | 56 | /** 57 | * @return null|FineTune 58 | */ 59 | protected function transformResponseBody(ResponseInterface $response, SerializerInterface $serializer, ?string $contentType = null) 60 | { 61 | $status = $response->getStatusCode(); 62 | $body = (string) $response->getBody(); 63 | if (($contentType === null) === false && ($status === 200 && mb_strpos($contentType, 'application/json') !== false)) { 64 | return $serializer->deserialize($body, FineTune::class, 'json'); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /generated/Endpoint/RetrieveModel.php: -------------------------------------------------------------------------------- 1 | model], '/models/{model}'); 34 | } 35 | 36 | public function getBody(SerializerInterface $serializer, $streamFactory = null): array 37 | { 38 | return [[], null]; 39 | } 40 | 41 | /** 42 | * @return array{Accept: string[]} 43 | */ 44 | public function getExtraHeaders(): array 45 | { 46 | return [ 47 | 'Accept' => ['application/json'], 48 | ]; 49 | } 50 | 51 | public function getAuthenticationScopes(): array 52 | { 53 | return []; 54 | } 55 | 56 | /** 57 | * @return null|Model 58 | */ 59 | protected function transformResponseBody(ResponseInterface $response, SerializerInterface $serializer, ?string $contentType = null) 60 | { 61 | $status = $response->getStatusCode(); 62 | $body = (string) $response->getBody(); 63 | if (($contentType === null) === false && ($status === 200 && mb_strpos($contentType, 'application/json') !== false)) { 64 | return $serializer->deserialize($body, Model::class, 'json'); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /generated/Model/ChatCompletionRequestMessageFunctionCall.php: -------------------------------------------------------------------------------- 1 | setName($name); 31 | } 32 | if ($arguments !== null) { 33 | $this->setArguments($arguments); 34 | } 35 | } 36 | 37 | public function isInitialized($property): bool 38 | { 39 | return array_key_exists($property, $this->initialized); 40 | } 41 | 42 | /** 43 | * The name of the function to call. 44 | */ 45 | public function getName(): string 46 | { 47 | return $this->name; 48 | } 49 | 50 | /** 51 | * The name of the function to call. 52 | */ 53 | public function setName(string $name): self 54 | { 55 | $this->initialized['name'] = true; 56 | $this->name = $name; 57 | return $this; 58 | } 59 | 60 | /** 61 | * The arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function. 62 | */ 63 | public function getArguments(): string 64 | { 65 | return $this->arguments; 66 | } 67 | 68 | /** 69 | * The arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function. 70 | */ 71 | public function setArguments(string $arguments): self 72 | { 73 | $this->initialized['arguments'] = true; 74 | $this->arguments = $arguments; 75 | return $this; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /generated/Model/ChatCompletionResponseMessage.php: -------------------------------------------------------------------------------- 1 | setRole($role); 37 | } 38 | if ($content !== null) { 39 | $this->setContent($content); 40 | } 41 | if ($functionCall !== null) { 42 | $this->setFunctionCall($functionCall); 43 | } 44 | } 45 | 46 | public function isInitialized($property): bool 47 | { 48 | return array_key_exists($property, $this->initialized); 49 | } 50 | 51 | /** 52 | * The role of the author of this message. 53 | */ 54 | public function getRole(): string 55 | { 56 | return $this->role; 57 | } 58 | 59 | /** 60 | * The role of the author of this message. 61 | */ 62 | public function setRole(string $role): self 63 | { 64 | $this->initialized['role'] = true; 65 | $this->role = $role; 66 | return $this; 67 | } 68 | 69 | /** 70 | * The contents of the message. 71 | */ 72 | public function getContent(): ?string 73 | { 74 | return $this->content; 75 | } 76 | 77 | /** 78 | * The contents of the message. 79 | */ 80 | public function setContent(?string $content): self 81 | { 82 | $this->initialized['content'] = true; 83 | $this->content = $content; 84 | return $this; 85 | } 86 | 87 | /** 88 | * The name and arguments of a function that should be called, as generated by the model. 89 | */ 90 | public function getFunctionCall(): ?ChatCompletionResponseMessageFunctionCall 91 | { 92 | return $this->functionCall; 93 | } 94 | 95 | /** 96 | * The name and arguments of a function that should be called, as generated by the model. 97 | */ 98 | public function setFunctionCall(?ChatCompletionResponseMessageFunctionCall $functionCall): self 99 | { 100 | $this->initialized['functionCall'] = true; 101 | $this->functionCall = $functionCall; 102 | return $this; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /generated/Model/ChatCompletionResponseMessageFunctionCall.php: -------------------------------------------------------------------------------- 1 | setName($name); 31 | } 32 | if ($arguments !== null) { 33 | $this->setArguments($arguments); 34 | } 35 | } 36 | 37 | public function isInitialized($property): bool 38 | { 39 | return array_key_exists($property, $this->initialized); 40 | } 41 | 42 | /** 43 | * The name of the function to call. 44 | */ 45 | public function getName(): string 46 | { 47 | return $this->name; 48 | } 49 | 50 | /** 51 | * The name of the function to call. 52 | */ 53 | public function setName(string $name): self 54 | { 55 | $this->initialized['name'] = true; 56 | $this->name = $name; 57 | return $this; 58 | } 59 | 60 | /** 61 | * The arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function. 62 | */ 63 | public function getArguments(): string 64 | { 65 | return $this->arguments; 66 | } 67 | 68 | /** 69 | * The arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function. 70 | */ 71 | public function setArguments(string $arguments): self 72 | { 73 | $this->initialized['arguments'] = true; 74 | $this->arguments = $arguments; 75 | return $this; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /generated/Model/CreateAnswerResponseSelectedDocumentsItem.php: -------------------------------------------------------------------------------- 1 | setDocument($document); 25 | } 26 | if ($text !== null) { 27 | $this->setText($text); 28 | } 29 | } 30 | 31 | public function isInitialized($property): bool 32 | { 33 | return array_key_exists($property, $this->initialized); 34 | } 35 | 36 | public function getDocument(): int 37 | { 38 | return $this->document; 39 | } 40 | 41 | public function setDocument(int $document): self 42 | { 43 | $this->initialized['document'] = true; 44 | $this->document = $document; 45 | return $this; 46 | } 47 | 48 | public function getText(): string 49 | { 50 | return $this->text; 51 | } 52 | 53 | public function setText(string $text): self 54 | { 55 | $this->initialized['text'] = true; 56 | $this->text = $text; 57 | return $this; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /generated/Model/CreateChatCompletionResponseChoicesItem.php: -------------------------------------------------------------------------------- 1 | setIndex($index); 28 | } 29 | if ($message !== null) { 30 | $this->setMessage($message); 31 | } 32 | if ($finishReason !== null) { 33 | $this->setFinishReason($finishReason); 34 | } 35 | } 36 | 37 | public function isInitialized($property): bool 38 | { 39 | return array_key_exists($property, $this->initialized); 40 | } 41 | 42 | public function getIndex(): int 43 | { 44 | return $this->index; 45 | } 46 | 47 | public function setIndex(int $index): self 48 | { 49 | $this->initialized['index'] = true; 50 | $this->index = $index; 51 | return $this; 52 | } 53 | 54 | public function getMessage(): ChatCompletionResponseMessage 55 | { 56 | return $this->message; 57 | } 58 | 59 | public function setMessage(ChatCompletionResponseMessage $message): self 60 | { 61 | $this->initialized['message'] = true; 62 | $this->message = $message; 63 | return $this; 64 | } 65 | 66 | public function getFinishReason(): ?string 67 | { 68 | return $this->finishReason; 69 | } 70 | 71 | public function setFinishReason(?string $finishReason): self 72 | { 73 | $this->initialized['finishReason'] = true; 74 | $this->finishReason = $finishReason; 75 | return $this; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /generated/Model/CreateChatCompletionResponseUsage.php: -------------------------------------------------------------------------------- 1 | setPromptTokens($promptTokens); 28 | } 29 | if ($completionTokens !== null) { 30 | $this->setCompletionTokens($completionTokens); 31 | } 32 | if ($totalTokens !== null) { 33 | $this->setTotalTokens($totalTokens); 34 | } 35 | } 36 | 37 | public function isInitialized($property): bool 38 | { 39 | return array_key_exists($property, $this->initialized); 40 | } 41 | 42 | public function getPromptTokens(): int 43 | { 44 | return $this->promptTokens; 45 | } 46 | 47 | public function setPromptTokens(int $promptTokens): self 48 | { 49 | $this->initialized['promptTokens'] = true; 50 | $this->promptTokens = $promptTokens; 51 | return $this; 52 | } 53 | 54 | public function getCompletionTokens(): int 55 | { 56 | return $this->completionTokens; 57 | } 58 | 59 | public function setCompletionTokens(int $completionTokens): self 60 | { 61 | $this->initialized['completionTokens'] = true; 62 | $this->completionTokens = $completionTokens; 63 | return $this; 64 | } 65 | 66 | public function getTotalTokens(): int 67 | { 68 | return $this->totalTokens; 69 | } 70 | 71 | public function setTotalTokens(int $totalTokens): self 72 | { 73 | $this->initialized['totalTokens'] = true; 74 | $this->totalTokens = $totalTokens; 75 | return $this; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /generated/Model/CreateClassificationResponseSelectedExamplesItem.php: -------------------------------------------------------------------------------- 1 | setDocument($document); 28 | } 29 | if ($text !== null) { 30 | $this->setText($text); 31 | } 32 | if ($label !== null) { 33 | $this->setLabel($label); 34 | } 35 | } 36 | 37 | public function isInitialized($property): bool 38 | { 39 | return array_key_exists($property, $this->initialized); 40 | } 41 | 42 | public function getDocument(): int 43 | { 44 | return $this->document; 45 | } 46 | 47 | public function setDocument(int $document): self 48 | { 49 | $this->initialized['document'] = true; 50 | $this->document = $document; 51 | return $this; 52 | } 53 | 54 | public function getText(): string 55 | { 56 | return $this->text; 57 | } 58 | 59 | public function setText(string $text): self 60 | { 61 | $this->initialized['text'] = true; 62 | $this->text = $text; 63 | return $this; 64 | } 65 | 66 | public function getLabel(): string 67 | { 68 | return $this->label; 69 | } 70 | 71 | public function setLabel(string $label): self 72 | { 73 | $this->initialized['label'] = true; 74 | $this->label = $label; 75 | return $this; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /generated/Model/CreateCompletionResponseChoicesItem.php: -------------------------------------------------------------------------------- 1 | setText($text); 31 | } 32 | if ($index !== null) { 33 | $this->setIndex($index); 34 | } 35 | if ($logprobs !== null) { 36 | $this->setLogprobs($logprobs); 37 | } 38 | if ($finishReason !== null) { 39 | $this->setFinishReason($finishReason); 40 | } 41 | } 42 | 43 | public function isInitialized($property): bool 44 | { 45 | return array_key_exists($property, $this->initialized); 46 | } 47 | 48 | public function getText(): string 49 | { 50 | return $this->text; 51 | } 52 | 53 | public function setText(string $text): self 54 | { 55 | $this->initialized['text'] = true; 56 | $this->text = $text; 57 | return $this; 58 | } 59 | 60 | public function getIndex(): int 61 | { 62 | return $this->index; 63 | } 64 | 65 | public function setIndex(int $index): self 66 | { 67 | $this->initialized['index'] = true; 68 | $this->index = $index; 69 | return $this; 70 | } 71 | 72 | public function getLogprobs(): ?CreateCompletionResponseChoicesItemLogprobs 73 | { 74 | return $this->logprobs; 75 | } 76 | 77 | public function setLogprobs(?CreateCompletionResponseChoicesItemLogprobs $logprobs): self 78 | { 79 | $this->initialized['logprobs'] = true; 80 | $this->logprobs = $logprobs; 81 | return $this; 82 | } 83 | 84 | public function getFinishReason(): ?string 85 | { 86 | return $this->finishReason; 87 | } 88 | 89 | public function setFinishReason(?string $finishReason): self 90 | { 91 | $this->initialized['finishReason'] = true; 92 | $this->finishReason = $finishReason; 93 | return $this; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /generated/Model/CreateCompletionResponseChoicesItemLogprobs.php: -------------------------------------------------------------------------------- 1 | setTokens($tokens); 43 | } 44 | if ($tokenLogprobs !== null) { 45 | $this->setTokenLogprobs($tokenLogprobs); 46 | } 47 | if ($topLogprobs !== null) { 48 | $this->setTopLogprobs($topLogprobs); 49 | } 50 | if ($textOffset !== null) { 51 | $this->setTextOffset($textOffset); 52 | } 53 | } 54 | 55 | public function isInitialized($property): bool 56 | { 57 | return array_key_exists($property, $this->initialized); 58 | } 59 | 60 | /** 61 | * @return string[] 62 | */ 63 | public function getTokens(): array 64 | { 65 | return $this->tokens; 66 | } 67 | 68 | /** 69 | * @param string[] $tokens 70 | */ 71 | public function setTokens(array $tokens): self 72 | { 73 | $this->initialized['tokens'] = true; 74 | $this->tokens = $tokens; 75 | return $this; 76 | } 77 | 78 | /** 79 | * @return float[] 80 | */ 81 | public function getTokenLogprobs(): array 82 | { 83 | return $this->tokenLogprobs; 84 | } 85 | 86 | /** 87 | * @param float[] $tokenLogprobs 88 | */ 89 | public function setTokenLogprobs(array $tokenLogprobs): self 90 | { 91 | $this->initialized['tokenLogprobs'] = true; 92 | $this->tokenLogprobs = $tokenLogprobs; 93 | return $this; 94 | } 95 | 96 | /** 97 | * @return mixed[][] 98 | */ 99 | public function getTopLogprobs(): array 100 | { 101 | return $this->topLogprobs; 102 | } 103 | 104 | /** 105 | * @param mixed[][] $topLogprobs 106 | */ 107 | public function setTopLogprobs(array $topLogprobs): self 108 | { 109 | $this->initialized['topLogprobs'] = true; 110 | $this->topLogprobs = $topLogprobs; 111 | return $this; 112 | } 113 | 114 | /** 115 | * @return int[] 116 | */ 117 | public function getTextOffset(): array 118 | { 119 | return $this->textOffset; 120 | } 121 | 122 | /** 123 | * @param int[] $textOffset 124 | */ 125 | public function setTextOffset(array $textOffset): self 126 | { 127 | $this->initialized['textOffset'] = true; 128 | $this->textOffset = $textOffset; 129 | return $this; 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /generated/Model/CreateCompletionResponseUsage.php: -------------------------------------------------------------------------------- 1 | setPromptTokens($promptTokens); 28 | } 29 | if ($completionTokens !== null) { 30 | $this->setCompletionTokens($completionTokens); 31 | } 32 | if ($totalTokens !== null) { 33 | $this->setTotalTokens($totalTokens); 34 | } 35 | } 36 | 37 | public function isInitialized($property): bool 38 | { 39 | return array_key_exists($property, $this->initialized); 40 | } 41 | 42 | public function getPromptTokens(): int 43 | { 44 | return $this->promptTokens; 45 | } 46 | 47 | public function setPromptTokens(int $promptTokens): self 48 | { 49 | $this->initialized['promptTokens'] = true; 50 | $this->promptTokens = $promptTokens; 51 | return $this; 52 | } 53 | 54 | public function getCompletionTokens(): int 55 | { 56 | return $this->completionTokens; 57 | } 58 | 59 | public function setCompletionTokens(int $completionTokens): self 60 | { 61 | $this->initialized['completionTokens'] = true; 62 | $this->completionTokens = $completionTokens; 63 | return $this; 64 | } 65 | 66 | public function getTotalTokens(): int 67 | { 68 | return $this->totalTokens; 69 | } 70 | 71 | public function setTotalTokens(int $totalTokens): self 72 | { 73 | $this->initialized['totalTokens'] = true; 74 | $this->totalTokens = $totalTokens; 75 | return $this; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /generated/Model/CreateEditResponse.php: -------------------------------------------------------------------------------- 1 | setObject($object); 34 | } 35 | if ($created !== null) { 36 | $this->setCreated($created); 37 | } 38 | if ($choices !== null) { 39 | $this->setChoices($choices); 40 | } 41 | if ($usage !== null) { 42 | $this->setUsage($usage); 43 | } 44 | } 45 | 46 | public function isInitialized($property): bool 47 | { 48 | return array_key_exists($property, $this->initialized); 49 | } 50 | 51 | public function getObject(): string 52 | { 53 | return $this->object; 54 | } 55 | 56 | public function setObject(string $object): self 57 | { 58 | $this->initialized['object'] = true; 59 | $this->object = $object; 60 | return $this; 61 | } 62 | 63 | public function getCreated(): int 64 | { 65 | return $this->created; 66 | } 67 | 68 | public function setCreated(int $created): self 69 | { 70 | $this->initialized['created'] = true; 71 | $this->created = $created; 72 | return $this; 73 | } 74 | 75 | /** 76 | * @return CreateEditResponseChoicesItem[] 77 | */ 78 | public function getChoices(): array 79 | { 80 | return $this->choices; 81 | } 82 | 83 | /** 84 | * @param CreateEditResponseChoicesItem[] $choices 85 | */ 86 | public function setChoices(array $choices): self 87 | { 88 | $this->initialized['choices'] = true; 89 | $this->choices = $choices; 90 | return $this; 91 | } 92 | 93 | public function getUsage(): CreateEditResponseUsage 94 | { 95 | return $this->usage; 96 | } 97 | 98 | public function setUsage(CreateEditResponseUsage $usage): self 99 | { 100 | $this->initialized['usage'] = true; 101 | $this->usage = $usage; 102 | return $this; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /generated/Model/CreateEditResponseChoicesItem.php: -------------------------------------------------------------------------------- 1 | setText($text); 31 | } 32 | if ($index !== null) { 33 | $this->setIndex($index); 34 | } 35 | if ($logprobs !== null) { 36 | $this->setLogprobs($logprobs); 37 | } 38 | if ($finishReason !== null) { 39 | $this->setFinishReason($finishReason); 40 | } 41 | } 42 | 43 | public function isInitialized($property): bool 44 | { 45 | return array_key_exists($property, $this->initialized); 46 | } 47 | 48 | public function getText(): string 49 | { 50 | return $this->text; 51 | } 52 | 53 | public function setText(string $text): self 54 | { 55 | $this->initialized['text'] = true; 56 | $this->text = $text; 57 | return $this; 58 | } 59 | 60 | public function getIndex(): int 61 | { 62 | return $this->index; 63 | } 64 | 65 | public function setIndex(int $index): self 66 | { 67 | $this->initialized['index'] = true; 68 | $this->index = $index; 69 | return $this; 70 | } 71 | 72 | public function getLogprobs(): ?CreateEditResponseChoicesItemLogprobs 73 | { 74 | return $this->logprobs; 75 | } 76 | 77 | public function setLogprobs(?CreateEditResponseChoicesItemLogprobs $logprobs): self 78 | { 79 | $this->initialized['logprobs'] = true; 80 | $this->logprobs = $logprobs; 81 | return $this; 82 | } 83 | 84 | public function getFinishReason(): string 85 | { 86 | return $this->finishReason; 87 | } 88 | 89 | public function setFinishReason(string $finishReason): self 90 | { 91 | $this->initialized['finishReason'] = true; 92 | $this->finishReason = $finishReason; 93 | return $this; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /generated/Model/CreateEditResponseChoicesItemLogprobs.php: -------------------------------------------------------------------------------- 1 | setTokens($tokens); 43 | } 44 | if ($tokenLogprobs !== null) { 45 | $this->setTokenLogprobs($tokenLogprobs); 46 | } 47 | if ($topLogprobs !== null) { 48 | $this->setTopLogprobs($topLogprobs); 49 | } 50 | if ($textOffset !== null) { 51 | $this->setTextOffset($textOffset); 52 | } 53 | } 54 | 55 | public function isInitialized($property): bool 56 | { 57 | return array_key_exists($property, $this->initialized); 58 | } 59 | 60 | /** 61 | * @return string[] 62 | */ 63 | public function getTokens(): array 64 | { 65 | return $this->tokens; 66 | } 67 | 68 | /** 69 | * @param string[] $tokens 70 | */ 71 | public function setTokens(array $tokens): self 72 | { 73 | $this->initialized['tokens'] = true; 74 | $this->tokens = $tokens; 75 | return $this; 76 | } 77 | 78 | /** 79 | * @return float[] 80 | */ 81 | public function getTokenLogprobs(): array 82 | { 83 | return $this->tokenLogprobs; 84 | } 85 | 86 | /** 87 | * @param float[] $tokenLogprobs 88 | */ 89 | public function setTokenLogprobs(array $tokenLogprobs): self 90 | { 91 | $this->initialized['tokenLogprobs'] = true; 92 | $this->tokenLogprobs = $tokenLogprobs; 93 | return $this; 94 | } 95 | 96 | /** 97 | * @return mixed[][] 98 | */ 99 | public function getTopLogprobs(): array 100 | { 101 | return $this->topLogprobs; 102 | } 103 | 104 | /** 105 | * @param mixed[][] $topLogprobs 106 | */ 107 | public function setTopLogprobs(array $topLogprobs): self 108 | { 109 | $this->initialized['topLogprobs'] = true; 110 | $this->topLogprobs = $topLogprobs; 111 | return $this; 112 | } 113 | 114 | /** 115 | * @return int[] 116 | */ 117 | public function getTextOffset(): array 118 | { 119 | return $this->textOffset; 120 | } 121 | 122 | /** 123 | * @param int[] $textOffset 124 | */ 125 | public function setTextOffset(array $textOffset): self 126 | { 127 | $this->initialized['textOffset'] = true; 128 | $this->textOffset = $textOffset; 129 | return $this; 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /generated/Model/CreateEditResponseUsage.php: -------------------------------------------------------------------------------- 1 | setPromptTokens($promptTokens); 28 | } 29 | if ($completionTokens !== null) { 30 | $this->setCompletionTokens($completionTokens); 31 | } 32 | if ($totalTokens !== null) { 33 | $this->setTotalTokens($totalTokens); 34 | } 35 | } 36 | 37 | public function isInitialized($property): bool 38 | { 39 | return array_key_exists($property, $this->initialized); 40 | } 41 | 42 | public function getPromptTokens(): int 43 | { 44 | return $this->promptTokens; 45 | } 46 | 47 | public function setPromptTokens(int $promptTokens): self 48 | { 49 | $this->initialized['promptTokens'] = true; 50 | $this->promptTokens = $promptTokens; 51 | return $this; 52 | } 53 | 54 | public function getCompletionTokens(): int 55 | { 56 | return $this->completionTokens; 57 | } 58 | 59 | public function setCompletionTokens(int $completionTokens): self 60 | { 61 | $this->initialized['completionTokens'] = true; 62 | $this->completionTokens = $completionTokens; 63 | return $this; 64 | } 65 | 66 | public function getTotalTokens(): int 67 | { 68 | return $this->totalTokens; 69 | } 70 | 71 | public function setTotalTokens(int $totalTokens): self 72 | { 73 | $this->initialized['totalTokens'] = true; 74 | $this->totalTokens = $totalTokens; 75 | return $this; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /generated/Model/CreateEmbeddingResponse.php: -------------------------------------------------------------------------------- 1 | setObject($object); 34 | } 35 | if ($model !== null) { 36 | $this->setModel($model); 37 | } 38 | if ($data !== null) { 39 | $this->setData($data); 40 | } 41 | if ($usage !== null) { 42 | $this->setUsage($usage); 43 | } 44 | } 45 | 46 | public function isInitialized($property): bool 47 | { 48 | return array_key_exists($property, $this->initialized); 49 | } 50 | 51 | public function getObject(): string 52 | { 53 | return $this->object; 54 | } 55 | 56 | public function setObject(string $object): self 57 | { 58 | $this->initialized['object'] = true; 59 | $this->object = $object; 60 | return $this; 61 | } 62 | 63 | public function getModel(): string 64 | { 65 | return $this->model; 66 | } 67 | 68 | public function setModel(string $model): self 69 | { 70 | $this->initialized['model'] = true; 71 | $this->model = $model; 72 | return $this; 73 | } 74 | 75 | /** 76 | * @return CreateEmbeddingResponseDataItem[] 77 | */ 78 | public function getData(): array 79 | { 80 | return $this->data; 81 | } 82 | 83 | /** 84 | * @param CreateEmbeddingResponseDataItem[] $data 85 | */ 86 | public function setData(array $data): self 87 | { 88 | $this->initialized['data'] = true; 89 | $this->data = $data; 90 | return $this; 91 | } 92 | 93 | public function getUsage(): CreateEmbeddingResponseUsage 94 | { 95 | return $this->usage; 96 | } 97 | 98 | public function setUsage(CreateEmbeddingResponseUsage $usage): self 99 | { 100 | $this->initialized['usage'] = true; 101 | $this->usage = $usage; 102 | return $this; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /generated/Model/CreateEmbeddingResponseDataItem.php: -------------------------------------------------------------------------------- 1 | setIndex($index); 31 | } 32 | if ($object !== null) { 33 | $this->setObject($object); 34 | } 35 | if ($embedding !== null) { 36 | $this->setEmbedding($embedding); 37 | } 38 | } 39 | 40 | public function isInitialized($property): bool 41 | { 42 | return array_key_exists($property, $this->initialized); 43 | } 44 | 45 | public function getIndex(): int 46 | { 47 | return $this->index; 48 | } 49 | 50 | public function setIndex(int $index): self 51 | { 52 | $this->initialized['index'] = true; 53 | $this->index = $index; 54 | return $this; 55 | } 56 | 57 | public function getObject(): string 58 | { 59 | return $this->object; 60 | } 61 | 62 | public function setObject(string $object): self 63 | { 64 | $this->initialized['object'] = true; 65 | $this->object = $object; 66 | return $this; 67 | } 68 | 69 | /** 70 | * @return float[] 71 | */ 72 | public function getEmbedding(): array 73 | { 74 | return $this->embedding; 75 | } 76 | 77 | /** 78 | * @param float[] $embedding 79 | */ 80 | public function setEmbedding(array $embedding): self 81 | { 82 | $this->initialized['embedding'] = true; 83 | $this->embedding = $embedding; 84 | return $this; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /generated/Model/CreateEmbeddingResponseUsage.php: -------------------------------------------------------------------------------- 1 | setPromptTokens($promptTokens); 25 | } 26 | if ($totalTokens !== null) { 27 | $this->setTotalTokens($totalTokens); 28 | } 29 | } 30 | 31 | public function isInitialized($property): bool 32 | { 33 | return array_key_exists($property, $this->initialized); 34 | } 35 | 36 | public function getPromptTokens(): int 37 | { 38 | return $this->promptTokens; 39 | } 40 | 41 | public function setPromptTokens(int $promptTokens): self 42 | { 43 | $this->initialized['promptTokens'] = true; 44 | $this->promptTokens = $promptTokens; 45 | return $this; 46 | } 47 | 48 | public function getTotalTokens(): int 49 | { 50 | return $this->totalTokens; 51 | } 52 | 53 | public function setTotalTokens(int $totalTokens): self 54 | { 55 | $this->initialized['totalTokens'] = true; 56 | $this->totalTokens = $totalTokens; 57 | return $this; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /generated/Model/CreateModerationResponse.php: -------------------------------------------------------------------------------- 1 | setId($id); 31 | } 32 | if ($model !== null) { 33 | $this->setModel($model); 34 | } 35 | if ($results !== null) { 36 | $this->setResults($results); 37 | } 38 | } 39 | 40 | public function isInitialized($property): bool 41 | { 42 | return array_key_exists($property, $this->initialized); 43 | } 44 | 45 | public function getId(): string 46 | { 47 | return $this->id; 48 | } 49 | 50 | public function setId(string $id): self 51 | { 52 | $this->initialized['id'] = true; 53 | $this->id = $id; 54 | return $this; 55 | } 56 | 57 | public function getModel(): string 58 | { 59 | return $this->model; 60 | } 61 | 62 | public function setModel(string $model): self 63 | { 64 | $this->initialized['model'] = true; 65 | $this->model = $model; 66 | return $this; 67 | } 68 | 69 | /** 70 | * @return CreateModerationResponseResultsItem[] 71 | */ 72 | public function getResults(): array 73 | { 74 | return $this->results; 75 | } 76 | 77 | /** 78 | * @param CreateModerationResponseResultsItem[] $results 79 | */ 80 | public function setResults(array $results): self 81 | { 82 | $this->initialized['results'] = true; 83 | $this->results = $results; 84 | return $this; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /generated/Model/CreateModerationResponseResultsItem.php: -------------------------------------------------------------------------------- 1 | setFlagged($flagged); 28 | } 29 | if ($categories !== null) { 30 | $this->setCategories($categories); 31 | } 32 | if ($categoryScores !== null) { 33 | $this->setCategoryScores($categoryScores); 34 | } 35 | } 36 | 37 | public function isInitialized($property): bool 38 | { 39 | return array_key_exists($property, $this->initialized); 40 | } 41 | 42 | public function getFlagged(): bool 43 | { 44 | return $this->flagged; 45 | } 46 | 47 | public function setFlagged(bool $flagged): self 48 | { 49 | $this->initialized['flagged'] = true; 50 | $this->flagged = $flagged; 51 | return $this; 52 | } 53 | 54 | public function getCategories(): CreateModerationResponseResultsItemCategories 55 | { 56 | return $this->categories; 57 | } 58 | 59 | public function setCategories(CreateModerationResponseResultsItemCategories $categories): self 60 | { 61 | $this->initialized['categories'] = true; 62 | $this->categories = $categories; 63 | return $this; 64 | } 65 | 66 | public function getCategoryScores(): CreateModerationResponseResultsItemCategoryScores 67 | { 68 | return $this->categoryScores; 69 | } 70 | 71 | public function setCategoryScores(CreateModerationResponseResultsItemCategoryScores $categoryScores): self 72 | { 73 | $this->initialized['categoryScores'] = true; 74 | $this->categoryScores = $categoryScores; 75 | return $this; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /generated/Model/CreateSearchResponse.php: -------------------------------------------------------------------------------- 1 | setObject($object); 31 | } 32 | if ($model !== null) { 33 | $this->setModel($model); 34 | } 35 | if ($data !== null) { 36 | $this->setData($data); 37 | } 38 | } 39 | 40 | public function isInitialized($property): bool 41 | { 42 | return array_key_exists($property, $this->initialized); 43 | } 44 | 45 | public function getObject(): string 46 | { 47 | return $this->object; 48 | } 49 | 50 | public function setObject(string $object): self 51 | { 52 | $this->initialized['object'] = true; 53 | $this->object = $object; 54 | return $this; 55 | } 56 | 57 | public function getModel(): string 58 | { 59 | return $this->model; 60 | } 61 | 62 | public function setModel(string $model): self 63 | { 64 | $this->initialized['model'] = true; 65 | $this->model = $model; 66 | return $this; 67 | } 68 | 69 | /** 70 | * @return CreateSearchResponseDataItem[] 71 | */ 72 | public function getData(): array 73 | { 74 | return $this->data; 75 | } 76 | 77 | /** 78 | * @param CreateSearchResponseDataItem[] $data 79 | */ 80 | public function setData(array $data): self 81 | { 82 | $this->initialized['data'] = true; 83 | $this->data = $data; 84 | return $this; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /generated/Model/CreateSearchResponseDataItem.php: -------------------------------------------------------------------------------- 1 | setObject($object); 28 | } 29 | if ($document !== null) { 30 | $this->setDocument($document); 31 | } 32 | if ($score !== null) { 33 | $this->setScore($score); 34 | } 35 | } 36 | 37 | public function isInitialized($property): bool 38 | { 39 | return array_key_exists($property, $this->initialized); 40 | } 41 | 42 | public function getObject(): string 43 | { 44 | return $this->object; 45 | } 46 | 47 | public function setObject(string $object): self 48 | { 49 | $this->initialized['object'] = true; 50 | $this->object = $object; 51 | return $this; 52 | } 53 | 54 | public function getDocument(): int 55 | { 56 | return $this->document; 57 | } 58 | 59 | public function setDocument(int $document): self 60 | { 61 | $this->initialized['document'] = true; 62 | $this->document = $document; 63 | return $this; 64 | } 65 | 66 | public function getScore(): float 67 | { 68 | return $this->score; 69 | } 70 | 71 | public function setScore(float $score): self 72 | { 73 | $this->initialized['score'] = true; 74 | $this->score = $score; 75 | return $this; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /generated/Model/CreateTranscriptionResponse.php: -------------------------------------------------------------------------------- 1 | setText($text); 22 | } 23 | } 24 | 25 | public function isInitialized($property): bool 26 | { 27 | return array_key_exists($property, $this->initialized); 28 | } 29 | 30 | public function getText(): string 31 | { 32 | return $this->text; 33 | } 34 | 35 | public function setText(string $text): self 36 | { 37 | $this->initialized['text'] = true; 38 | $this->text = $text; 39 | return $this; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /generated/Model/CreateTranslationResponse.php: -------------------------------------------------------------------------------- 1 | setText($text); 22 | } 23 | } 24 | 25 | public function isInitialized($property): bool 26 | { 27 | return array_key_exists($property, $this->initialized); 28 | } 29 | 30 | public function getText(): string 31 | { 32 | return $this->text; 33 | } 34 | 35 | public function setText(string $text): self 36 | { 37 | $this->initialized['text'] = true; 38 | $this->text = $text; 39 | return $this; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /generated/Model/DeleteFileResponse.php: -------------------------------------------------------------------------------- 1 | setId($id); 28 | } 29 | if ($object !== null) { 30 | $this->setObject($object); 31 | } 32 | if ($deleted !== null) { 33 | $this->setDeleted($deleted); 34 | } 35 | } 36 | 37 | public function isInitialized($property): bool 38 | { 39 | return array_key_exists($property, $this->initialized); 40 | } 41 | 42 | public function getId(): string 43 | { 44 | return $this->id; 45 | } 46 | 47 | public function setId(string $id): self 48 | { 49 | $this->initialized['id'] = true; 50 | $this->id = $id; 51 | return $this; 52 | } 53 | 54 | public function getObject(): string 55 | { 56 | return $this->object; 57 | } 58 | 59 | public function setObject(string $object): self 60 | { 61 | $this->initialized['object'] = true; 62 | $this->object = $object; 63 | return $this; 64 | } 65 | 66 | public function getDeleted(): bool 67 | { 68 | return $this->deleted; 69 | } 70 | 71 | public function setDeleted(bool $deleted): self 72 | { 73 | $this->initialized['deleted'] = true; 74 | $this->deleted = $deleted; 75 | return $this; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /generated/Model/DeleteModelResponse.php: -------------------------------------------------------------------------------- 1 | setId($id); 28 | } 29 | if ($object !== null) { 30 | $this->setObject($object); 31 | } 32 | if ($deleted !== null) { 33 | $this->setDeleted($deleted); 34 | } 35 | } 36 | 37 | public function isInitialized($property): bool 38 | { 39 | return array_key_exists($property, $this->initialized); 40 | } 41 | 42 | public function getId(): string 43 | { 44 | return $this->id; 45 | } 46 | 47 | public function setId(string $id): self 48 | { 49 | $this->initialized['id'] = true; 50 | $this->id = $id; 51 | return $this; 52 | } 53 | 54 | public function getObject(): string 55 | { 56 | return $this->object; 57 | } 58 | 59 | public function setObject(string $object): self 60 | { 61 | $this->initialized['object'] = true; 62 | $this->object = $object; 63 | return $this; 64 | } 65 | 66 | public function getDeleted(): bool 67 | { 68 | return $this->deleted; 69 | } 70 | 71 | public function setDeleted(bool $deleted): self 72 | { 73 | $this->initialized['deleted'] = true; 74 | $this->deleted = $deleted; 75 | return $this; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /generated/Model/Engine.php: -------------------------------------------------------------------------------- 1 | setId($id); 31 | } 32 | if ($object !== null) { 33 | $this->setObject($object); 34 | } 35 | if ($created !== null) { 36 | $this->setCreated($created); 37 | } 38 | if ($ready !== null) { 39 | $this->setReady($ready); 40 | } 41 | } 42 | 43 | public function isInitialized($property): bool 44 | { 45 | return array_key_exists($property, $this->initialized); 46 | } 47 | 48 | public function getId(): string 49 | { 50 | return $this->id; 51 | } 52 | 53 | public function setId(string $id): self 54 | { 55 | $this->initialized['id'] = true; 56 | $this->id = $id; 57 | return $this; 58 | } 59 | 60 | public function getObject(): string 61 | { 62 | return $this->object; 63 | } 64 | 65 | public function setObject(string $object): self 66 | { 67 | $this->initialized['object'] = true; 68 | $this->object = $object; 69 | return $this; 70 | } 71 | 72 | public function getCreated(): ?int 73 | { 74 | return $this->created; 75 | } 76 | 77 | public function setCreated(?int $created): self 78 | { 79 | $this->initialized['created'] = true; 80 | $this->created = $created; 81 | return $this; 82 | } 83 | 84 | public function getReady(): bool 85 | { 86 | return $this->ready; 87 | } 88 | 89 | public function setReady(bool $ready): self 90 | { 91 | $this->initialized['ready'] = true; 92 | $this->ready = $ready; 93 | return $this; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /generated/Model/Error.php: -------------------------------------------------------------------------------- 1 | setType($type); 31 | } 32 | if ($message !== null) { 33 | $this->setMessage($message); 34 | } 35 | if ($param !== null) { 36 | $this->setParam($param); 37 | } 38 | if ($code !== null) { 39 | $this->setCode($code); 40 | } 41 | } 42 | 43 | public function isInitialized($property): bool 44 | { 45 | return array_key_exists($property, $this->initialized); 46 | } 47 | 48 | public function getType(): string 49 | { 50 | return $this->type; 51 | } 52 | 53 | public function setType(string $type): self 54 | { 55 | $this->initialized['type'] = true; 56 | $this->type = $type; 57 | return $this; 58 | } 59 | 60 | public function getMessage(): string 61 | { 62 | return $this->message; 63 | } 64 | 65 | public function setMessage(string $message): self 66 | { 67 | $this->initialized['message'] = true; 68 | $this->message = $message; 69 | return $this; 70 | } 71 | 72 | public function getParam(): ?string 73 | { 74 | return $this->param; 75 | } 76 | 77 | public function setParam(?string $param): self 78 | { 79 | $this->initialized['param'] = true; 80 | $this->param = $param; 81 | return $this; 82 | } 83 | 84 | public function getCode(): ?string 85 | { 86 | return $this->code; 87 | } 88 | 89 | public function setCode(?string $code): self 90 | { 91 | $this->initialized['code'] = true; 92 | $this->code = $code; 93 | return $this; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /generated/Model/ErrorResponse.php: -------------------------------------------------------------------------------- 1 | setError($error); 22 | } 23 | } 24 | 25 | public function isInitialized($property): bool 26 | { 27 | return array_key_exists($property, $this->initialized); 28 | } 29 | 30 | public function getError(): Error 31 | { 32 | return $this->error; 33 | } 34 | 35 | public function setError(Error $error): self 36 | { 37 | $this->initialized['error'] = true; 38 | $this->error = $error; 39 | return $this; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /generated/Model/FineTuneEvent.php: -------------------------------------------------------------------------------- 1 | setObject($object); 31 | } 32 | if ($createdAt !== null) { 33 | $this->setCreatedAt($createdAt); 34 | } 35 | if ($level !== null) { 36 | $this->setLevel($level); 37 | } 38 | if ($message !== null) { 39 | $this->setMessage($message); 40 | } 41 | } 42 | 43 | public function isInitialized($property): bool 44 | { 45 | return array_key_exists($property, $this->initialized); 46 | } 47 | 48 | public function getObject(): string 49 | { 50 | return $this->object; 51 | } 52 | 53 | public function setObject(string $object): self 54 | { 55 | $this->initialized['object'] = true; 56 | $this->object = $object; 57 | return $this; 58 | } 59 | 60 | public function getCreatedAt(): int 61 | { 62 | return $this->createdAt; 63 | } 64 | 65 | public function setCreatedAt(int $createdAt): self 66 | { 67 | $this->initialized['createdAt'] = true; 68 | $this->createdAt = $createdAt; 69 | return $this; 70 | } 71 | 72 | public function getLevel(): string 73 | { 74 | return $this->level; 75 | } 76 | 77 | public function setLevel(string $level): self 78 | { 79 | $this->initialized['level'] = true; 80 | $this->level = $level; 81 | return $this; 82 | } 83 | 84 | public function getMessage(): string 85 | { 86 | return $this->message; 87 | } 88 | 89 | public function setMessage(string $message): self 90 | { 91 | $this->initialized['message'] = true; 92 | $this->message = $message; 93 | return $this; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /generated/Model/ImagesResponse.php: -------------------------------------------------------------------------------- 1 | setCreated($created); 28 | } 29 | if ($data !== null) { 30 | $this->setData($data); 31 | } 32 | } 33 | 34 | public function isInitialized($property): bool 35 | { 36 | return array_key_exists($property, $this->initialized); 37 | } 38 | 39 | public function getCreated(): int 40 | { 41 | return $this->created; 42 | } 43 | 44 | public function setCreated(int $created): self 45 | { 46 | $this->initialized['created'] = true; 47 | $this->created = $created; 48 | return $this; 49 | } 50 | 51 | /** 52 | * @return ImagesResponseDataItem[] 53 | */ 54 | public function getData(): array 55 | { 56 | return $this->data; 57 | } 58 | 59 | /** 60 | * @param ImagesResponseDataItem[] $data 61 | */ 62 | public function setData(array $data): self 63 | { 64 | $this->initialized['data'] = true; 65 | $this->data = $data; 66 | return $this; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /generated/Model/ImagesResponseDataItem.php: -------------------------------------------------------------------------------- 1 | setUrl($url); 25 | } 26 | if ($b64Json !== null) { 27 | $this->setB64Json($b64Json); 28 | } 29 | } 30 | 31 | public function isInitialized($property): bool 32 | { 33 | return array_key_exists($property, $this->initialized); 34 | } 35 | 36 | public function getUrl(): string 37 | { 38 | return $this->url; 39 | } 40 | 41 | public function setUrl(string $url): self 42 | { 43 | $this->initialized['url'] = true; 44 | $this->url = $url; 45 | return $this; 46 | } 47 | 48 | public function getB64Json(): string 49 | { 50 | return $this->b64Json; 51 | } 52 | 53 | public function setB64Json(string $b64Json): self 54 | { 55 | $this->initialized['b64Json'] = true; 56 | $this->b64Json = $b64Json; 57 | return $this; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /generated/Model/ListEnginesResponse.php: -------------------------------------------------------------------------------- 1 | setObject($object); 28 | } 29 | if ($data !== null) { 30 | $this->setData($data); 31 | } 32 | } 33 | 34 | public function isInitialized($property): bool 35 | { 36 | return array_key_exists($property, $this->initialized); 37 | } 38 | 39 | public function getObject(): string 40 | { 41 | return $this->object; 42 | } 43 | 44 | public function setObject(string $object): self 45 | { 46 | $this->initialized['object'] = true; 47 | $this->object = $object; 48 | return $this; 49 | } 50 | 51 | /** 52 | * @return Engine[] 53 | */ 54 | public function getData(): array 55 | { 56 | return $this->data; 57 | } 58 | 59 | /** 60 | * @param Engine[] $data 61 | */ 62 | public function setData(array $data): self 63 | { 64 | $this->initialized['data'] = true; 65 | $this->data = $data; 66 | return $this; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /generated/Model/ListFilesResponse.php: -------------------------------------------------------------------------------- 1 | setObject($object); 28 | } 29 | if ($data !== null) { 30 | $this->setData($data); 31 | } 32 | } 33 | 34 | public function isInitialized($property): bool 35 | { 36 | return array_key_exists($property, $this->initialized); 37 | } 38 | 39 | public function getObject(): string 40 | { 41 | return $this->object; 42 | } 43 | 44 | public function setObject(string $object): self 45 | { 46 | $this->initialized['object'] = true; 47 | $this->object = $object; 48 | return $this; 49 | } 50 | 51 | /** 52 | * @return OpenAIFile[] 53 | */ 54 | public function getData(): array 55 | { 56 | return $this->data; 57 | } 58 | 59 | /** 60 | * @param OpenAIFile[] $data 61 | */ 62 | public function setData(array $data): self 63 | { 64 | $this->initialized['data'] = true; 65 | $this->data = $data; 66 | return $this; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /generated/Model/ListFineTuneEventsResponse.php: -------------------------------------------------------------------------------- 1 | setObject($object); 28 | } 29 | if ($data !== null) { 30 | $this->setData($data); 31 | } 32 | } 33 | 34 | public function isInitialized($property): bool 35 | { 36 | return array_key_exists($property, $this->initialized); 37 | } 38 | 39 | public function getObject(): string 40 | { 41 | return $this->object; 42 | } 43 | 44 | public function setObject(string $object): self 45 | { 46 | $this->initialized['object'] = true; 47 | $this->object = $object; 48 | return $this; 49 | } 50 | 51 | /** 52 | * @return FineTuneEvent[] 53 | */ 54 | public function getData(): array 55 | { 56 | return $this->data; 57 | } 58 | 59 | /** 60 | * @param FineTuneEvent[] $data 61 | */ 62 | public function setData(array $data): self 63 | { 64 | $this->initialized['data'] = true; 65 | $this->data = $data; 66 | return $this; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /generated/Model/ListFineTunesResponse.php: -------------------------------------------------------------------------------- 1 | setObject($object); 28 | } 29 | if ($data !== null) { 30 | $this->setData($data); 31 | } 32 | } 33 | 34 | public function isInitialized($property): bool 35 | { 36 | return array_key_exists($property, $this->initialized); 37 | } 38 | 39 | public function getObject(): string 40 | { 41 | return $this->object; 42 | } 43 | 44 | public function setObject(string $object): self 45 | { 46 | $this->initialized['object'] = true; 47 | $this->object = $object; 48 | return $this; 49 | } 50 | 51 | /** 52 | * @return FineTune[] 53 | */ 54 | public function getData(): array 55 | { 56 | return $this->data; 57 | } 58 | 59 | /** 60 | * @param FineTune[] $data 61 | */ 62 | public function setData(array $data): self 63 | { 64 | $this->initialized['data'] = true; 65 | $this->data = $data; 66 | return $this; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /generated/Model/ListModelsResponse.php: -------------------------------------------------------------------------------- 1 | setObject($object); 28 | } 29 | if ($data !== null) { 30 | $this->setData($data); 31 | } 32 | } 33 | 34 | public function isInitialized($property): bool 35 | { 36 | return array_key_exists($property, $this->initialized); 37 | } 38 | 39 | public function getObject(): string 40 | { 41 | return $this->object; 42 | } 43 | 44 | public function setObject(string $object): self 45 | { 46 | $this->initialized['object'] = true; 47 | $this->object = $object; 48 | return $this; 49 | } 50 | 51 | /** 52 | * @return Model[] 53 | */ 54 | public function getData(): array 55 | { 56 | return $this->data; 57 | } 58 | 59 | /** 60 | * @param Model[] $data 61 | */ 62 | public function setData(array $data): self 63 | { 64 | $this->initialized['data'] = true; 65 | $this->data = $data; 66 | return $this; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /generated/Model/Model.php: -------------------------------------------------------------------------------- 1 | setId($id); 31 | } 32 | if ($object !== null) { 33 | $this->setObject($object); 34 | } 35 | if ($created !== null) { 36 | $this->setCreated($created); 37 | } 38 | if ($ownedBy !== null) { 39 | $this->setOwnedBy($ownedBy); 40 | } 41 | } 42 | 43 | public function isInitialized($property): bool 44 | { 45 | return array_key_exists($property, $this->initialized); 46 | } 47 | 48 | public function getId(): string 49 | { 50 | return $this->id; 51 | } 52 | 53 | public function setId(string $id): self 54 | { 55 | $this->initialized['id'] = true; 56 | $this->id = $id; 57 | return $this; 58 | } 59 | 60 | public function getObject(): string 61 | { 62 | return $this->object; 63 | } 64 | 65 | public function setObject(string $object): self 66 | { 67 | $this->initialized['object'] = true; 68 | $this->object = $object; 69 | return $this; 70 | } 71 | 72 | public function getCreated(): int 73 | { 74 | return $this->created; 75 | } 76 | 77 | public function setCreated(int $created): self 78 | { 79 | $this->initialized['created'] = true; 80 | $this->created = $created; 81 | return $this; 82 | } 83 | 84 | public function getOwnedBy(): string 85 | { 86 | return $this->ownedBy; 87 | } 88 | 89 | public function setOwnedBy(string $ownedBy): self 90 | { 91 | $this->initialized['ownedBy'] = true; 92 | $this->ownedBy = $ownedBy; 93 | return $this; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /generated/Normalizer/ChatCompletionRequestMessageFunctionCallNormalizer.php: -------------------------------------------------------------------------------- 1 | setName($data['name']); 53 | unset($data['name']); 54 | } 55 | if (\array_key_exists('arguments', $data)) { 56 | $object->setArguments($data['arguments']); 57 | unset($data['arguments']); 58 | } 59 | foreach ($data as $key => $value) { 60 | if (preg_match('/.*/', (string) $key)) { 61 | $object[$key] = $value; 62 | } 63 | } 64 | return $object; 65 | } 66 | 67 | /** 68 | * @return array|string|int|float|bool|ArrayObject|null 69 | */ 70 | public function normalize($object, $format = null, array $context = []) 71 | { 72 | $data = []; 73 | if ($object->isInitialized('name') && $object->getName() !== null) { 74 | $data['name'] = $object->getName(); 75 | } 76 | if ($object->isInitialized('arguments') && $object->getArguments() !== null) { 77 | $data['arguments'] = $object->getArguments(); 78 | } 79 | foreach ($object as $key => $value) { 80 | if (preg_match('/.*/', (string) $key)) { 81 | $data[$key] = $value; 82 | } 83 | } 84 | return $data; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /generated/Normalizer/ChatCompletionResponseMessageFunctionCallNormalizer.php: -------------------------------------------------------------------------------- 1 | setName($data['name']); 53 | unset($data['name']); 54 | } 55 | if (\array_key_exists('arguments', $data)) { 56 | $object->setArguments($data['arguments']); 57 | unset($data['arguments']); 58 | } 59 | foreach ($data as $key => $value) { 60 | if (preg_match('/.*/', (string) $key)) { 61 | $object[$key] = $value; 62 | } 63 | } 64 | return $object; 65 | } 66 | 67 | /** 68 | * @return array|string|int|float|bool|ArrayObject|null 69 | */ 70 | public function normalize($object, $format = null, array $context = []) 71 | { 72 | $data = []; 73 | if ($object->isInitialized('name') && $object->getName() !== null) { 74 | $data['name'] = $object->getName(); 75 | } 76 | if ($object->isInitialized('arguments') && $object->getArguments() !== null) { 77 | $data['arguments'] = $object->getArguments(); 78 | } 79 | foreach ($object as $key => $value) { 80 | if (preg_match('/.*/', (string) $key)) { 81 | $data[$key] = $value; 82 | } 83 | } 84 | return $data; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /generated/Normalizer/CreateAnswerResponseSelectedDocumentsItemNormalizer.php: -------------------------------------------------------------------------------- 1 | setDocument($data['document']); 53 | unset($data['document']); 54 | } 55 | if (\array_key_exists('text', $data)) { 56 | $object->setText($data['text']); 57 | unset($data['text']); 58 | } 59 | foreach ($data as $key => $value) { 60 | if (preg_match('/.*/', (string) $key)) { 61 | $object[$key] = $value; 62 | } 63 | } 64 | return $object; 65 | } 66 | 67 | /** 68 | * @return array|string|int|float|bool|ArrayObject|null 69 | */ 70 | public function normalize($object, $format = null, array $context = []) 71 | { 72 | $data = []; 73 | if ($object->isInitialized('document') && $object->getDocument() !== null) { 74 | $data['document'] = $object->getDocument(); 75 | } 76 | if ($object->isInitialized('text') && $object->getText() !== null) { 77 | $data['text'] = $object->getText(); 78 | } 79 | foreach ($object as $key => $value) { 80 | if (preg_match('/.*/', (string) $key)) { 81 | $data[$key] = $value; 82 | } 83 | } 84 | return $data; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /generated/Normalizer/CreateEmbeddingRequestNormalizer.php: -------------------------------------------------------------------------------- 1 | setModel($data['model']); 52 | } 53 | if (\array_key_exists('input', $data)) { 54 | $object->setInput($data['input']); 55 | } 56 | if (\array_key_exists('user', $data)) { 57 | $object->setUser($data['user']); 58 | } 59 | return $object; 60 | } 61 | 62 | /** 63 | * @return array{model: mixed, input: mixed, user?: mixed} 64 | */ 65 | public function normalize($object, $format = null, array $context = []) 66 | { 67 | $data = []; 68 | $data['model'] = $object->getModel(); 69 | $data['input'] = $object->getInput(); 70 | if ($object->isInitialized('user') && $object->getUser() !== null) { 71 | $data['user'] = $object->getUser(); 72 | } 73 | return $data; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /generated/Normalizer/CreateEmbeddingResponseUsageNormalizer.php: -------------------------------------------------------------------------------- 1 | setPromptTokens($data['prompt_tokens']); 53 | unset($data['prompt_tokens']); 54 | } 55 | if (\array_key_exists('total_tokens', $data)) { 56 | $object->setTotalTokens($data['total_tokens']); 57 | unset($data['total_tokens']); 58 | } 59 | foreach ($data as $key => $value) { 60 | if (preg_match('/.*/', (string) $key)) { 61 | $object[$key] = $value; 62 | } 63 | } 64 | return $object; 65 | } 66 | 67 | /** 68 | * @return array|string|int|float|bool|ArrayObject|null 69 | */ 70 | public function normalize($object, $format = null, array $context = []) 71 | { 72 | $data = []; 73 | $data['prompt_tokens'] = $object->getPromptTokens(); 74 | $data['total_tokens'] = $object->getTotalTokens(); 75 | foreach ($object as $key => $value) { 76 | if (preg_match('/.*/', (string) $key)) { 77 | $data[$key] = $value; 78 | } 79 | } 80 | return $data; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /generated/Normalizer/CreateFileRequestNormalizer.php: -------------------------------------------------------------------------------- 1 | setFile($data['file']); 52 | } 53 | if (\array_key_exists('purpose', $data)) { 54 | $object->setPurpose($data['purpose']); 55 | } 56 | return $object; 57 | } 58 | 59 | /** 60 | * @return array{file: mixed, purpose: mixed} 61 | */ 62 | public function normalize($object, $format = null, array $context = []) 63 | { 64 | $data = []; 65 | $data['file'] = $object->getFile(); 66 | $data['purpose'] = $object->getPurpose(); 67 | return $data; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /generated/Normalizer/CreateModerationRequestNormalizer.php: -------------------------------------------------------------------------------- 1 | setInput($data['input']); 53 | unset($data['input']); 54 | } 55 | if (\array_key_exists('model', $data)) { 56 | $object->setModel($data['model']); 57 | unset($data['model']); 58 | } 59 | foreach ($data as $key => $value) { 60 | if (preg_match('/.*/', (string) $key)) { 61 | $object[$key] = $value; 62 | } 63 | } 64 | return $object; 65 | } 66 | 67 | /** 68 | * @return array|string|int|float|bool|ArrayObject|null 69 | */ 70 | public function normalize($object, $format = null, array $context = []) 71 | { 72 | $data = []; 73 | $data['input'] = $object->getInput(); 74 | if ($object->isInitialized('model') && $object->getModel() !== null) { 75 | $data['model'] = $object->getModel(); 76 | } 77 | foreach ($object as $key => $value) { 78 | if (preg_match('/.*/', (string) $key)) { 79 | $data[$key] = $value; 80 | } 81 | } 82 | return $data; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /generated/Normalizer/CreateTranscriptionResponseNormalizer.php: -------------------------------------------------------------------------------- 1 | setText($data['text']); 53 | unset($data['text']); 54 | } 55 | foreach ($data as $key => $value) { 56 | if (preg_match('/.*/', (string) $key)) { 57 | $object[$key] = $value; 58 | } 59 | } 60 | return $object; 61 | } 62 | 63 | /** 64 | * @return array|string|int|float|bool|ArrayObject|null 65 | */ 66 | public function normalize($object, $format = null, array $context = []) 67 | { 68 | $data = []; 69 | $data['text'] = $object->getText(); 70 | foreach ($object as $key => $value) { 71 | if (preg_match('/.*/', (string) $key)) { 72 | $data[$key] = $value; 73 | } 74 | } 75 | return $data; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /generated/Normalizer/CreateTranslationResponseNormalizer.php: -------------------------------------------------------------------------------- 1 | setText($data['text']); 53 | unset($data['text']); 54 | } 55 | foreach ($data as $key => $value) { 56 | if (preg_match('/.*/', (string) $key)) { 57 | $object[$key] = $value; 58 | } 59 | } 60 | return $object; 61 | } 62 | 63 | /** 64 | * @return array|string|int|float|bool|ArrayObject|null 65 | */ 66 | public function normalize($object, $format = null, array $context = []) 67 | { 68 | $data = []; 69 | $data['text'] = $object->getText(); 70 | foreach ($object as $key => $value) { 71 | if (preg_match('/.*/', (string) $key)) { 72 | $data[$key] = $value; 73 | } 74 | } 75 | return $data; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /generated/Normalizer/DeleteFileResponseNormalizer.php: -------------------------------------------------------------------------------- 1 | setId($data['id']); 53 | unset($data['id']); 54 | } 55 | if (\array_key_exists('object', $data)) { 56 | $object->setObject($data['object']); 57 | unset($data['object']); 58 | } 59 | if (\array_key_exists('deleted', $data)) { 60 | $object->setDeleted($data['deleted']); 61 | unset($data['deleted']); 62 | } 63 | foreach ($data as $key => $value) { 64 | if (preg_match('/.*/', (string) $key)) { 65 | $object[$key] = $value; 66 | } 67 | } 68 | return $object; 69 | } 70 | 71 | /** 72 | * @return array|string|int|float|bool|ArrayObject|null 73 | */ 74 | public function normalize($object, $format = null, array $context = []) 75 | { 76 | $data = []; 77 | $data['id'] = $object->getId(); 78 | $data['object'] = $object->getObject(); 79 | $data['deleted'] = $object->getDeleted(); 80 | foreach ($object as $key => $value) { 81 | if (preg_match('/.*/', (string) $key)) { 82 | $data[$key] = $value; 83 | } 84 | } 85 | return $data; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /generated/Normalizer/DeleteModelResponseNormalizer.php: -------------------------------------------------------------------------------- 1 | setId($data['id']); 53 | unset($data['id']); 54 | } 55 | if (\array_key_exists('object', $data)) { 56 | $object->setObject($data['object']); 57 | unset($data['object']); 58 | } 59 | if (\array_key_exists('deleted', $data)) { 60 | $object->setDeleted($data['deleted']); 61 | unset($data['deleted']); 62 | } 63 | foreach ($data as $key => $value) { 64 | if (preg_match('/.*/', (string) $key)) { 65 | $object[$key] = $value; 66 | } 67 | } 68 | return $object; 69 | } 70 | 71 | /** 72 | * @return array|string|int|float|bool|ArrayObject|null 73 | */ 74 | public function normalize($object, $format = null, array $context = []) 75 | { 76 | $data = []; 77 | $data['id'] = $object->getId(); 78 | $data['object'] = $object->getObject(); 79 | $data['deleted'] = $object->getDeleted(); 80 | foreach ($object as $key => $value) { 81 | if (preg_match('/.*/', (string) $key)) { 82 | $data[$key] = $value; 83 | } 84 | } 85 | return $data; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /generated/Normalizer/ErrorResponseNormalizer.php: -------------------------------------------------------------------------------- 1 | setError($this->denormalizer->denormalize($data['error'], Error::class, 'json', $context)); 54 | unset($data['error']); 55 | } 56 | foreach ($data as $key => $value) { 57 | if (preg_match('/.*/', (string) $key)) { 58 | $object[$key] = $value; 59 | } 60 | } 61 | return $object; 62 | } 63 | 64 | /** 65 | * @return array|string|int|float|bool|ArrayObject|null 66 | */ 67 | public function normalize($object, $format = null, array $context = []) 68 | { 69 | $data = []; 70 | $data['error'] = $this->normalizer->normalize($object->getError(), 'json', $context); 71 | foreach ($object as $key => $value) { 72 | if (preg_match('/.*/', (string) $key)) { 73 | $data[$key] = $value; 74 | } 75 | } 76 | return $data; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /generated/Normalizer/ImagesResponseDataItemNormalizer.php: -------------------------------------------------------------------------------- 1 | setUrl($data['url']); 53 | unset($data['url']); 54 | } 55 | if (\array_key_exists('b64_json', $data)) { 56 | $object->setB64Json($data['b64_json']); 57 | unset($data['b64_json']); 58 | } 59 | foreach ($data as $key => $value) { 60 | if (preg_match('/.*/', (string) $key)) { 61 | $object[$key] = $value; 62 | } 63 | } 64 | return $object; 65 | } 66 | 67 | /** 68 | * @return array|string|int|float|bool|ArrayObject|null 69 | */ 70 | public function normalize($object, $format = null, array $context = []) 71 | { 72 | $data = []; 73 | if ($object->isInitialized('url') && $object->getUrl() !== null) { 74 | $data['url'] = $object->getUrl(); 75 | } 76 | if ($object->isInitialized('b64Json') && $object->getB64Json() !== null) { 77 | $data['b64_json'] = $object->getB64Json(); 78 | } 79 | foreach ($object as $key => $value) { 80 | if (preg_match('/.*/', (string) $key)) { 81 | $data[$key] = $value; 82 | } 83 | } 84 | return $data; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /generated/Normalizer/ModelNormalizer.php: -------------------------------------------------------------------------------- 1 | setId($data['id']); 53 | unset($data['id']); 54 | } 55 | if (\array_key_exists('object', $data)) { 56 | $object->setObject($data['object']); 57 | unset($data['object']); 58 | } 59 | if (\array_key_exists('created', $data)) { 60 | $object->setCreated($data['created']); 61 | unset($data['created']); 62 | } 63 | if (\array_key_exists('owned_by', $data)) { 64 | $object->setOwnedBy($data['owned_by']); 65 | unset($data['owned_by']); 66 | } 67 | foreach ($data as $key => $value) { 68 | if (preg_match('/.*/', (string) $key)) { 69 | $object[$key] = $value; 70 | } 71 | } 72 | return $object; 73 | } 74 | 75 | /** 76 | * @return array|string|int|float|bool|ArrayObject|null 77 | */ 78 | public function normalize($object, $format = null, array $context = []) 79 | { 80 | $data = []; 81 | $data['id'] = $object->getId(); 82 | $data['object'] = $object->getObject(); 83 | $data['created'] = $object->getCreated(); 84 | $data['owned_by'] = $object->getOwnedBy(); 85 | foreach ($object as $key => $value) { 86 | if (preg_match('/.*/', (string) $key)) { 87 | $data[$key] = $value; 88 | } 89 | } 90 | return $data; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /generated/Runtime/Client/BaseEndpoint.php: -------------------------------------------------------------------------------- 1 | getQueryOptionsResolver()->resolve($this->queryParameters); 31 | $optionsResolved = array_map(fn ($value) => $value ?? '', $optionsResolved); 32 | return http_build_query($optionsResolved, '', '&', PHP_QUERY_RFC3986); 33 | } 34 | 35 | public function getHeaders(array $baseHeaders = []): array 36 | { 37 | return array_merge($this->getExtraHeaders(), $baseHeaders, $this->getHeadersOptionsResolver()->resolve($this->headerParameters)); 38 | } 39 | 40 | abstract protected function transformResponseBody(ResponseInterface $response, SerializerInterface $serializer, ?string $contentType = null); 41 | 42 | protected function getExtraHeaders(): array 43 | { 44 | return []; 45 | } 46 | 47 | protected function getQueryOptionsResolver(): OptionsResolver 48 | { 49 | return new OptionsResolver(); 50 | } 51 | 52 | protected function getHeadersOptionsResolver(): OptionsResolver 53 | { 54 | return new OptionsResolver(); 55 | } 56 | 57 | // ---------------------------------------------------------------------------------------------------- 58 | // Used for OpenApi2 compatibility 59 | protected function getFormBody(): array 60 | { 61 | return [[ 62 | 'Content-Type' => ['application/x-www-form-urlencoded'], 63 | ], http_build_query($this->getFormOptionsResolver()->resolve($this->formParameters))]; 64 | } 65 | 66 | protected function getMultipartBody($streamFactory = null): array 67 | { 68 | $bodyBuilder = new MultipartStreamBuilder($streamFactory); 69 | $formParameters = $this->getFormOptionsResolver()->resolve($this->formParameters); 70 | foreach ($formParameters as $key => $value) { 71 | $bodyBuilder->addResource($key, $value); 72 | } 73 | return [[ 74 | 'Content-Type' => ['multipart/form-data; boundary="' . ($bodyBuilder->getBoundary() . '"')], 75 | ], $bodyBuilder->build()]; 76 | } 77 | 78 | protected function getFormOptionsResolver(): OptionsResolver 79 | { 80 | return new OptionsResolver(); 81 | } 82 | 83 | protected function getSerializedBody(SerializerInterface $serializer): array 84 | { 85 | return [[ 86 | 'Content-Type' => ['application/json'], 87 | ], $serializer->serialize($this->body, 'json')]; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /generated/Runtime/Client/Client.php: -------------------------------------------------------------------------------- 1 | executeRawEndpoint($endpoint); 34 | } 35 | return $endpoint->parseResponse($this->processEndpoint($endpoint), $this->serializer, $fetch); 36 | } 37 | 38 | public function executeRawEndpoint(Endpoint $endpoint): ResponseInterface 39 | { 40 | return $this->processEndpoint($endpoint); 41 | } 42 | 43 | private function processEndpoint(Endpoint $endpoint): ResponseInterface 44 | { 45 | [$bodyHeaders, $body] = $endpoint->getBody($this->serializer, $this->streamFactory); 46 | $queryString = $endpoint->getQueryString(); 47 | $uriGlue = ! str_contains($endpoint->getUri(), '?') ? '?' : '&'; 48 | $uri = $queryString !== '' ? $endpoint->getUri() . $uriGlue . $queryString : $endpoint->getUri(); 49 | $request = $this->requestFactory->createRequest($endpoint->getMethod(), $uri); 50 | if ($body) { 51 | if ($body instanceof StreamInterface) { 52 | $request = $request->withBody($body); 53 | } elseif (is_resource($body)) { 54 | $request = $request->withBody($this->streamFactory->createStreamFromResource($body)); 55 | } elseif (strlen($body) <= 4000 && @file_exists($body)) { 56 | // more than 4096 chars will trigger an error 57 | $request = $request->withBody($this->streamFactory->createStreamFromFile($body)); 58 | } else { 59 | $request = $request->withBody($this->streamFactory->createStream($body)); 60 | } 61 | } 62 | foreach ($endpoint->getHeaders($bodyHeaders) as $name => $value) { 63 | $request = $request->withHeader($name, $value); 64 | } 65 | if (count($endpoint->getAuthenticationScopes()) > 0) { 66 | $scopes = []; 67 | foreach ($endpoint->getAuthenticationScopes() as $scope) { 68 | $scopes[] = $scope; 69 | } 70 | $request = $request->withHeader(AuthenticationRegistry::SCOPES_HEADER, $scopes); 71 | } 72 | return $this->httpClient->sendRequest($request); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /generated/Runtime/Client/CustomQueryResolver.php: -------------------------------------------------------------------------------- 1 | hasHeader('Content-Type') ? current($response->getHeader('Content-Type')) : null; 15 | return $this->transformResponseBody($response, $serializer, $contentType); 16 | } 17 | 18 | abstract protected function transformResponseBody(ResponseInterface $response, SerializerInterface $serializer, ?string $contentType = null); 19 | } 20 | -------------------------------------------------------------------------------- /generated/Runtime/Normalizer/CheckArray.php: -------------------------------------------------------------------------------- 1 | is_numeric($key), ARRAY_FILTER_USE_KEY)) === count($array); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /generated/Runtime/Normalizer/ReferenceNormalizer.php: -------------------------------------------------------------------------------- 1 | getReferenceUri(); 16 | return $ref; 17 | } 18 | 19 | public function supportsNormalization($data, $format = null): bool 20 | { 21 | return $data instanceof Reference; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /generated/Runtime/Normalizer/ValidationException.php: -------------------------------------------------------------------------------- 1 | count()), 400); 16 | } 17 | 18 | public function getViolationList(): ConstraintViolationListInterface 19 | { 20 | return $this->violationList; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /generated/Runtime/Normalizer/ValidatorTrait.php: -------------------------------------------------------------------------------- 1 | validate($data, $constraint); 16 | if ($violations->count() > 0) { 17 | throw new ValidationException($violations); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | tests 15 | 16 | 17 | 18 | 19 | 20 | src 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /rector.php: -------------------------------------------------------------------------------- 1 | importNames(true); 25 | $rectorConfig->paths([ 26 | __DIR__ . '/build', 27 | __DIR__ . '/generated', 28 | __DIR__ . '/src', 29 | ]); 30 | 31 | $rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class); 32 | $rectorConfig->rule(AddMethodCallBasedStrictParamTypeRector::class); 33 | $rectorConfig->rule(AddParamTypeFromPropertyTypeRector::class); 34 | $rectorConfig->rule(ArrayShapeFromConstantArrayReturnRector::class); 35 | $rectorConfig->rule(ParamTypeByMethodCallTypeRector::class); 36 | $rectorConfig->rule(ParamTypeFromStrictTypedPropertyRector::class); 37 | $rectorConfig->rule(PropertyTypeFromStrictSetterGetterRector::class); 38 | $rectorConfig->rule(ReturnTypeFromReturnDirectArrayRector::class); 39 | $rectorConfig->rule(ReturnTypeFromReturnNewRector::class); 40 | $rectorConfig->rule(TypedPropertyFromStrictConstructorRector::class); 41 | $rectorConfig->rule(TypedPropertyFromStrictGetterMethodReturnTypeRector::class); 42 | $rectorConfig->ruleWithConfiguration(TypedPropertyFromAssignsRector::class, [ 43 | TypedPropertyFromAssignsRector::INLINE_PUBLIC => true, 44 | ]); 45 | $rectorConfig->sets([ 46 | LevelSetList::UP_TO_PHP_80, 47 | SetList::TYPE_DECLARATION, 48 | ]); 49 | $rectorConfig->skip([ 50 | ClassPropertyAssignToConstructorPromotionRector::class => [ 51 | __DIR__ . '/generated/Model' 52 | ], 53 | ]); 54 | }; 55 | -------------------------------------------------------------------------------- /src/Pricing/ModelPricing.php: -------------------------------------------------------------------------------- 1 | prompt; 18 | } 19 | 20 | public function getCompletion(): TokenPricing 21 | { 22 | return $this->completion; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Pricing/ModelPricingRepository.php: -------------------------------------------------------------------------------- 1 | 17 | */ 18 | private const PRICING_PER_MODEL = [ 19 | 'gpt-4' => [ 20 | 'prompt' => '0.03', 21 | 'completion' => '0.06', 22 | ], 23 | 'gpt-4-32k' => [ 24 | 'prompt' => '0.06', 25 | 'completion' => '0.12', 26 | ], 27 | 'gpt-3.5-turbo' => [ 28 | 'prompt' => '0.0015', 29 | 'completion' => '0.002', 30 | ], 31 | 'gpt-3.5-turbo-16k' => [ 32 | 'prompt' => '0.003', 33 | 'completion' => '0.004', 34 | ], 35 | 'davinci' => '0.02', 36 | 'curie' => '0.002', 37 | 'babbage' => '0.0005', 38 | 'ada' => '0.0004', 39 | ]; 40 | 41 | private const TOKENS_PER_PRICE = 1000; 42 | 43 | public function getPricing(string $requestedModel): ModelPricing 44 | { 45 | $pricing = null; 46 | foreach (self::PRICING_PER_MODEL as $model => $modelPricing) { 47 | if (! str_starts_with($requestedModel, $model) 48 | && ! str_starts_with($requestedModel, 'text-' . $model) 49 | ) { 50 | continue; 51 | } 52 | 53 | $pricing = $modelPricing; 54 | } 55 | 56 | if ($pricing === null) { 57 | throw new InvalidArgumentException(sprintf('Pricing for model "%s" not found.', $requestedModel)); 58 | } 59 | 60 | if (is_array($pricing)) { 61 | $prompt = $pricing['prompt']; 62 | $completion = $pricing['completion']; 63 | } else { 64 | $prompt = $completion = $pricing; 65 | } 66 | 67 | // Make sure the price of a single token can be accurately modeled 68 | // Same as \Brick\Money\Context\AutoContext::applyTo 69 | $scale = max( 70 | BigDecimal::of($prompt) 71 | ->toBigDecimal() 72 | ->stripTrailingZeros() 73 | ->getScale(), 74 | BigDecimal::of($completion) 75 | ->toBigDecimal() 76 | ->stripTrailingZeros() 77 | ->getScale(), 78 | ) + 3; // +3 because self::TOKENS_PER_PRICE 79 | 80 | $moneyContext = new CustomContext($scale); 81 | 82 | return new ModelPricing( 83 | new TokenPricing( 84 | Money::of($prompt, 'USD', $moneyContext), 85 | self::TOKENS_PER_PRICE 86 | ), 87 | new TokenPricing( 88 | Money::of($completion, 'USD', $moneyContext), 89 | self::TOKENS_PER_PRICE 90 | ) 91 | ); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/Pricing/ResponseCost.php: -------------------------------------------------------------------------------- 1 | prompt; 20 | } 21 | 22 | public function getCompletion(): Money 23 | { 24 | return $this->completion; 25 | } 26 | 27 | public function getTotal(): Money 28 | { 29 | return $this->prompt->plus($this->completion); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Pricing/ResponseCostCalculator.php: -------------------------------------------------------------------------------- 1 | modelPricingRepository = $modelPricingRepository ?? new ModelPricingRepository(); 17 | } 18 | 19 | public function calculate(CreateCompletionResponse|CreateChatCompletionResponse $response): ResponseCost 20 | { 21 | $pricing = $this->modelPricingRepository->getPricing( 22 | $response->getModel() 23 | ); 24 | 25 | return new ResponseCost( 26 | $pricing->getPrompt()->calculatePrice( 27 | $response->getUsage()->getPromptTokens() 28 | ), 29 | $pricing->getCompletion()->calculatePrice( 30 | $response->getUsage()->getCompletionTokens() 31 | ), 32 | ); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Pricing/TokenPricing.php: -------------------------------------------------------------------------------- 1 | price->toRational() 21 | ->dividedBy($this->tokens) 22 | ->multipliedBy($tokens) 23 | ->to($this->price->getContext(), $roudingMode) 24 | ; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests/Pricing/ModelPricingRepositoryTest.php: -------------------------------------------------------------------------------- 1 | expectException(\InvalidArgumentException::class); 13 | $this->expectExceptionMessage('Pricing for model "foobar" not found.'); 14 | 15 | $repository = new ModelPricingRepository(); 16 | $repository->getPricing('foobar'); 17 | } 18 | 19 | public function test() 20 | { 21 | $repository = new ModelPricingRepository(); 22 | 23 | $chatGPTPricing = $repository->getPricing('gpt-3.5-turbo'); 24 | 25 | self::assertSame( 26 | '0.0000015', 27 | (string) $chatGPTPricing->getPrompt()->calculatePrice(1)->getAmount() 28 | ); 29 | self::assertSame( 30 | '0.0015000', 31 | (string) $chatGPTPricing->getPrompt()->calculatePrice(1000)->getAmount() 32 | ); 33 | self::assertSame( 34 | '0.0001845', 35 | (string) $chatGPTPricing->getPrompt()->calculatePrice(123)->getAmount() 36 | ); 37 | 38 | $chatGPT16kPricing = $repository->getPricing('gpt-3.5-turbo-16k'); 39 | 40 | self::assertSame( 41 | '0.000003', 42 | (string) $chatGPT16kPricing->getPrompt()->calculatePrice(1)->getAmount() 43 | ); 44 | self::assertSame( 45 | '0.003000', 46 | (string) $chatGPT16kPricing->getPrompt()->calculatePrice(1000)->getAmount() 47 | ); 48 | self::assertSame( 49 | '0.000369', 50 | (string) $chatGPT16kPricing->getPrompt()->calculatePrice(123)->getAmount() 51 | ); 52 | 53 | $adaPricing = $repository->getPricing('ada'); 54 | 55 | self::assertSame( 56 | '0.0000004', 57 | (string) $adaPricing->getPrompt()->calculatePrice(1)->getAmount() 58 | ); 59 | self::assertSame( 60 | '0.0004000', 61 | (string) $adaPricing->getPrompt()->calculatePrice(1000)->getAmount() 62 | ); 63 | self::assertSame( 64 | '0.0000492', 65 | (string) $adaPricing->getPrompt()->calculatePrice(123)->getAmount() 66 | ); 67 | } 68 | 69 | public function testAda001() 70 | { 71 | $repository = new ModelPricingRepository(); 72 | 73 | $adaPricing = $repository->getPricing('text-ada-001'); 74 | 75 | self::assertNotNull($adaPricing); 76 | } 77 | 78 | public function testDavinci003() 79 | { 80 | $repository = new ModelPricingRepository(); 81 | 82 | $daVinciPricing = $repository->getPricing('text-davinci-003'); 83 | $daVinciPricing2 = $repository->getPricing('davinci'); 84 | 85 | self::assertNotNull($daVinciPricing); 86 | self::assertNotNull($daVinciPricing2); 87 | } 88 | 89 | public function testTurbo() 90 | { 91 | $repository = new ModelPricingRepository(); 92 | 93 | self::assertNotNull($repository->getPricing('gpt-3.5-turbo')); 94 | self::assertNotNull($repository->getPricing('gpt-3.5-turbo-0301')); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /tests/Pricing/ResponseCostCalculatorTest.php: -------------------------------------------------------------------------------- 1 | setUsage(new CreateChatCompletionResponseUsage(523, 873)); 16 | $response->setModel('gpt-3.5-turbo'); 17 | 18 | $calculator = new ResponseCostCalculator(); 19 | 20 | $responseCost = $calculator->calculate($response); 21 | 22 | self::assertSame('0.0025305', (string) $responseCost->getTotal()->getAmount()); 23 | self::assertSame('0.0007845', (string) $responseCost->getPrompt()->getAmount()); 24 | self::assertSame('0.0017460', (string) $responseCost->getCompletion()->getAmount()); 25 | } 26 | 27 | public function testAda() 28 | { 29 | $response = new CreateChatCompletionResponse(); 30 | $response->setUsage(new CreateChatCompletionResponseUsage(245, 75)); 31 | $response->setModel('text-ada-001'); 32 | 33 | $calculator = new ResponseCostCalculator(); 34 | 35 | $responseCost = $calculator->calculate($response); 36 | 37 | self::assertSame('0.0001280', (string) $responseCost->getTotal()->getAmount()); 38 | self::assertSame('0.0000980', (string) $responseCost->getPrompt()->getAmount()); 39 | self::assertSame('0.0000300', (string) $responseCost->getCompletion()->getAmount()); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /tests/Pricing/TokenPricingTest.php: -------------------------------------------------------------------------------- 1 | calculatePrice(1500)->getAmount() 22 | ); 23 | self::assertSame( 24 | '0.00001', 25 | (string) $gpt35TurboPricing->calculatePrice(1)->getAmount() 26 | ); 27 | self::assertSame( 28 | '0.02169', 29 | (string) $gpt4_8kPromptPricing->calculatePrice(723)->getAmount() 30 | ); 31 | } 32 | } 33 | --------------------------------------------------------------------------------