├── .github
└── workflows
│ └── maven.yml
├── .gitignore
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── cdx-openai-codestyle.xml
├── openai-api-coverage
└── pom.xml
├── openai-api-examples
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── bg
│ │ └── codexio
│ │ └── ai
│ │ └── openai
│ │ └── api
│ │ └── examples
│ │ ├── assistant
│ │ ├── AssistantAsk.java
│ │ └── CreateAssistant.java
│ │ ├── chat
│ │ ├── ChatAskAsync.java
│ │ ├── ChatAskMultipleQuestionsWithGPT4.java
│ │ ├── ChatAskReactive.java
│ │ ├── ChatAskWithCustomHttpClientHttpContext.java
│ │ ├── ChatAskWithCustomOkHttpClientObjectMapper.java
│ │ ├── ChatAskWithEnabledLogprobabilites.java
│ │ ├── ChatAskWithTopLogprobabilites.java
│ │ ├── ChatDefinedAuthenticationMethod.java
│ │ └── ChatSimplyAsk.java
│ │ ├── file
│ │ ├── DownloadFile.java
│ │ ├── DownloadFileWithFileResult.java
│ │ └── UploadFile.java
│ │ ├── images
│ │ ├── create
│ │ │ ├── ImagesGenerateDalle2CustomSettingsAndDownloadAsync.java
│ │ │ ├── ImagesGenerateDalle3CustomSettings.java
│ │ │ ├── ImagesGenerateDalle3CustomSettingsAndDownload.java
│ │ │ └── ImagesSimplyGenerate.java
│ │ ├── edit
│ │ │ ├── ImagesEditCustomMaskFile.java
│ │ │ └── ImagesEditMaskByHexColor.java
│ │ └── variations
│ │ │ └── ImageMultipleVariationsAsync.java
│ │ ├── message
│ │ └── CreateMessage.java
│ │ ├── run
│ │ └── CreateRun.java
│ │ ├── thread
│ │ ├── CreateEmptyThread.java
│ │ └── CreateThread.java
│ │ ├── vision
│ │ ├── VisionDetailedExampleWithLimit.java
│ │ └── VisionMultipleImagesExample.java
│ │ └── voice
│ │ ├── speech
│ │ ├── SpeechConfiguredExample.java
│ │ └── SpeechSimpleExample.java
│ │ ├── transcription
│ │ ├── TranscriptionConfiguredExample.java
│ │ └── TranscriptionSimpleExample.java
│ │ └── translation
│ │ ├── TranslationConfiguredExample.java
│ │ └── TranslationSimpleExample.java
│ └── resources
│ ├── audio-de.mp3
│ ├── audio.mp3
│ ├── codi-image-to-explain.png
│ ├── editable-image-mask.png
│ ├── editable-image.png
│ ├── fake-file.txt
│ ├── image-for-variations.png
│ ├── log4j2.xml
│ └── openai-credentials.json
├── openai-api-http
├── pom.xml
└── src
│ ├── main
│ └── java
│ │ └── bg
│ │ └── codexio
│ │ └── ai
│ │ └── openai
│ │ └── api
│ │ └── http
│ │ ├── AuthenticationInterceptor.java
│ │ ├── CommonConstantsUtils.java
│ │ ├── DefaultOpenAIHttpExecutor.java
│ │ ├── HttpExecutorContext.java
│ │ ├── HttpTimeout.java
│ │ ├── HttpTimeouts.java
│ │ ├── OpenAIHttpExecutor.java
│ │ ├── assistant
│ │ └── AssistantHttpExecutor.java
│ │ ├── chat
│ │ └── ChatHttpExecutor.java
│ │ ├── exception
│ │ ├── HttpCallFailedException.java
│ │ ├── OpenAIRespondedNot2xxException.java
│ │ ├── UnparseableRequestException.java
│ │ └── UnparseableResponseException.java
│ │ ├── file
│ │ ├── RetrieveFileContentHttpExecutor.java
│ │ └── UploadFileHttpExecutor.java
│ │ ├── images
│ │ ├── CreateImageHttpExecutor.java
│ │ ├── EditImageHttpExecutor.java
│ │ └── ImageVariationHttpExecutor.java
│ │ ├── message
│ │ ├── MessageHttpExecutor.java
│ │ └── RetrieveListMessagesHttpExecutor.java
│ │ ├── run
│ │ └── RunnableHttpExecutor.java
│ │ ├── thread
│ │ ├── CreateThreadHttpExecutor.java
│ │ └── ModifyThreadHttpExecutor.java
│ │ ├── vision
│ │ └── VisionHttpExecutor.java
│ │ └── voice
│ │ ├── SpeechHttpExecutor.java
│ │ ├── TranscriptionHttpExecutor.java
│ │ └── TranslationHttpExecutor.java
│ └── test
│ ├── java
│ └── bg
│ │ └── codexio
│ │ └── ai
│ │ └── openai
│ │ └── api
│ │ └── http
│ │ ├── AuthenticationInterceptorTest.java
│ │ ├── CommonTestConstantsUtils.java
│ │ ├── DefaultOpenAIHttpExecutorTest.java
│ │ ├── ExecutorTests.java
│ │ ├── assistant
│ │ ├── AssistantHttpExecutorTest.java
│ │ └── AssistantHttpExecutorTestConstants.java
│ │ ├── chat
│ │ └── ChatHttpExecutorTest.java
│ │ ├── file
│ │ ├── FileHttpExecutorTestConstants.java
│ │ ├── RetrieveFileContentHttpExecutorTest.java
│ │ └── UploadFileHttpExecutorTest.java
│ │ ├── images
│ │ ├── CreateImageHttpExecutorTest.java
│ │ ├── EditImageHttpExecutorTest.java
│ │ └── ImageVariationHttpExecutorTest.java
│ │ ├── message
│ │ ├── MessageHttpExecutorTest.java
│ │ ├── MessageHttpExecutorTestConstants.java
│ │ └── RetrieveListMessagesHttpExecutorTest.java
│ │ ├── run
│ │ ├── RunnableHttpExecutorTest.java
│ │ └── RunnableHttpExecutorTestConstants.java
│ │ ├── thread
│ │ ├── CreateThreadHttpExecutorTest.java
│ │ ├── ModifyThreadHttpExecutorTest.java
│ │ └── ThreadHttpExecutorTestConstants.java
│ │ ├── vision
│ │ └── VisionHttpExecutorTest.java
│ │ └── voice
│ │ ├── SpeechHttpExecutorTest.java
│ │ ├── TranscriptionHttpExecutorTest.java
│ │ └── TranslationHttpExecutorTest.java
│ └── resources
│ ├── fake-file.txt
│ └── fake-image.png
├── openai-api-models
├── pom.xml
└── src
│ ├── main
│ └── java
│ │ └── bg
│ │ └── codexio
│ │ └── ai
│ │ └── openai
│ │ └── api
│ │ └── models
│ │ ├── ModelType.java
│ │ ├── ModelTypeAbstract.java
│ │ ├── dalle
│ │ ├── DallE20.java
│ │ └── DallE30.java
│ │ ├── tts
│ │ ├── TTS1HDModel.java
│ │ └── TTS1Model.java
│ │ ├── v35
│ │ ├── GPT35Turbo1106Model.java
│ │ ├── GPT35Turbo16kModel.java
│ │ └── GPT35TurboModel.java
│ │ ├── v40
│ │ ├── GPT401106Model.java
│ │ ├── GPT4032kModel.java
│ │ ├── GPT40Model.java
│ │ └── GPT40VisionPreviewModel.java
│ │ └── whisper
│ │ └── Whisper10.java
│ └── test
│ └── java
│ └── bg
│ └── codexio
│ └── ai
│ └── openai
│ └── api
│ └── models
│ ├── ModelTypeAbstractTest.java
│ ├── dalle
│ ├── DallE20Test.java
│ └── DallE30Test.java
│ ├── tts
│ ├── TTS1HDModelTest.java
│ └── TTS1ModelTest.java
│ ├── v35
│ ├── GPT35Turbo1106ModelTest.java
│ ├── GPT35Turbo16kModelTest.java
│ └── GPT35TurboModelTest.java
│ ├── v40
│ ├── GPT401105ModelTest.java
│ ├── GPT40302kModelTest.java
│ ├── GPT40ModelTest.java
│ └── GPT40VisionPreviewModelTest.java
│ └── whisper
│ └── Whisper10Test.java
├── openai-api-payload
├── pom.xml
└── src
│ └── main
│ └── java
│ └── bg
│ └── codexio
│ └── ai
│ └── openai
│ └── api
│ └── payload
│ ├── Mergeable.java
│ ├── MetadataUtils.java
│ ├── Streamable.java
│ ├── assistant
│ ├── request
│ │ └── AssistantRequest.java
│ ├── response
│ │ └── AssistantResponse.java
│ └── tool
│ │ ├── AssistantTool.java
│ │ ├── AssistantToolAbstract.java
│ │ ├── CodeInterpreter.java
│ │ └── Retrieval.java
│ ├── chat
│ ├── ChatFunction.java
│ ├── ChatMessage.java
│ ├── functions
│ │ ├── GetCurrentWeather.java
│ │ └── GetNearbyPlaces.java
│ ├── request
│ │ ├── ChatMessageRequest.java
│ │ ├── ChatTool.java
│ │ ├── FunctionChoice.java
│ │ └── FunctionTool.java
│ └── response
│ │ ├── ChatChoiceResponse.java
│ │ ├── ChatMessageResponse.java
│ │ ├── ChatUsageResponse.java
│ │ ├── Content.java
│ │ ├── FunctionResponse.java
│ │ ├── Logprobs.java
│ │ └── ToolCallResponse.java
│ ├── creativity
│ ├── Creativity.java
│ └── RepetitionPenalty.java
│ ├── credentials
│ └── ApiCredentials.java
│ ├── environment
│ └── AvailableEnvironmentVariables.java
│ ├── error
│ ├── ErrorResponse.java
│ └── ErrorResponseHolder.java
│ ├── file
│ ├── purpose
│ │ ├── AssistantPurpose.java
│ │ ├── Purpose.java
│ │ └── PurposeAbstract.java
│ ├── request
│ │ └── UploadFileRequest.java
│ └── response
│ │ ├── FileContentResponse.java
│ │ └── FileResponse.java
│ ├── images
│ ├── Dimensions.java
│ ├── Format.java
│ ├── Quality.java
│ ├── Style.java
│ ├── request
│ │ ├── CreateImageRequest.java
│ │ ├── EditImageRequest.java
│ │ ├── ImageRequest.java
│ │ ├── ImageRequestBuilder.java
│ │ └── ImageVariationRequest.java
│ └── response
│ │ ├── ImageDataResponse.java
│ │ └── ImageResponse.java
│ ├── message
│ ├── content
│ │ ├── ImageFileContent.java
│ │ ├── MessageContent.java
│ │ ├── MessageContentAbstract.java
│ │ ├── TextContent.java
│ │ ├── TextMessageContent.java
│ │ └── annotation
│ │ │ ├── Annotation.java
│ │ │ ├── AnnotationAbstract.java
│ │ │ ├── FileCitation.java
│ │ │ ├── FileCitationAnnotation.java
│ │ │ ├── FilePath.java
│ │ │ └── FilePathAnnotation.java
│ ├── request
│ │ └── MessageRequest.java
│ └── response
│ │ ├── ListMessagesResponse.java
│ │ └── MessageResponse.java
│ ├── run
│ ├── request
│ │ └── RunnableRequest.java
│ └── response
│ │ ├── RunnableResponse.java
│ │ ├── action
│ │ ├── Function.java
│ │ ├── RequiredAction.java
│ │ ├── SubmitToolOutput.java
│ │ └── ToolCall.java
│ │ └── error
│ │ └── LastError.java
│ ├── thread
│ ├── request
│ │ ├── ThreadCreationRequest.java
│ │ ├── ThreadModificationRequest.java
│ │ ├── ThreadRequest.java
│ │ └── ThreadRequestBuilder.java
│ └── response
│ │ └── ThreadResponse.java
│ ├── vision
│ ├── DetailedAnalyze.java
│ └── request
│ │ ├── ImageUrlMessageRequest.java
│ │ ├── ImageUrlRequest.java
│ │ ├── MessageContentHolder.java
│ │ ├── QuestionVisionRequest.java
│ │ ├── VisionMessage.java
│ │ └── VisionRequest.java
│ └── voice
│ ├── AudioFormat.java
│ ├── Speaker.java
│ ├── Speed.java
│ ├── request
│ ├── SpeechRequest.java
│ ├── TranscriptionFormat.java
│ ├── TranscriptionRequest.java
│ └── TranslationRequest.java
│ └── response
│ ├── AudioBinaryResponse.java
│ └── SpeechTextResponse.java
├── openai-api-sdk
├── pom.xml
└── src
│ ├── main
│ └── java
│ │ └── bg
│ │ └── codexio
│ │ └── ai
│ │ └── openai
│ │ └── api
│ │ └── sdk
│ │ ├── Authenticator.java
│ │ ├── HttpBuilder.java
│ │ ├── IntermediateStage.java
│ │ ├── ObjectMapperSubtypesRegistrationUtils.java
│ │ ├── Processing.java
│ │ ├── RuntimeExecutor.java
│ │ ├── RuntimeSelectionStage.java
│ │ ├── StartStage.java
│ │ ├── TerminalStage.java
│ │ ├── ThreadOperationUtils.java
│ │ ├── assistant
│ │ ├── AIModelStage.java
│ │ ├── AssistantAdvancedConfigurationStage.java
│ │ ├── AssistantConfigurationStage.java
│ │ ├── AssistantDescriptionStage.java
│ │ ├── AssistantFileStage.java
│ │ ├── AssistantInstructionStage.java
│ │ ├── AssistantMetaStage.java
│ │ ├── AssistantNameStage.java
│ │ ├── Assistants.java
│ │ └── ToolStage.java
│ │ ├── auth
│ │ ├── FromDeveloper.java
│ │ ├── FromEnvironment.java
│ │ ├── FromJson.java
│ │ ├── SdkAuth.java
│ │ ├── exception
│ │ │ └── NotValidAuthenticationMethod.java
│ │ └── util
│ │ │ └── StringUtil.java
│ │ ├── chat
│ │ ├── AIModelStage.java
│ │ ├── AccuracyStage.java
│ │ ├── AsyncContextStage.java
│ │ ├── AsyncPromise.java
│ │ ├── AsyncRawPromise.java
│ │ ├── Chat.java
│ │ ├── ChatConfigurationStage.java
│ │ ├── ChatRuntimeSelectionStage.java
│ │ ├── ImmediateContextStage.java
│ │ ├── LogprobsStage.java
│ │ ├── ManualConfigurationStage.java
│ │ ├── MessageStage.java
│ │ ├── ReactiveContextStage.java
│ │ ├── SimplifiedStage.java
│ │ ├── TemperatureStage.java
│ │ ├── TokenStage.java
│ │ ├── ToolStage.java
│ │ ├── constant
│ │ │ └── ExceptionMessageConstants.java
│ │ └── exception
│ │ │ └── TopLogprobsOutOfRangeException.java
│ │ ├── file
│ │ ├── DownloadExecutor.java
│ │ ├── FileActionTypeStage.java
│ │ ├── FileConfigurationStage.java
│ │ ├── FileDownloadingNameTypeStage.java
│ │ ├── FileDownloadingStage.java
│ │ ├── FileResult.java
│ │ ├── FileSimplified.java
│ │ ├── FileTargetingStage.java
│ │ ├── FileUploadingStage.java
│ │ └── Files.java
│ │ ├── images
│ │ ├── AIModelStage.java
│ │ ├── ActionTypeStage.java
│ │ ├── AsyncApi.java
│ │ ├── AsyncExecutor.java
│ │ ├── ChoicesStage.java
│ │ ├── CreatingActionTypeStage.java
│ │ ├── Dalle2SizeStage.java
│ │ ├── Dalle3SizeStage.java
│ │ ├── DownloadExecutor.java
│ │ ├── EditingActionTypeStage.java
│ │ ├── EditingMaskStage.java
│ │ ├── FormatStage.java
│ │ ├── ImageConfigurationStage.java
│ │ ├── Images.java
│ │ ├── ImagesPromptStage.java
│ │ ├── ImagesTerminalStage.java
│ │ ├── PromptfulImagesRuntimeSelectionStage.java
│ │ ├── PromptlessImagesRuntimeSelectionStage.java
│ │ ├── QualityStage.java
│ │ ├── ReactiveApi.java
│ │ ├── ReactiveExecutor.java
│ │ ├── SimplifiedStage.java
│ │ ├── StyleStage.java
│ │ ├── SynchronousApi.java
│ │ ├── SynchronousExecutor.java
│ │ ├── VariatingActionTypeStage.java
│ │ ├── color
│ │ │ └── PopularColor.java
│ │ └── tolerance
│ │ │ └── ColorDeviation.java
│ │ ├── message
│ │ ├── MessageActionTypeStage.java
│ │ ├── MessageAdvancedConfigurationStage.java
│ │ ├── MessageAnswerStage.java
│ │ ├── MessageAnswersRetrievalTypeStage.java
│ │ ├── MessageAssistantStage.java
│ │ ├── MessageConfigurationStage.java
│ │ ├── MessageContentStage.java
│ │ ├── MessageFileStage.java
│ │ ├── MessageMetaStage.java
│ │ ├── MessageResult.java
│ │ ├── Messages.java
│ │ └── constant
│ │ │ └── MessageConstants.java
│ │ ├── run
│ │ ├── AIModelStage.java
│ │ ├── RunnableAdvancedConfigurationStage.java
│ │ ├── RunnableConfigurationStage.java
│ │ ├── RunnableInitializationStage.java
│ │ ├── RunnableInstructionStage.java
│ │ ├── RunnableMessageResult.java
│ │ ├── RunnableMetaStage.java
│ │ ├── RunnableResultStage.java
│ │ ├── Runnables.java
│ │ └── constant
│ │ │ ├── RunnableDefaultValuesConstants.java
│ │ │ ├── RunnableEnvironmentVariableNameConstants.java
│ │ │ └── RunnableStatusConstants.java
│ │ ├── thread
│ │ ├── ThreadActionTypeStage.java
│ │ ├── ThreadAdvancedConfigurationStage.java
│ │ ├── ThreadConfigurationStage.java
│ │ ├── ThreadCreationStage.java
│ │ ├── ThreadMessageContentStage.java
│ │ ├── ThreadMessageFileStage.java
│ │ ├── ThreadMetaStage.java
│ │ ├── ThreadModificationStage.java
│ │ ├── Threads.java
│ │ └── constant
│ │ │ └── ThreadDefaultValuesConstants.java
│ │ ├── vision
│ │ ├── AIModelStage.java
│ │ ├── AsyncPromise.java
│ │ ├── AsyncPromptStage.java
│ │ ├── ImageChooserOrSkipStage.java
│ │ ├── ImageChooserStage.java
│ │ ├── ImageDetailStage.java
│ │ ├── ReactivePromptStage.java
│ │ ├── SimplifiedStage.java
│ │ ├── SynchronousPromptStage.java
│ │ ├── TokenStage.java
│ │ ├── Vision.java
│ │ ├── VisionConfigurationStage.java
│ │ └── VisionRuntimeSelectionStage.java
│ │ └── voice
│ │ ├── speech
│ │ ├── AIModelStage.java
│ │ ├── AsyncDownloadStage.java
│ │ ├── AsyncPromiseStage.java
│ │ ├── AsyncPromptStage.java
│ │ ├── DownloadExecutor.java
│ │ ├── OutputStage.java
│ │ ├── ReactiveDownloadStage.java
│ │ ├── ReactivePromptStage.java
│ │ ├── SimplifiedStage.java
│ │ ├── Speech.java
│ │ ├── SpeechConfigurationStage.java
│ │ ├── SpeechRuntimeSelectionStage.java
│ │ ├── SpeedStage.java
│ │ ├── SynchronousDownloadStage.java
│ │ ├── SynchronousPromptStage.java
│ │ └── VoiceStage.java
│ │ ├── transcription
│ │ ├── AIModelStage.java
│ │ ├── AsyncPromiseStage.java
│ │ ├── AsyncPromptStage.java
│ │ ├── AudioFileStage.java
│ │ ├── FormatStage.java
│ │ ├── LanguageStage.java
│ │ ├── PreSimplifiedStage.java
│ │ ├── ReactivePromptStage.java
│ │ ├── SimplifiedStage.java
│ │ ├── SynchronousPromptStage.java
│ │ ├── TemperatureStage.java
│ │ ├── Transcription.java
│ │ ├── TranscriptionConfigurationStage.java
│ │ └── TranscriptionRuntimeSelectionStage.java
│ │ └── translation
│ │ ├── AIModelStage.java
│ │ ├── AsyncPromiseStage.java
│ │ ├── AsyncPromptStage.java
│ │ ├── AudioFileStage.java
│ │ ├── FormatStage.java
│ │ ├── PreSimplifiedStage.java
│ │ ├── ReactivePromptStage.java
│ │ ├── SimplifiedStage.java
│ │ ├── SynchronousPromptStage.java
│ │ ├── TemperatureStage.java
│ │ ├── Translation.java
│ │ ├── TranslationConfigurationStage.java
│ │ └── TranslationRuntimeSelectionStage.java
│ └── test
│ ├── java
│ └── bg
│ │ └── codexio
│ │ └── ai
│ │ └── openai
│ │ └── api
│ │ └── sdk
│ │ ├── AsyncCallbackUtils.java
│ │ ├── AuthenticatorTest.java
│ │ ├── CommonTestAssertions.java
│ │ ├── HttpBuilderTest.java
│ │ ├── MockedFileSimplifiedUtils.java
│ │ ├── ObjectMapperSubtypesRegistrationUtilsTest.java
│ │ ├── ProcessingTest.java
│ │ ├── ThreadOperationUtilsTest.java
│ │ ├── assistant
│ │ ├── AIModelStageTest.java
│ │ ├── AssistantAdvancedConfigurationTest.java
│ │ ├── AssistantDescriptionStageTest.java
│ │ ├── AssistantFileStageTest.java
│ │ ├── AssistantInstructionStageTest.java
│ │ ├── AssistantMetaStageTest.java
│ │ ├── AssistantNameStageTest.java
│ │ ├── AssistantsTest.java
│ │ ├── InternalAssertions.java
│ │ └── ToolStageTest.java
│ │ ├── auth
│ │ ├── FromDeveloperTest.java
│ │ ├── FromEnvironmentTest.java
│ │ ├── FromJsonTest.java
│ │ └── util
│ │ │ └── StringUtilTest.java
│ │ ├── chat
│ │ ├── AIModelStageTest.java
│ │ ├── AccuracyStageTest.java
│ │ ├── AsyncContextStageTest.java
│ │ ├── ChatRuntimeSelectionStageTest.java
│ │ ├── ChatTest.java
│ │ ├── ImmediateContextStageTest.java
│ │ ├── InternalAssertions.java
│ │ ├── LogprobsStageTest.java
│ │ ├── ManualConfigurationStageTest.java
│ │ ├── MessageStageTest.java
│ │ ├── ReactiveContextStageTest.java
│ │ ├── SimplifiedStageTest.java
│ │ ├── TemperatureStageTest.java
│ │ ├── TokenStageTest.java
│ │ └── ToolStageTest.java
│ │ ├── file
│ │ ├── DownloadExecutorTest.java
│ │ ├── FileActionTypeStageTest.java
│ │ ├── FileDownloadingNameTypeStageTest.java
│ │ ├── FileDownloadingStageTest.java
│ │ ├── FileResultTest.java
│ │ ├── FileSimplifiedTest.java
│ │ ├── FileTargetingStageTest.java
│ │ ├── FileUploadingStageTest.java
│ │ ├── FilesTest.java
│ │ └── InternalAssertions.java
│ │ ├── images
│ │ ├── AIModelStageTest.java
│ │ ├── ActionTypeStageTest.java
│ │ ├── AsyncApiTest.java
│ │ ├── AsyncExecutorTest.java
│ │ ├── ChoicesStageTest.java
│ │ ├── CreatingActionTypeStageTest.java
│ │ ├── Dalle2SizeStageTest.java
│ │ ├── Dalle3SizeStageTest.java
│ │ ├── DownloadExecutorTest.java
│ │ ├── EditingActionTypeStageTest.java
│ │ ├── EditingMaskStageTest.java
│ │ ├── FormatStageTest.java
│ │ ├── ImagesTerminalStageTest.java
│ │ ├── ImagesTest.java
│ │ ├── InternalAssertions.java
│ │ ├── PromptfulImagesRuntimeSelectionStageTest.java
│ │ ├── PromptlessImagesRuntimeSelectionStageTest.java
│ │ ├── QualityStageTest.java
│ │ ├── ReactiveApiTest.java
│ │ ├── ReactiveExecutorTest.java
│ │ ├── SimplifiedStageTest.java
│ │ ├── StyleStageTest.java
│ │ ├── SynchronousApiTest.java
│ │ ├── SynchronousExecutorTest.java
│ │ └── VariatingActionTypeStageTest.java
│ │ ├── message
│ │ ├── InternalAssertions.java
│ │ ├── MessageActionTypeStageTest.java
│ │ ├── MessageAdvancedConfigurationStageTest.java
│ │ ├── MessageAnswerStageTest.java
│ │ ├── MessageAnswersRetrievalTypeStageTest.java
│ │ ├── MessageAssistantStageTest.java
│ │ ├── MessageContentStageTest.java
│ │ ├── MessageFileStageTest.java
│ │ ├── MessageMetaStageTest.java
│ │ ├── MessageResultTest.java
│ │ └── MessagesTest.java
│ │ ├── run
│ │ ├── AIModelStageTest.java
│ │ ├── InternalAssertions.java
│ │ ├── RunnableAdvancedConfigurationStageTest.java
│ │ ├── RunnableInitializationStageTest.java
│ │ ├── RunnableInstructionStageTest.java
│ │ ├── RunnableMessageResultTest.java
│ │ ├── RunnableMetaStageTest.java
│ │ ├── RunnableResultStageTest.java
│ │ └── RunnablesTest.java
│ │ ├── thread
│ │ ├── InternalAssertions.java
│ │ ├── ThreadActionTypeStageTest.java
│ │ ├── ThreadAdvancedConfigurationStageTest.java
│ │ ├── ThreadCreationMetaStageTest.java
│ │ ├── ThreadCreationStageTest.java
│ │ ├── ThreadMessageContentStageTest.java
│ │ ├── ThreadMessageFileStageTest.java
│ │ ├── ThreadModificationMetaStageTest.java
│ │ ├── ThreadModificationStageTest.java
│ │ └── ThreadsTest.java
│ │ ├── vision
│ │ ├── AIModelStageTest.java
│ │ ├── AsyncPromiseStageTest.java
│ │ ├── AsyncPromptStageTest.java
│ │ ├── ChooserAssertions.java
│ │ ├── ImageChooserOrSkipStageTest.java
│ │ ├── ImageChooserStageTest.java
│ │ ├── ImageDetailStageTest.java
│ │ ├── InternalAssertions.java
│ │ ├── ReactivePromptStageTest.java
│ │ ├── SimplifiedStageTest.java
│ │ ├── SynchronousPromptStageTest.java
│ │ ├── TokenStageTest.java
│ │ ├── VisionRuntimeSelectionStageTest.java
│ │ └── VisionTest.java
│ │ └── voice
│ │ ├── .gitkeep
│ │ ├── speech
│ │ ├── AIModelStageTest.java
│ │ ├── AsyncDownloadStageTest.java
│ │ ├── AsyncPromiseStageTest.java
│ │ ├── AsyncPromptStageTest.java
│ │ ├── DownloadExecutorTest.java
│ │ ├── InternalAssertions.java
│ │ ├── OutputStageTest.java
│ │ ├── ReactiveDownloadStageTest.java
│ │ ├── ReactivePromptStageTest.java
│ │ ├── SimplifiedStageTest.java
│ │ ├── SpeechRuntimeSelectionStageTest.java
│ │ ├── SpeechTest.java
│ │ ├── SpeedStageTest.java
│ │ ├── SynchronousDownloadStageTest.java
│ │ ├── SynchronousPromptStageTest.java
│ │ └── VoiceStageTest.java
│ │ ├── transcription
│ │ ├── AIModelStageTest.java
│ │ ├── AsyncPromiseStageTest.java
│ │ ├── AsyncPromptStageTest.java
│ │ ├── AudioFileStageTest.java
│ │ ├── FormatStageTest.java
│ │ ├── InternalAssertions.java
│ │ ├── LanguageStageTest.java
│ │ ├── PreSimplifiedStageTest.java
│ │ ├── ReactivePromptStageTest.java
│ │ ├── SimplifiedStageTest.java
│ │ ├── SynchronousPromptStageTest.java
│ │ ├── TemperatureStageTest.java
│ │ ├── TranscriptionRuntimeSelectionStageTest.java
│ │ └── TranscriptionTest.java
│ │ └── translation
│ │ ├── AIModelStageTest.java
│ │ ├── AsyncPromiseStageTest.java
│ │ ├── AsyncPromptStageTest.java
│ │ ├── AudioFileStageTest.java
│ │ ├── FormatStageTest.java
│ │ ├── InternalAssertions.java
│ │ ├── PreSimplifiedStageTest.java
│ │ ├── ReactivePromptStageTest.java
│ │ ├── SimplifiedStageTest.java
│ │ ├── SynchronousPromptStageTest.java
│ │ ├── TemperatureStageTest.java
│ │ ├── TranslationRuntimeSelectionStageTest.java
│ │ └── TranslationTest.java
│ └── resources
│ ├── fake-file.txt
│ └── test-key.json
├── pom.xml
├── project-logo.png
└── scaled-java-cat-min.png
/.github/workflows/maven.yml:
--------------------------------------------------------------------------------
1 | name: Maven Build
2 |
3 | on:
4 | push:
5 | branches:
6 | - master
7 | pull_request:
8 | branches:
9 | - master
10 |
11 | jobs:
12 | build:
13 | runs-on: ubuntu-latest
14 | steps:
15 | - uses: actions/checkout@v2
16 | - name: Set up JDK 21
17 | uses: actions/setup-java@v4
18 | with:
19 | java-version: '21'
20 | distribution: 'temurin'
21 | - name: JaCoCo Coverage
22 | run: mvn clean test jacoco:report -Pmvn-deploy
23 | - name: Codecov Upload
24 | uses: codecov/codecov-action@v4
25 | with:
26 | token: ${{ secrets.CODECOV_TOKEN }}
27 | file: ./openai-api-coverage/target/site/jacoco-aggregate/jacoco.xml
28 | fail_ci_if_error: true
29 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | HELP.md
2 | target/
3 | !.mvn/wrapper/maven-wrapper.jar
4 | !**/src/main/**/target/
5 | !**/src/test/**/target/
6 |
7 | ### STS ###
8 | .apt_generated
9 | .classpath
10 | .factorypath
11 | .project
12 | .settings
13 | .springBeans
14 | .sts4-cache
15 |
16 | ### IntelliJ IDEA ###
17 | .idea
18 | *.iws
19 | *.iml
20 | *.ipr
21 |
22 | ### NetBeans ###
23 | /nbproject/private/
24 | /nbbuild/
25 | /dist/
26 | /nbdist/
27 | /.nb-gradle/
28 | build/
29 | !**/src/main/**/build/
30 | !**/src/test/**/build/
31 |
32 | ### VS Code ###
33 | .vscode/
34 |
35 | ## Exclude manual testing module
36 | openai-api-app
37 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | This project is in its very early stage and contributors are very welcomed. If you feel that something has to be
4 | changed or a bug to be fixed, you can report a [new issue](https://github.com/CodexioLtd/openai-api-sdk/issues/new), and
5 | we can take care of it.
6 |
7 | If you want to submit directly a code fix, we will be more than glad to see it. Fork the repository and start a clean
8 | branch out of the version you want to patch. When you are finished, make sure all your tests are passing and the
9 | coverage remains in decent level by executing `mvn clean test jacoco:report -Pmvn-deploy`.
10 |
11 | Please, use the [code style](https://github.com/CodexioLtd/openai-api-sdk/blob/master/cdx-openai-codestyle.xml)
12 | in the project root folder. If your IDE does not support it, we strongly encourage you just to follow
13 | the code styling in the rest of the classes and methods.
14 |
15 | After all your tests are passing and the coverage seems good to you, create a
16 | [pull request](https://github.com/CodexioLtd/openai-api-sdk/compare). We will review the request and either leave
17 | some meaningful suggestions back or maybe merge it and release it with the next release.
18 |
19 | The first open beta of the project is 0.8.0 and all the way up to 1.0.0 we will strive to find core
20 | contributors who will serve as project maintainers in the future. [Codexio Ltd.](https://codexio.bg) will remain
21 | the main project maintainer.
22 |
--------------------------------------------------------------------------------
/openai-api-examples/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 |
8 | bg.codexio.ai
9 | openai-api
10 | 0.9.1.BETA-SNAPSHOT
11 |
12 |
13 | openai-api-examples
14 | jar
15 |
16 |
17 | false
18 |
19 |
20 |
21 |
22 |
23 | bg.codexio.ai
24 | openai-api-sdk
25 | 0.9.1.BETA-SNAPSHOT
26 |
27 |
28 |
29 | org.apache.logging.log4j
30 | log4j-slf4j2-impl
31 | 3.0.0-alpha1
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/chat/ChatAskAsync.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.examples.chat;
2 |
3 | import bg.codexio.ai.openai.api.sdk.chat.Chat;
4 |
5 | public class ChatAskAsync {
6 | public static void main(String[] args) {
7 | Chat.defaults()
8 | .and()
9 | .poweredByGPT40()
10 | .andRespond()
11 | .async()
12 | .ask(
13 | "Are cinnamon rolls a cool dessert?",
14 | "What types of cinnamon rolls exist?"
15 | )
16 | .then(System.out::println);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/chat/ChatAskMultipleQuestionsWithGPT4.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.examples.chat;
2 |
3 | import bg.codexio.ai.openai.api.sdk.chat.Chat;
4 |
5 | public class ChatAskMultipleQuestionsWithGPT4 {
6 | public static void main(String[] args) {
7 | // In this case, the response for the two questions is going to be
8 | // merged in one
9 |
10 | var response = Chat.defaults()
11 | .and()
12 | .poweredByGPT40()
13 | .predictable()
14 | .andRespond()
15 | .immediate()
16 | .ask(
17 | "Is Java the coolest programming language "
18 | + "on the planet?",
19 | "Are cats the coolest animals on the "
20 | + "planet too?"
21 | );
22 |
23 | System.out.println(response);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/chat/ChatAskReactive.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.examples.chat;
2 |
3 | import bg.codexio.ai.openai.api.payload.creativity.Creativity;
4 | import bg.codexio.ai.openai.api.sdk.chat.Chat;
5 |
6 | public class ChatAskReactive {
7 | public static void main(String[] args) {
8 | Chat.defaults()
9 | .and()
10 | .poweredByGPT40()
11 | .creativeAs(Creativity.BALANCE_BETWEEN_NOVELTY_AND_PREDICTABILITY)
12 | .andRespond()
13 | .reactive()
14 | .askRaw(
15 | "Are cinnamon rolls a cool dessert?",
16 | "What types of cinnamon rolls exist?"
17 | )
18 | .lines()
19 | .subscribe(System.out::println);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/chat/ChatAskWithEnabledLogprobabilites.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.examples.chat;
2 |
3 | import bg.codexio.ai.openai.api.sdk.chat.Chat;
4 |
5 | public class ChatAskWithEnabledLogprobabilites {
6 |
7 | public static void main(String[] args) {
8 | var chatResponse = Chat.defaults()
9 | .and()
10 | .poweredByGPT40()
11 | .deepConfigure()
12 | .logprobs()
13 | .enable()
14 | .and()
15 | .done()
16 | .andRespond()
17 | .immediate()
18 | .askRaw("Which is the highest mountain in "
19 | + "Bulgaria?");
20 |
21 | System.out.println(chatResponse);
22 | }
23 | }
--------------------------------------------------------------------------------
/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/chat/ChatAskWithTopLogprobabilites.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.examples.chat;
2 |
3 | import bg.codexio.ai.openai.api.sdk.chat.Chat;
4 |
5 | public class ChatAskWithTopLogprobabilites {
6 |
7 | public static void main(String[] args) {
8 | var chatResponse = Chat.defaults()
9 | .and()
10 | .poweredByGPT40()
11 | .deepConfigure()
12 | .logprobs()
13 | .withTop(2)
14 | .and()
15 | .done()
16 | .andRespond()
17 | .immediate()
18 | .askRaw("Which is the highest mountain in "
19 | + "Bulgaria?");
20 |
21 | System.out.println(chatResponse);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/chat/ChatDefinedAuthenticationMethod.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.examples.chat;
2 |
3 | import bg.codexio.ai.openai.api.sdk.auth.FromJson;
4 | import bg.codexio.ai.openai.api.sdk.chat.Chat;
5 |
6 | public class ChatDefinedAuthenticationMethod {
7 | public static void main(String[] args) {
8 |
9 | // In this case, we're using a predefined SDK Auth, so we skip the
10 | // iteration through all authentication methods
11 | // After that, we have some fun by prompting the chat to be as
12 | // imaginative as possible
13 | var response = Chat.authenticate(FromJson.AUTH)
14 | .and()
15 | .poweredByGPT40()
16 | .randomized()
17 | .assist("You can be as imaginative and dreamy as "
18 | + "possible")
19 | .andRespond()
20 | .immediate()
21 | .ask("Are coffee and cinnamon rolls a good combo?");
22 |
23 | System.out.println(response);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/chat/ChatSimplyAsk.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.examples.chat;
2 |
3 | import bg.codexio.ai.openai.api.sdk.chat.Chat;
4 |
5 | public class ChatSimplyAsk {
6 | public static void main(String[] args) {
7 | var response = Chat.simply()
8 | .ask("Is Java the coolest programming language on "
9 | + "the planet?");
10 |
11 | System.out.println(response);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/file/DownloadFile.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.examples.file;
2 |
3 | import bg.codexio.ai.openai.api.sdk.file.Files;
4 |
5 | import java.io.File;
6 | import java.io.IOException;
7 |
8 | public class DownloadFile {
9 |
10 | public static void main(String[] args) throws IOException {
11 | var file = new File(DownloadFile.class.getClassLoader()
12 | .getResource("")
13 | .getPath() + "generated-files");
14 |
15 | var downloadedFile = Files.defaults()
16 | .and()
17 | .download("file-zR7aSAvw1xFBjqLIGKnRpT1q")
18 | .as("file.py")
19 | .toFolder(file);
20 |
21 | System.out.println(downloadedFile.getAbsoluteFile()
22 | .getName());
23 | }
24 | }
--------------------------------------------------------------------------------
/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/file/DownloadFileWithFileResult.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.examples.file;
2 |
3 | import bg.codexio.ai.openai.api.sdk.file.FileResult;
4 |
5 | import java.io.File;
6 | import java.io.IOException;
7 |
8 | public class DownloadFileWithFileResult {
9 |
10 | public static void main(String[] args) throws IOException {
11 | var targetFolder = new File(
12 | DownloadFileWithFileResult.class.getClassLoader()
13 | .getResource("")
14 | .getPath() + "generated-files");
15 |
16 | var downloadedFile = new FileResult(
17 | "file-zR7aSAvw1xFBjqLIGKnRpT1q",
18 | "file.py"
19 | ).download(targetFolder);
20 |
21 | System.out.println(downloadedFile.getName());
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/file/UploadFile.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.examples.file;
2 |
3 |
4 | import bg.codexio.ai.openai.api.payload.file.purpose.AssistantPurpose;
5 | import bg.codexio.ai.openai.api.sdk.file.Files;
6 |
7 | import java.io.File;
8 |
9 | public class UploadFile {
10 |
11 | public static void main(String[] args) {
12 | var file = new File(UploadFile.class.getClassLoader()
13 | .getResource("fake-file.txt")
14 | .getPath());
15 | var fileId = Files.defaults()
16 | .and()
17 | .upload()
18 | .targeting(new AssistantPurpose())
19 | .feed(file);
20 |
21 | System.out.println(fileId);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/images/create/ImagesGenerateDalle2CustomSettingsAndDownloadAsync.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.examples.images.create;
2 |
3 | import bg.codexio.ai.openai.api.sdk.images.Images;
4 |
5 | import java.io.File;
6 | import java.io.IOException;
7 |
8 | public class ImagesGenerateDalle2CustomSettingsAndDownloadAsync {
9 | public static void main(String[] args) throws IOException {
10 | var file = new File(
11 | ImagesGenerateDalle2CustomSettingsAndDownloadAsync.class.getClassLoader()
12 | .getResource("")
13 | .getPath()
14 | + "generated-images");
15 |
16 | Images.defaults()
17 | .and()
18 | .creating()
19 | .poweredByDallE2()
20 | .singleChoice()
21 | .mediumSquare()
22 | .expectUrl()
23 | .andRespond()
24 | .async()
25 | .generate("Cartoon cat")
26 | .whenDownloaded(
27 | file,
28 | System.out::println
29 | );
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/images/create/ImagesGenerateDalle3CustomSettings.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.examples.images.create;
2 |
3 | import bg.codexio.ai.openai.api.sdk.images.Images;
4 |
5 | public class ImagesGenerateDalle3CustomSettings {
6 | public static void main(String[] args) {
7 | var response = Images.defaults()
8 | .and()
9 | .creating()
10 | .poweredByDallE3()
11 | .vivid()
12 | .highDefinitioned()
13 | .portrait()
14 | .expectUrl()
15 | .andRespond()
16 | .immediate()
17 | .generate("Cat drinking coffee in a green and "
18 | + "snowy forest in a beautiful"
19 | + " day")
20 | .andGetRaw();
21 |
22 | System.out.println(response);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/images/create/ImagesGenerateDalle3CustomSettingsAndDownload.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.examples.images.create;
2 |
3 | import bg.codexio.ai.openai.api.sdk.images.Images;
4 |
5 | import java.io.File;
6 | import java.io.IOException;
7 |
8 | public class ImagesGenerateDalle3CustomSettingsAndDownload {
9 | public static void main(String[] args) throws IOException {
10 | var file = new File(
11 | ImagesGenerateDalle3CustomSettingsAndDownload.class.getClassLoader()
12 | .getResource("")
13 | .getPath()
14 | + "generated-images");
15 |
16 | Images.defaults()
17 | .and()
18 | .creating()
19 | .poweredByDallE3()
20 | .vivid()
21 | .highDefinitioned()
22 | .portrait()
23 | .expectUrl()
24 | .andRespond()
25 | .immediate()
26 | .generate("Cat drinking coffee in a green and snowy forest in a"
27 | + " beautiful day")
28 | .andDownload(file);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/images/create/ImagesSimplyGenerate.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.examples.images.create;
2 |
3 | import bg.codexio.ai.openai.api.sdk.images.Images;
4 |
5 | public class ImagesSimplyGenerate {
6 | public static void main(String[] args) {
7 | var response = Images.simply()
8 | .generate("Image of a cat playing in the snow");
9 |
10 | System.out.println(response);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/images/edit/ImagesEditCustomMaskFile.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.examples.images.edit;
2 |
3 | import bg.codexio.ai.openai.api.sdk.images.Images;
4 |
5 | import java.io.File;
6 |
7 | public class ImagesEditCustomMaskFile {
8 | public static void main(String[] args) {
9 | var imageToEdit =
10 | new File(ImagesEditCustomMaskFile.class.getClassLoader()
11 | .getResource("editable-image.png")
12 | .getPath());
13 |
14 | var imageMask = new File(ImagesEditCustomMaskFile.class.getClassLoader()
15 | .getResource(
16 | "editable-image-mask.png")
17 | .getPath());
18 |
19 | var response = Images.defaults()
20 | .and()
21 | .editing(imageToEdit)
22 | .masked(imageMask)
23 | .singleChoice()
24 | .mediumSquare()
25 | .expectUrl()
26 | .andRespond()
27 | .immediate()
28 | .generate("Black fur")
29 | .andGetRaw();
30 |
31 | System.out.println(response);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/images/edit/ImagesEditMaskByHexColor.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.examples.images.edit;
2 |
3 | import bg.codexio.ai.openai.api.sdk.images.Images;
4 | import bg.codexio.ai.openai.api.sdk.images.tolerance.ColorDeviation;
5 |
6 | import java.io.File;
7 |
8 | public class ImagesEditMaskByHexColor {
9 | public static void main(String[] args) {
10 | var inputImage =
11 | new File(ImagesEditMaskByHexColor.class.getClassLoader()
12 | .getResource(
13 | "editable-image.png")
14 | .getPath());
15 |
16 | var response = Images.defaults()
17 | .and()
18 | .editing(inputImage)
19 | .masked(
20 | "#6F4E00",
21 | ColorDeviation.BALANCED_TOLERANCE
22 | )
23 | .singleChoice()
24 | .mediumSquare()
25 | .expectUrl()
26 | .andRespond()
27 | .immediate()
28 | .generate("Black fur")
29 | .andGetRaw();
30 |
31 | System.out.println(response);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/images/variations/ImageMultipleVariationsAsync.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.examples.images.variations;
2 |
3 | import bg.codexio.ai.openai.api.examples.images.edit.ImagesEditCustomMaskFile;
4 | import bg.codexio.ai.openai.api.sdk.images.Images;
5 |
6 | import java.io.File;
7 |
8 | public class ImageMultipleVariationsAsync {
9 | public static void main(String[] args) {
10 | var inputImage =
11 | new File(ImagesEditCustomMaskFile.class.getClassLoader()
12 | .getResource(
13 | "image-for-variations.png")
14 | .getPath());
15 |
16 | Images.defaults()
17 | .and()
18 | .another(inputImage)
19 | .withChoices(3)
20 | .smallSquare()
21 | .expectUrl()
22 | .andRespond()
23 | .async()
24 | .onResponse(System.out::println);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/message/CreateMessage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.examples.message;
2 |
3 | import bg.codexio.ai.openai.api.sdk.message.Messages;
4 | import bg.codexio.ai.openai.api.sdk.thread.Threads;
5 |
6 | public class CreateMessage {
7 |
8 | public static void main(String[] args) {
9 | var messageResponse = Messages.defaults(Threads.defaults()
10 | .and()
11 | .creating()
12 | .empty())
13 | .and()
14 | .chat()
15 | .withContent("How are you?")
16 | .andRespond();
17 |
18 | System.out.println(messageResponse);
19 | }
20 | }
--------------------------------------------------------------------------------
/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/run/CreateRun.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.examples.run;
2 |
3 | import bg.codexio.ai.openai.api.payload.assistant.tool.CodeInterpreter;
4 | import bg.codexio.ai.openai.api.sdk.assistant.Assistants;
5 | import bg.codexio.ai.openai.api.sdk.run.Runnables;
6 | import bg.codexio.ai.openai.api.sdk.thread.Threads;
7 |
8 | public class CreateRun {
9 |
10 | public static void main(String[] args) {
11 | var run = Runnables.defaults(Threads.defaults()
12 | .and()
13 | .creating()
14 | .empty())
15 | .and()
16 | .deepConfigure(Assistants.defaults()
17 | .and()
18 | .poweredByGPT40()
19 | .from(new CodeInterpreter())
20 | .called("Cody")
21 | .instruct("Be intuitive")
22 | .andRespond())
23 | .andRespond();
24 |
25 | System.out.println(run);
26 | }
27 | }
--------------------------------------------------------------------------------
/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/thread/CreateEmptyThread.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.examples.thread;
2 |
3 | import bg.codexio.ai.openai.api.sdk.thread.Threads;
4 |
5 | public class CreateEmptyThread {
6 |
7 | public static void main(String[] args) {
8 | var thread = Threads.defaults()
9 | .and()
10 | .creating()
11 | .empty();
12 |
13 | System.out.println(thread);
14 | }
15 | }
--------------------------------------------------------------------------------
/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/thread/CreateThread.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.examples.thread;
2 |
3 | import bg.codexio.ai.openai.api.sdk.thread.Threads;
4 |
5 | import java.io.File;
6 |
7 | public class CreateThread {
8 |
9 | public static void main(String[] args) {
10 | var file = new File(CreateThread.class.getClassLoader()
11 | .getResource("fake-file.txt")
12 | .getPath());
13 |
14 | var thread = Threads.defaults()
15 | .and()
16 | .creating()
17 | .deepConfigure()
18 | .meta()
19 | .awareOf(
20 | "key1",
21 | "value1",
22 | "key2",
23 | "value2"
24 | )
25 | .file()
26 | .attach(file)
27 | .message()
28 | .startWith("You're java developer.")
29 | .feed(file);
30 |
31 | System.out.println(thread);
32 | }
33 | }
--------------------------------------------------------------------------------
/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/vision/VisionDetailedExampleWithLimit.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.examples.vision;
2 |
3 | import bg.codexio.ai.openai.api.examples.images.edit.ImagesEditCustomMaskFile;
4 | import bg.codexio.ai.openai.api.payload.vision.DetailedAnalyze;
5 | import bg.codexio.ai.openai.api.sdk.vision.Vision;
6 |
7 | import java.io.File;
8 |
9 | public class VisionDetailedExampleWithLimit {
10 | public static void main(String[] args) {
11 | var inputImage =
12 | new File(ImagesEditCustomMaskFile.class.getClassLoader()
13 | .getResource(
14 | "codi-image-to-explain.png")
15 | .getPath());
16 |
17 | var response = Vision.defaults()
18 | .and()
19 | .poweredByGpt40Vision()
20 | .limitResponseTo(300)
21 | .explain(inputImage)
22 | .analyze(DetailedAnalyze.HIGH)
23 | .andRespond()
24 | .immediate()
25 | .describeRaw();
26 |
27 | System.out.println(response);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/voice/speech/SpeechConfiguredExample.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.examples.voice.speech;
2 |
3 | import bg.codexio.ai.openai.api.payload.voice.Speaker;
4 | import bg.codexio.ai.openai.api.sdk.voice.speech.Speech;
5 |
6 | import java.io.File;
7 | import java.io.IOException;
8 |
9 | public class SpeechConfiguredExample {
10 | public static void main(String[] args) throws IOException {
11 | var targetFolder = new File(
12 | SpeechConfiguredExample.class.getClassLoader()
13 | .getResource("")
14 | .getPath() + "generated-audio");
15 |
16 | Speech.defaults()
17 | .and()
18 | .hdPowered()
19 | .voiceOf(Speaker.NOVA)
20 | .mp3()
21 | .sameSpeed()
22 | .immediate()
23 | .dictate("There is nothing better that the combination of Java,"
24 | + " coffee and the company of cats.")
25 | .downloadTo(targetFolder);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/voice/speech/SpeechSimpleExample.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.examples.voice.speech;
2 |
3 | import bg.codexio.ai.openai.api.sdk.voice.speech.Speech;
4 |
5 | import java.io.File;
6 | import java.io.IOException;
7 |
8 | public class SpeechSimpleExample {
9 | public static void main(String[] args) throws IOException {
10 | var targetFolder = new File(SpeechSimpleExample.class.getClassLoader()
11 | .getResource("")
12 | .getPath()
13 | + "generated-audio");
14 |
15 | Speech.simply()
16 | .dictate("Katzen sind wunderschöne Geschöpfe.")
17 | .downloadTo(targetFolder);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/voice/transcription/TranscriptionConfiguredExample.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.examples.voice.transcription;
2 |
3 | import bg.codexio.ai.openai.api.sdk.voice.transcription.Transcription;
4 |
5 | import java.io.File;
6 |
7 | public class TranscriptionConfiguredExample {
8 | public static void main(String[] args) {
9 | var audioFile =
10 | new File(TranscriptionConfiguredExample.class.getClassLoader()
11 | .getResource("audio.mp3")
12 | .getPath());
13 | var response = Transcription.defaults()
14 | .and()
15 | .poweredByWhisper10()
16 | .transcribe(audioFile)
17 | .randomized()
18 | .talkingIn("en")
19 | .subtitlesWithMetadata()
20 | .immediate()
21 | .guide("Be creative")
22 | .text();
23 |
24 | System.out.println(response);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/voice/transcription/TranscriptionSimpleExample.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.examples.voice.transcription;
2 |
3 | import bg.codexio.ai.openai.api.sdk.voice.transcription.Transcription;
4 |
5 | import java.io.File;
6 |
7 | public class TranscriptionSimpleExample {
8 | public static void main(String[] args) {
9 | var audioFile =
10 | new File(TranscriptionSimpleExample.class.getClassLoader()
11 | .getResource("audio.mp3")
12 | .getPath());
13 | var response = Transcription.simply()
14 | .transcribe(audioFile)
15 | .unguided();
16 |
17 | System.out.println(response);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/voice/translation/TranslationConfiguredExample.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.examples.voice.translation;
2 |
3 | import bg.codexio.ai.openai.api.sdk.voice.translation.Translation;
4 |
5 | import java.io.File;
6 |
7 | public class TranslationConfiguredExample {
8 | public static void main(String[] args) {
9 | var audioFile =
10 | new File(TranslationConfiguredExample.class.getClassLoader()
11 | .getResource("audio-de.mp3")
12 | .getPath());
13 |
14 | var response = Translation.defaults()
15 | .and()
16 | .poweredByWhisper10()
17 | .translate(audioFile)
18 | .deterministic()
19 | .justText()
20 | .immediate()
21 | .unguided()
22 | .text();
23 |
24 | System.out.println(response);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/openai-api-examples/src/main/java/bg/codexio/ai/openai/api/examples/voice/translation/TranslationSimpleExample.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.examples.voice.translation;
2 |
3 | import bg.codexio.ai.openai.api.sdk.voice.translation.Translation;
4 |
5 | import java.io.File;
6 |
7 | public class TranslationSimpleExample {
8 | public static void main(String[] args) {
9 | var audioFile = new File(TranslationSimpleExample.class.getClassLoader()
10 | .getResource(
11 | "audio-de.mp3")
12 | .getPath());
13 |
14 | var response = Translation.simply()
15 | .translate(audioFile)
16 | .unguided()
17 | .text();
18 |
19 | System.out.println(response);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/openai-api-examples/src/main/resources/audio-de.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CodexioLtd/openai-api-sdk/584766f390964541c2a0138677038e5e06bfc937/openai-api-examples/src/main/resources/audio-de.mp3
--------------------------------------------------------------------------------
/openai-api-examples/src/main/resources/audio.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CodexioLtd/openai-api-sdk/584766f390964541c2a0138677038e5e06bfc937/openai-api-examples/src/main/resources/audio.mp3
--------------------------------------------------------------------------------
/openai-api-examples/src/main/resources/codi-image-to-explain.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CodexioLtd/openai-api-sdk/584766f390964541c2a0138677038e5e06bfc937/openai-api-examples/src/main/resources/codi-image-to-explain.png
--------------------------------------------------------------------------------
/openai-api-examples/src/main/resources/editable-image-mask.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CodexioLtd/openai-api-sdk/584766f390964541c2a0138677038e5e06bfc937/openai-api-examples/src/main/resources/editable-image-mask.png
--------------------------------------------------------------------------------
/openai-api-examples/src/main/resources/editable-image.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CodexioLtd/openai-api-sdk/584766f390964541c2a0138677038e5e06bfc937/openai-api-examples/src/main/resources/editable-image.png
--------------------------------------------------------------------------------
/openai-api-examples/src/main/resources/fake-file.txt:
--------------------------------------------------------------------------------
1 | test
--------------------------------------------------------------------------------
/openai-api-examples/src/main/resources/image-for-variations.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CodexioLtd/openai-api-sdk/584766f390964541c2a0138677038e5e06bfc937/openai-api-examples/src/main/resources/image-for-variations.png
--------------------------------------------------------------------------------
/openai-api-examples/src/main/resources/log4j2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/openai-api-examples/src/main/resources/openai-credentials.json:
--------------------------------------------------------------------------------
1 | {
2 | "apiKey": "YOUR_API_KEY_HERE"
3 | }
4 |
--------------------------------------------------------------------------------
/openai-api-http/src/main/java/bg/codexio/ai/openai/api/http/CommonConstantsUtils.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.http;
2 |
3 | public class CommonConstantsUtils {
4 |
5 | public static final String ASSISTANTS_HEADER_NAME = "OpenAI-Beta";
6 | public static final String ASSISTANTS_HEADER_VALUE = "assistants=v1";
7 |
8 | private CommonConstantsUtils() {
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/openai-api-http/src/main/java/bg/codexio/ai/openai/api/http/HttpTimeout.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.http;
2 |
3 | import java.util.concurrent.TimeUnit;
4 |
5 | /**
6 | * Representation of an HTTP Timeout.
7 | * Can be used for all call, connect and read.
8 | */
9 | public record HttpTimeout(
10 | long period,
11 | TimeUnit timeUnit
12 | ) {}
13 |
--------------------------------------------------------------------------------
/openai-api-http/src/main/java/bg/codexio/ai/openai/api/http/HttpTimeouts.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.http;
2 |
3 | /**
4 | * Context object hinting the variety of timeouts
5 | */
6 | public record HttpTimeouts(
7 | HttpTimeout call,
8 | HttpTimeout connect,
9 | HttpTimeout read
10 | ) {}
11 |
--------------------------------------------------------------------------------
/openai-api-http/src/main/java/bg/codexio/ai/openai/api/http/exception/HttpCallFailedException.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.http.exception;
2 |
3 | public class HttpCallFailedException
4 | extends RuntimeException {
5 | private static final String MESSAGE = "HTTP call to %s failed.";
6 |
7 | public HttpCallFailedException(
8 | String url,
9 | Throwable cause
10 | ) {
11 | super(
12 | String.format(
13 | MESSAGE,
14 | url
15 | ),
16 | cause
17 | );
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/openai-api-http/src/main/java/bg/codexio/ai/openai/api/http/exception/OpenAIRespondedNot2xxException.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.http.exception;
2 |
3 | import bg.codexio.ai.openai.api.payload.error.ErrorResponseHolder;
4 |
5 | public class OpenAIRespondedNot2xxException
6 | extends RuntimeException {
7 |
8 | private final ErrorResponseHolder errorHolder;
9 | private final int httpStatusCode;
10 |
11 | public OpenAIRespondedNot2xxException(
12 | ErrorResponseHolder errorHolder,
13 | int httpStatusCode
14 | ) {
15 | super(String.format(
16 | "HTTP status: %d. Response: %s",
17 | httpStatusCode,
18 | errorHolder
19 | ));
20 |
21 | this.errorHolder = errorHolder;
22 | this.httpStatusCode = httpStatusCode;
23 | }
24 |
25 | public ErrorResponseHolder getErrorHolder() {
26 | return errorHolder;
27 | }
28 |
29 | public int getHttpStatusCode() {
30 | return httpStatusCode;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/openai-api-http/src/main/java/bg/codexio/ai/openai/api/http/exception/UnparseableRequestException.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.http.exception;
2 |
3 | public class UnparseableRequestException
4 | extends RuntimeException {
5 |
6 | private static final String MESSAGE =
7 | "Request could not be converted to " + "JSON.";
8 |
9 | public UnparseableRequestException(Throwable cause) {
10 | super(
11 | MESSAGE,
12 | cause
13 | );
14 | }
15 |
16 | public UnparseableRequestException() {
17 | super(MESSAGE);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/openai-api-http/src/main/java/bg/codexio/ai/openai/api/http/exception/UnparseableResponseException.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.http.exception;
2 |
3 | public class UnparseableResponseException
4 | extends RuntimeException {
5 |
6 | private static final String MESSAGE =
7 | "Response %s cannot be serialized " + "to %s.";
8 |
9 | public UnparseableResponseException(
10 | String rawResponse,
11 | Class> type,
12 | Throwable cause
13 | ) {
14 | super(
15 | String.format(
16 | MESSAGE,
17 | rawResponse,
18 | type.getName()
19 | ),
20 | cause
21 | );
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/openai-api-http/src/test/java/bg/codexio/ai/openai/api/http/CommonTestConstantsUtils.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.http;
2 |
3 | public class CommonTestConstantsUtils {
4 |
5 | public static final String TEST_BASE_URL = "http://base-url";
6 |
7 | private CommonTestConstantsUtils() {
8 | }
9 | }
--------------------------------------------------------------------------------
/openai-api-http/src/test/resources/fake-file.txt:
--------------------------------------------------------------------------------
1 | test
2 |
--------------------------------------------------------------------------------
/openai-api-http/src/test/resources/fake-image.png:
--------------------------------------------------------------------------------
1 | test
--------------------------------------------------------------------------------
/openai-api-models/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 |
8 | bg.codexio.ai
9 | openai-api
10 | 0.9.1.BETA-SNAPSHOT
11 |
12 |
13 | openai-api-models
14 | jar
15 |
16 |
17 | false
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/openai-api-models/src/main/java/bg/codexio/ai/openai/api/models/ModelType.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.models;
2 |
3 | @FunctionalInterface
4 | public interface ModelType {
5 |
6 | String name();
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/openai-api-models/src/main/java/bg/codexio/ai/openai/api/models/ModelTypeAbstract.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.models;
2 |
3 | public abstract class ModelTypeAbstract
4 | implements ModelType {
5 |
6 | private final String name;
7 |
8 | protected ModelTypeAbstract(String name) {
9 | this.name = name;
10 | }
11 |
12 | @Override
13 | public String name() {
14 | return this.name;
15 | }
16 |
17 | @Override
18 | public String toString() {
19 | return this.name();
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/openai-api-models/src/main/java/bg/codexio/ai/openai/api/models/dalle/DallE20.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.models.dalle;
2 |
3 | import bg.codexio.ai.openai.api.models.ModelTypeAbstract;
4 |
5 | /**
6 | * Image Model
7 | * Currently points to dall-e-2.
8 | */
9 | public class DallE20
10 | extends ModelTypeAbstract {
11 | public DallE20() {
12 | super("dall-e-2");
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/openai-api-models/src/main/java/bg/codexio/ai/openai/api/models/dalle/DallE30.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.models.dalle;
2 |
3 | import bg.codexio.ai.openai.api.models.ModelTypeAbstract;
4 |
5 | /**
6 | * Image Model
7 | * Currently points to dall-e-3.
8 | */
9 | public class DallE30
10 | extends ModelTypeAbstract {
11 | public DallE30() {
12 | super("dall-e-3");
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/openai-api-models/src/main/java/bg/codexio/ai/openai/api/models/tts/TTS1HDModel.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.models.tts;
2 |
3 | import bg.codexio.ai.openai.api.models.ModelTypeAbstract;
4 |
5 | /**
6 | * Text to speech model
7 | * Currently points to tts-1-hd.
8 | */
9 | public class TTS1HDModel
10 | extends ModelTypeAbstract {
11 | public TTS1HDModel() {
12 | super("tts-1-hd");
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/openai-api-models/src/main/java/bg/codexio/ai/openai/api/models/tts/TTS1Model.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.models.tts;
2 |
3 | import bg.codexio.ai.openai.api.models.ModelTypeAbstract;
4 |
5 | /**
6 | * Text to speech model
7 | * Currently points to tts-1.
8 | */
9 | public class TTS1Model
10 | extends ModelTypeAbstract {
11 | public TTS1Model() {
12 | super("tts-1");
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/openai-api-models/src/main/java/bg/codexio/ai/openai/api/models/v35/GPT35Turbo1106Model.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.models.v35;
2 |
3 | import bg.codexio.ai.openai.api.models.ModelTypeAbstract;
4 |
5 | /**
6 | * Updated GPT 3.5 TurboNew
7 | *
8 | * The latest GPT-3.5 Turbo model with improved instruction following, JSON
9 | * mode,
10 | * reproducible outputs, parallel function calling, and more.
11 | * Returns a maximum of 4,096 output tokens.
12 | *
13 | *
14 | * Context Window: 16,385 tokens
15 | *
16 | */
17 | public class GPT35Turbo1106Model
18 | extends ModelTypeAbstract {
19 | public GPT35Turbo1106Model() {
20 | super("gpt-3.5-turbo-1106");
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/openai-api-models/src/main/java/bg/codexio/ai/openai/api/models/v35/GPT35Turbo16kModel.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.models.v35;
2 |
3 | import bg.codexio.ai.openai.api.models.ModelTypeAbstract;
4 |
5 | /**
6 | * Currently points to gpt-3.5-turbo-0613.
7 | * Context Window: 16,385 tokens
8 | *
9 | * Will point to gpt-3.5-turbo-1106 starting Dec 11, 2023. See
10 | *
11 | */
12 | public class GPT35Turbo16kModel
13 | extends ModelTypeAbstract {
14 | public GPT35Turbo16kModel() {
15 | super("gpt-3.5-turbo-16k");
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/openai-api-models/src/main/java/bg/codexio/ai/openai/api/models/v35/GPT35TurboModel.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.models.v35;
2 |
3 | import bg.codexio.ai.openai.api.models.ModelTypeAbstract;
4 |
5 | /**
6 | * Currently points to gpt-3.5-turbo-0613.
7 | * Context Window: 4,096 tokens
8 | *
9 | * Will point to gpt-3.5-turbo-1106 starting Dec 11, 2023.
10 | *
11 | */
12 | public class GPT35TurboModel
13 | extends ModelTypeAbstract {
14 | public GPT35TurboModel() {
15 | super("gpt-3.5-turbo");
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/openai-api-models/src/main/java/bg/codexio/ai/openai/api/models/v40/GPT401106Model.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.models.v40;
2 |
3 | import bg.codexio.ai.openai.api.models.ModelTypeAbstract;
4 |
5 | /**
6 | * GPT-4 Turbo
7 | *
8 | * The latest GPT-4 model with improved instruction following, JSON mode,
9 | * reproducible outputs, parallel function calling, and more.
10 | * Returns a maximum of 4,096 output tokens.
11 | * This preview model is not yet suited for production traffic
12 | * Context Window: 128,000 tokens
13 | *
14 | */
15 | public class GPT401106Model
16 | extends ModelTypeAbstract {
17 | public GPT401106Model() {
18 | super("gpt-4-1106-preview");
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/openai-api-models/src/main/java/bg/codexio/ai/openai/api/models/v40/GPT4032kModel.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.models.v40;
2 |
3 | import bg.codexio.ai.openai.api.models.ModelTypeAbstract;
4 |
5 | /**
6 | * Currently points to gpt-4-32k-0613.
7 | * Context Window: 32,768 tokens
8 | */
9 | public class GPT4032kModel
10 | extends ModelTypeAbstract {
11 | public GPT4032kModel() {
12 | super("gpt-4-32k");
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/openai-api-models/src/main/java/bg/codexio/ai/openai/api/models/v40/GPT40Model.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.models.v40;
2 |
3 | import bg.codexio.ai.openai.api.models.ModelTypeAbstract;
4 |
5 | /**
6 | * Currently points to gpt-4-0613.
7 | * Context Window: 8,192 tokens
8 | */
9 | public class GPT40Model
10 | extends ModelTypeAbstract {
11 | public GPT40Model() {
12 | super("gpt-4");
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/openai-api-models/src/main/java/bg/codexio/ai/openai/api/models/v40/GPT40VisionPreviewModel.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.models.v40;
2 |
3 | import bg.codexio.ai.openai.api.models.ModelTypeAbstract;
4 |
5 | /**
6 | * Currently points to gpt-4-vision-preview
7 | * A 1024 x 1024 square image in detail: high mode costs 765 tokens
8 | */
9 | public class GPT40VisionPreviewModel
10 | extends ModelTypeAbstract {
11 | public GPT40VisionPreviewModel() {
12 | super("gpt-4-vision-preview");
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/openai-api-models/src/main/java/bg/codexio/ai/openai/api/models/whisper/Whisper10.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.models.whisper;
2 |
3 | import bg.codexio.ai.openai.api.models.ModelTypeAbstract;
4 |
5 | /**
6 | * Speech to text model
7 | * Currently points to whisper-1.
8 | */
9 | public class Whisper10
10 | extends ModelTypeAbstract {
11 | public Whisper10() {
12 | super("whisper-1");
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/openai-api-models/src/test/java/bg/codexio/ai/openai/api/models/ModelTypeAbstractTest.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.models;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import static org.junit.jupiter.api.Assertions.assertAll;
6 | import static org.junit.jupiter.api.Assertions.assertEquals;
7 |
8 | public class ModelTypeAbstractTest {
9 |
10 | @Test
11 | public void testConstructor_expectCorrectModelName() {
12 | var model = new ModelTypeAbstract("test-model") {};
13 |
14 | assertAll(
15 | () -> assertEquals(
16 | "test-model",
17 | model.name()
18 | ),
19 | () -> assertEquals(
20 | "test-model",
21 | model.toString()
22 | )
23 | );
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/openai-api-models/src/test/java/bg/codexio/ai/openai/api/models/dalle/DallE20Test.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.models.dalle;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import static org.junit.jupiter.api.Assertions.assertEquals;
6 |
7 | public class DallE20Test {
8 |
9 | @Test
10 | public void testConstructor_expectCorrectModelName() {
11 | assertEquals(
12 | "dall-e-2",
13 | new DallE20().name()
14 | );
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/openai-api-models/src/test/java/bg/codexio/ai/openai/api/models/dalle/DallE30Test.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.models.dalle;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import static org.junit.jupiter.api.Assertions.assertEquals;
6 |
7 | public class DallE30Test {
8 |
9 | @Test
10 | public void testConstructor_expectCorrectModelName() {
11 | assertEquals(
12 | "dall-e-3",
13 | new DallE30().name()
14 | );
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/openai-api-models/src/test/java/bg/codexio/ai/openai/api/models/tts/TTS1HDModelTest.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.models.tts;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import static org.junit.jupiter.api.Assertions.assertEquals;
6 |
7 | public class TTS1HDModelTest {
8 |
9 | @Test
10 | public void testConstructor_expectCorrectModelName() {
11 | assertEquals(
12 | "tts-1-hd",
13 | new TTS1HDModel().name()
14 | );
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/openai-api-models/src/test/java/bg/codexio/ai/openai/api/models/tts/TTS1ModelTest.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.models.tts;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import static org.junit.jupiter.api.Assertions.assertEquals;
6 |
7 | public class TTS1ModelTest {
8 |
9 | @Test
10 | public void testConstructor_expectCorrectModelName() {
11 | assertEquals(
12 | "tts-1",
13 | new TTS1Model().name()
14 | );
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/openai-api-models/src/test/java/bg/codexio/ai/openai/api/models/v35/GPT35Turbo1106ModelTest.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.models.v35;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import static org.junit.jupiter.api.Assertions.assertEquals;
6 |
7 | public class GPT35Turbo1106ModelTest {
8 |
9 | @Test
10 | public void testConstructor_expectCorrectModelName() {
11 | assertEquals(
12 | "gpt-3.5-turbo-1106",
13 | new GPT35Turbo1106Model().name()
14 | );
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/openai-api-models/src/test/java/bg/codexio/ai/openai/api/models/v35/GPT35Turbo16kModelTest.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.models.v35;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import static org.junit.jupiter.api.Assertions.assertEquals;
6 |
7 | public class GPT35Turbo16kModelTest {
8 |
9 | @Test
10 | public void testConstructor_expectCorrectModelName() {
11 | assertEquals(
12 | "gpt-3.5-turbo-16k",
13 | new GPT35Turbo16kModel().name()
14 | );
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/openai-api-models/src/test/java/bg/codexio/ai/openai/api/models/v35/GPT35TurboModelTest.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.models.v35;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import static org.junit.jupiter.api.Assertions.assertEquals;
6 |
7 | public class GPT35TurboModelTest {
8 |
9 | @Test
10 | public void testConstructor_expectCorrectModelName() {
11 | assertEquals(
12 | "gpt-3.5-turbo",
13 | new GPT35TurboModel().name()
14 | );
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/openai-api-models/src/test/java/bg/codexio/ai/openai/api/models/v40/GPT401105ModelTest.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.models.v40;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import static org.junit.jupiter.api.Assertions.assertEquals;
6 |
7 | public class GPT401105ModelTest {
8 |
9 | @Test
10 | public void testConstructor_expectCorrectModelName() {
11 | assertEquals(
12 | "gpt-4-1106-preview",
13 | new GPT401106Model().name()
14 | );
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/openai-api-models/src/test/java/bg/codexio/ai/openai/api/models/v40/GPT40302kModelTest.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.models.v40;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import static org.junit.jupiter.api.Assertions.assertEquals;
6 |
7 | public class GPT40302kModelTest {
8 |
9 | @Test
10 | public void testConstructor_expectCorrectModelName() {
11 | assertEquals(
12 | "gpt-4-32k",
13 | new GPT4032kModel().name()
14 | );
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/openai-api-models/src/test/java/bg/codexio/ai/openai/api/models/v40/GPT40ModelTest.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.models.v40;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import static org.junit.jupiter.api.Assertions.assertEquals;
6 |
7 | public class GPT40ModelTest {
8 |
9 | @Test
10 | public void testConstructor_expectCorrectModelName() {
11 | assertEquals(
12 | "gpt-4",
13 | new GPT40Model().name()
14 | );
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/openai-api-models/src/test/java/bg/codexio/ai/openai/api/models/v40/GPT40VisionPreviewModelTest.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.models.v40;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import static org.junit.jupiter.api.Assertions.assertEquals;
6 |
7 | public class GPT40VisionPreviewModelTest {
8 |
9 | @Test
10 | public void testConstructor_expectCorrectModelName() {
11 | assertEquals(
12 | "gpt-4-vision-preview",
13 | new GPT40VisionPreviewModel().name()
14 | );
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/openai-api-models/src/test/java/bg/codexio/ai/openai/api/models/whisper/Whisper10Test.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.models.whisper;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import static org.junit.jupiter.api.Assertions.assertEquals;
6 |
7 | public class Whisper10Test {
8 |
9 | @Test
10 | public void testConstructor_expectCorrectModelName() {
11 | assertEquals(
12 | "whisper-1",
13 | new Whisper10().name()
14 | );
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/openai-api-payload/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 |
8 | bg.codexio.ai
9 | openai-api
10 | 0.9.1.BETA-SNAPSHOT
11 |
12 |
13 | openai-api-payload
14 | jar
15 |
16 |
17 | false
18 |
19 |
20 |
21 |
22 |
23 | com.fasterxml.jackson.core
24 | jackson-annotations
25 | 2.16.0
26 | compile
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/MetadataUtils.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 | import java.util.Objects;
6 |
7 | public class MetadataUtils {
8 | public static Map addMetadata(
9 | Map originalMetadata,
10 | String... metadata
11 | ) {
12 | if (metadata.length % 2 != 0) {
13 | throw new IllegalArgumentException(
14 | "Metadata needs to contain at " + "least 2 arguments.");
15 | }
16 |
17 | var metadataMap = Objects.requireNonNullElse(
18 | originalMetadata,
19 | new HashMap()
20 | );
21 | for (int i = 0; i < metadata.length - 1; i += 2) {
22 | metadataMap.put(
23 | metadata[i],
24 | metadata[i + 1]
25 | );
26 | }
27 |
28 | return metadataMap;
29 | }
30 | }
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/Streamable.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload;
2 |
3 | /**
4 | * Represents a request objects
5 | * that may belong to a streamable API.
6 | * This does not necessary means,
7 | * that Streaming is supported by this object,
8 | * hence the {@link #stream()} method.
9 | */
10 | public interface Streamable {
11 |
12 | boolean stream();
13 | }
14 |
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/assistant/response/AssistantResponse.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.assistant.response;
2 |
3 | import bg.codexio.ai.openai.api.payload.Mergeable;
4 | import bg.codexio.ai.openai.api.payload.assistant.tool.AssistantTool;
5 |
6 | import java.util.List;
7 | import java.util.Map;
8 |
9 | public record AssistantResponse(
10 | String id,
11 | String object,
12 | Integer createdAt,
13 | String name,
14 | String description,
15 | String model,
16 | String instructions,
17 | List tools,
18 | List fileIds,
19 | Map metadata
20 | )
21 | implements Mergeable {
22 |
23 | @Override
24 | public AssistantResponse merge(AssistantResponse other) {
25 | if (other == null) {
26 | return this;
27 | }
28 |
29 | return other;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/assistant/tool/AssistantTool.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.assistant.tool;
2 |
3 | import com.fasterxml.jackson.annotation.JsonTypeInfo;
4 |
5 | @FunctionalInterface
6 | @JsonTypeInfo(
7 | use = JsonTypeInfo.Id.NAME, property = "type"
8 | )
9 | public interface AssistantTool {
10 | String type();
11 | }
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/assistant/tool/AssistantToolAbstract.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.assistant.tool;
2 |
3 | public abstract class AssistantToolAbstract
4 | implements AssistantTool {
5 |
6 | private final String type;
7 |
8 | protected AssistantToolAbstract(String type) {
9 | this.type = type;
10 | }
11 |
12 | @Override
13 | public String type() {
14 | return this.type;
15 | }
16 |
17 | @Override
18 | public String toString() {
19 | return this.type();
20 | }
21 | }
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/assistant/tool/CodeInterpreter.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.assistant.tool;
2 |
3 | public class CodeInterpreter
4 | extends AssistantToolAbstract {
5 |
6 | public CodeInterpreter() {
7 | super("code_interpreter");
8 | }
9 | }
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/assistant/tool/Retrieval.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.assistant.tool;
2 |
3 | public class Retrieval
4 | extends AssistantToolAbstract {
5 | public Retrieval() {
6 | super("retrieval");
7 | }
8 | }
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/chat/ChatFunction.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.chat;
2 |
3 | import bg.codexio.ai.openai.api.payload.chat.request.ChatTool;
4 |
5 | import java.util.Map;
6 |
7 | /**
8 | * Representation of a function as per
9 | * Defining functions
10 | */
11 | public class ChatFunction {
12 | private final String description;
13 | private final String name;
14 | private final Map parameters;
15 | private final ChatTool.ChatToolChoice choice;
16 |
17 | public ChatFunction(
18 | String description,
19 | String name,
20 | Map parameters,
21 | ChatTool.ChatToolChoice choice
22 | ) {
23 | this.description = description;
24 | this.name = name;
25 | this.parameters = parameters;
26 | this.choice = choice;
27 | }
28 |
29 | public String getDescription() {
30 | return description;
31 | }
32 |
33 | public String getName() {
34 | return name;
35 | }
36 |
37 | public Map getParameters() {
38 | return parameters;
39 | }
40 |
41 | public ChatTool.ChatToolChoice asChoice() {
42 | return this.choice;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/chat/ChatMessage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.chat;
2 |
3 | import bg.codexio.ai.openai.api.payload.chat.response.ToolCallResponse;
4 |
5 | import java.util.List;
6 | import java.util.Objects;
7 |
8 | public record ChatMessage(
9 | String role,
10 | String content,
11 | List toolCalls
12 | ) {
13 |
14 | @Override
15 | public String role() {
16 | return Objects.requireNonNullElse(
17 | this.role,
18 | "user"
19 | );
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/chat/request/ChatTool.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.chat.request;
2 |
3 | public interface ChatTool {
4 | String getType();
5 |
6 | ChatToolChoice asChoice();
7 |
8 | interface ChatToolChoice {
9 | String type();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/chat/request/FunctionChoice.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.chat.request;
2 |
3 | public interface FunctionChoice {
4 | String name();
5 | }
6 |
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/chat/request/FunctionTool.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.chat.request;
2 |
3 | import bg.codexio.ai.openai.api.payload.chat.ChatFunction;
4 |
5 | public record FunctionTool(
6 | ChatFunction function
7 | )
8 | implements ChatTool {
9 |
10 | @Override
11 | public String getType() {
12 | return "function";
13 | }
14 |
15 | @Override
16 | public ChatToolChoice asChoice() {
17 | return null;
18 | }
19 |
20 | public record FunctionToolChoice(FunctionChoice function)
21 | implements ChatToolChoice {
22 | @Override
23 | public String type() {
24 | return "function";
25 | }
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/chat/response/ChatUsageResponse.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.chat.response;
2 |
3 | import bg.codexio.ai.openai.api.payload.Mergeable;
4 |
5 | public record ChatUsageResponse(
6 | int promptTokens,
7 | int completionTokens,
8 | int totalTokens
9 | )
10 | implements Mergeable {
11 |
12 | public static ChatUsageResponse empty() {
13 | return new ChatUsageResponse(
14 | 0,
15 | 0,
16 | 0
17 | );
18 | }
19 |
20 | @Override
21 | public ChatUsageResponse merge(ChatUsageResponse other) {
22 | return new ChatUsageResponse(
23 | this.promptTokens() + other.promptTokens(),
24 | this.completionTokens() + other.completionTokens(),
25 | this.totalTokens() + other.totalTokens()
26 | );
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/chat/response/FunctionResponse.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.chat.response;
2 |
3 | import bg.codexio.ai.openai.api.payload.Mergeable;
4 |
5 | import java.util.Objects;
6 |
7 | public record FunctionResponse(
8 | String name,
9 | String arguments
10 | )
11 | implements Mergeable {
12 |
13 | public static FunctionResponse empty() {
14 | return new FunctionResponse(
15 | null,
16 | null
17 | );
18 | }
19 |
20 | @Override
21 | public FunctionResponse merge(FunctionResponse other) {
22 | return new FunctionResponse(
23 | this.name() != null
24 | ? this.name()
25 | : other.name(),
26 | Objects.requireNonNullElse(
27 | this.arguments(),
28 | ""
29 | ) + Objects.requireNonNullElse(
30 | other.arguments(),
31 | ""
32 | )
33 | );
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/chat/response/Logprobs.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.chat.response;
2 |
3 | import bg.codexio.ai.openai.api.payload.Mergeable;
4 |
5 | import java.util.List;
6 | import java.util.Objects;
7 |
8 | public record Logprobs(
9 | List content
10 | )
11 | implements Mergeable {
12 |
13 | @Override
14 | public Logprobs merge(Logprobs other) {
15 | return new Logprobs(Objects.requireNonNullElse(
16 | this.content,
17 | other.content
18 | ));
19 | }
20 | }
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/chat/response/ToolCallResponse.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.chat.response;
2 |
3 | import bg.codexio.ai.openai.api.payload.Mergeable;
4 |
5 | import java.util.Objects;
6 |
7 | public record ToolCallResponse(
8 | Integer index,
9 | String id,
10 | String type,
11 | FunctionResponse function
12 |
13 | )
14 | implements Mergeable {
15 |
16 | public static ToolCallResponse empty() {
17 | return new ToolCallResponse(
18 | null,
19 | null,
20 | null,
21 | FunctionResponse.empty()
22 | );
23 | }
24 |
25 | @Override
26 | public ToolCallResponse merge(ToolCallResponse other) {
27 | return new ToolCallResponse(
28 | this.index() != null
29 | ? this.index()
30 | : other.index(),
31 | this.id() != null
32 | ? this.id()
33 | : other.id(),
34 | this.type() != null
35 | ? this.type()
36 | : other.type(),
37 | Objects.requireNonNullElse(
38 | this.function(),
39 | FunctionResponse.empty()
40 | )
41 | .merge(Objects.requireNonNullElse(
42 | other.function(),
43 | FunctionResponse.empty()
44 | ))
45 | );
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/creativity/Creativity.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.creativity;
2 |
3 | public enum Creativity {
4 | TRULY_DETERMINISTIC(0.0),
5 | MOSTLY_DETERMINISTIC(0.1),
6 | INTRODUCE_SOME_RANDOMNESS(0.2),
7 | FIRST_JUMP_TO_CREATIVITY(0.3),
8 | INTRODUCE_UNIQUENESS(0.4),
9 | BALANCE_BETWEEN_NOVELTY_AND_PREDICTABILITY(0.5),
10 | BE_LESS_OBVIOUS(0.6),
11 | INVENTIVE_AND_UNEXPECTED(0.7),
12 | I_AM_WRITING_SONGS(0.8),
13 | DONT_TRUST_ME(0.9),
14 | I_HAVE_NO_IDEA_WHAT_I_AM_TALKING(1.0);
15 |
16 |
17 | private final double value;
18 |
19 | Creativity(double value) {
20 | this.value = value;
21 | }
22 |
23 | public double val() {
24 | return this.value;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/creativity/RepetitionPenalty.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.creativity;
2 |
3 | public enum RepetitionPenalty {
4 | REPEAT_A_LOT(0.0),
5 | REUSE_VOCABULARY(0.1),
6 | SLIGHT_REPETITION_DISCOURAGE(0.2),
7 | CONSTRAINTS_GOT_VISIBLE(0.3),
8 | ALMOST_GOOD(0.4),
9 | REDUCED_REDUNDANCY(0.5),
10 | ENCOURAGE_COHERENCY(0.6),
11 | DISCOURAGE_REPETITION(0.7),
12 | SOPHISTICATED_VOCABULARY(0.8),
13 | HARDLY_REPEATS(0.9),
14 | NEVER_REPEATS(1.0);
15 |
16 |
17 | private final double value;
18 |
19 | RepetitionPenalty(double value) {
20 | this.value = value;
21 | }
22 |
23 | public double val() {
24 | return this.value;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/environment/AvailableEnvironmentVariables.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.environment;
2 |
3 | /**
4 | * This enum acts as a list of all available
5 | * environment variables that you can provide.
6 | */
7 | public enum AvailableEnvironmentVariables {
8 | OPENAI_API_BASE_URL,
9 | OPENAI_API_KEY,
10 | OPENAI_ORG_ID,
11 | OPENAI_LOGGING_ENABLED,
12 | OPENAI_LOGGING_LEVEL
13 | }
14 |
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/error/ErrorResponse.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.error;
2 |
3 | public record ErrorResponse(
4 | String message,
5 | String type,
6 | String param,
7 | String code
8 | ) {}
9 |
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/error/ErrorResponseHolder.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.error;
2 |
3 | public record ErrorResponseHolder(
4 | ErrorResponse error
5 | ) {}
6 |
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/file/purpose/AssistantPurpose.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.file.purpose;
2 |
3 | public class AssistantPurpose
4 | extends PurposeAbstract {
5 |
6 | public AssistantPurpose() {
7 | super("assistants");
8 | }
9 | }
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/file/purpose/Purpose.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.file.purpose;
2 |
3 | public interface Purpose {
4 | String name();
5 | }
6 |
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/file/purpose/PurposeAbstract.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.file.purpose;
2 |
3 | public abstract class PurposeAbstract
4 | implements Purpose {
5 |
6 | private final String name;
7 |
8 | protected PurposeAbstract(String name) {
9 | this.name = name;
10 | }
11 |
12 | @Override
13 | public String name() {
14 | return this.name;
15 | }
16 | }
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/file/request/UploadFileRequest.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.file.request;
2 |
3 | import bg.codexio.ai.openai.api.payload.Streamable;
4 |
5 | import java.io.File;
6 |
7 | public record UploadFileRequest(
8 | File file,
9 | String purpose
10 | )
11 | implements Streamable {
12 |
13 | public static Builder builder() {
14 | return new Builder(
15 | null,
16 | null
17 | );
18 | }
19 |
20 | @Override
21 | public boolean stream() {
22 | return false;
23 | }
24 |
25 | public record Builder(
26 | File file,
27 | String purpose
28 | ) {
29 | public Builder withFile(File file) {
30 | return new Builder(
31 | file,
32 | purpose
33 | );
34 | }
35 |
36 | public Builder withPurpose(String purpose) {
37 | return new Builder(
38 | file,
39 | purpose
40 | );
41 | }
42 |
43 | public UploadFileRequest build() {
44 | return new UploadFileRequest(
45 | file,
46 | purpose
47 | );
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/file/response/FileContentResponse.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.file.response;
2 |
3 | import bg.codexio.ai.openai.api.payload.Mergeable;
4 |
5 | import java.util.Arrays;
6 | import java.util.Objects;
7 |
8 | public record FileContentResponse(
9 | byte[] bytes
10 | )
11 | implements Mergeable {
12 | @Override
13 | public FileContentResponse merge(FileContentResponse other) {
14 | return new FileContentResponse(Objects.requireNonNullElse(
15 | other.bytes,
16 | this.bytes
17 | ));
18 | }
19 |
20 | @Override
21 | public boolean equals(Object object) {
22 | if (this == object) {
23 | return true;
24 | }
25 | if (object == null || getClass() != object.getClass()) {
26 | return false;
27 | }
28 | FileContentResponse that = (FileContentResponse) object;
29 | return Arrays.equals(
30 | bytes,
31 | that.bytes
32 | );
33 | }
34 |
35 | @Override
36 | public int hashCode() {
37 | return Arrays.hashCode(bytes);
38 | }
39 | }
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/file/response/FileResponse.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.file.response;
2 |
3 | import bg.codexio.ai.openai.api.payload.Mergeable;
4 |
5 | public record FileResponse(
6 | String id,
7 | String object,
8 | Integer bytes,
9 | Integer createdAt,
10 | String filename,
11 | String purpose
12 | )
13 | implements Mergeable {
14 | @Override
15 | public FileResponse merge(FileResponse other) {
16 | if (other == null) {
17 | return this;
18 | }
19 |
20 | return new FileResponse(
21 | this.id,
22 | this.object,
23 | this.bytes,
24 | this.createdAt,
25 | this.filename,
26 | this.purpose
27 | );
28 | }
29 | }
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/images/Dimensions.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.images;
2 |
3 | public enum Dimensions {
4 | SQUARE_256("256x256"),
5 | SQUARE_512("512x512"),
6 | SQUARE_1024("1024x1024"),
7 | LANDSCAPE_1792("1792x1024"),
8 | PORTRAIT_1792("1024x1792");
9 |
10 | private final String size;
11 |
12 | Dimensions(String size) {
13 | this.size = size;
14 | }
15 |
16 | public String val() {
17 | return this.size;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/images/Format.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.images;
2 |
3 | import java.util.Arrays;
4 |
5 | public enum Format {
6 | BASE_64("b64_json"),
7 | URL("url");
8 |
9 | private final String value;
10 |
11 | Format(String value) {
12 | this.value = value;
13 | }
14 |
15 | public static Format fromVal(String text) {
16 | return Arrays.stream(Format.values())
17 | .filter(format -> format.value.equalsIgnoreCase(text))
18 | .findFirst()
19 | .orElseThrow(() -> new IllegalArgumentException(
20 | "No constant with text " + text + " found"));
21 | }
22 |
23 | public String val() {
24 | return this.value;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/images/Quality.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.images;
2 |
3 | public enum Quality {
4 | STANDARD("standard"),
5 | HIGH_QUALITY("hd");
6 |
7 | private final String value;
8 |
9 | Quality(String value) {
10 | this.value = value;
11 | }
12 |
13 | public String val() {
14 | return this.value;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/images/Style.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.images;
2 |
3 | public enum Style {
4 | HYPER_REAL("vivid"),
5 | NATURAL("natural");
6 |
7 | private final String value;
8 |
9 | Style(String value) {
10 | this.value = value;
11 | }
12 |
13 | public String val() {
14 | return this.value;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/images/request/CreateImageRequest.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.images.request;
2 |
3 | import bg.codexio.ai.openai.api.payload.Streamable;
4 |
5 | public record CreateImageRequest(
6 | String prompt,
7 | String model,
8 | Integer n,
9 | String quality,
10 | String responseFormat,
11 | String size,
12 | String style,
13 | String user
14 | )
15 | implements Streamable,
16 | ImageRequest {
17 | @Override
18 | public boolean stream() {
19 | return false;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/images/request/EditImageRequest.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.images.request;
2 |
3 | import java.io.File;
4 |
5 | public record EditImageRequest(
6 | File image,
7 | String prompt,
8 | File mask,
9 | String model,
10 | Integer n,
11 | String size,
12 | String responseFormat,
13 | String user
14 | )
15 | implements ImageRequest {
16 | @Override
17 | public boolean stream() {
18 | return false;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/images/request/ImageRequest.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.images.request;
2 |
3 | import bg.codexio.ai.openai.api.payload.Streamable;
4 |
5 | public interface ImageRequest
6 | extends Streamable {
7 | String prompt();
8 |
9 | String model();
10 |
11 | Integer n();
12 |
13 | String responseFormat();
14 |
15 | String size();
16 |
17 | String user();
18 | }
19 |
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/images/request/ImageVariationRequest.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.images.request;
2 |
3 | import bg.codexio.ai.openai.api.payload.Streamable;
4 |
5 | import java.io.File;
6 |
7 | public record ImageVariationRequest(
8 | File image,
9 | String prompt,
10 | String model,
11 | Integer n,
12 | String size,
13 | String responseFormat,
14 | String user
15 | )
16 | implements ImageRequest,
17 | Streamable {
18 | @Override
19 | public boolean stream() {
20 | return false;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/images/response/ImageResponse.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.images.response;
2 |
3 | import bg.codexio.ai.openai.api.payload.Mergeable;
4 |
5 | import java.util.Objects;
6 |
7 | public record ImageResponse(
8 | String b64Json,
9 | String url,
10 | String revisedPrompt
11 | )
12 | implements Mergeable {
13 | public static ImageResponse empty() {
14 | return new ImageResponse(
15 | null,
16 | null,
17 | null
18 | );
19 | }
20 |
21 | @Override
22 | public ImageResponse merge(ImageResponse other) {
23 | return new ImageResponse(
24 | Objects.requireNonNullElse(
25 | this.b64Json(),
26 | other.b64Json()
27 | ),
28 | Objects.requireNonNullElse(
29 | this.url(),
30 | other.url()
31 | ),
32 | Objects.requireNonNullElse(
33 | this.revisedPrompt(),
34 | other.revisedPrompt()
35 | )
36 | );
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/message/content/ImageFileContent.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.message.content;
2 |
3 | import com.fasterxml.jackson.annotation.JsonCreator;
4 |
5 | public class ImageFileContent
6 | extends MessageContentAbstract {
7 |
8 | private final String fileId;
9 |
10 | @JsonCreator
11 | public ImageFileContent(String fileId) {
12 | super("image_file");
13 | this.fileId = fileId;
14 | }
15 |
16 | public String getFileId() {
17 | return fileId;
18 | }
19 | }
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/message/content/MessageContent.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.message.content;
2 |
3 | import com.fasterxml.jackson.annotation.JsonSubTypes;
4 | import com.fasterxml.jackson.annotation.JsonTypeInfo;
5 |
6 | // find way to load interface implementations dynamically
7 | @JsonTypeInfo(
8 | use = JsonTypeInfo.Id.NAME, property = "type"
9 | )
10 | @JsonSubTypes(
11 | {
12 | @JsonSubTypes.Type(
13 | value = TextMessageContent.class, name = "text"
14 | ), @JsonSubTypes.Type(
15 | value = ImageFileContent.class, name = "image_file"
16 | )
17 | }
18 | )
19 | public interface MessageContent {
20 | String type();
21 | }
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/message/content/MessageContentAbstract.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.message.content;
2 |
3 | public abstract class MessageContentAbstract
4 | implements MessageContent {
5 |
6 | private final String type;
7 |
8 | protected MessageContentAbstract(String type) {
9 | this.type = type;
10 | }
11 |
12 | @Override
13 | public String type() {
14 | return this.type;
15 | }
16 |
17 | @Override
18 | public String toString() {
19 | return this.type;
20 | }
21 | }
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/message/content/TextContent.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.message.content;
2 |
3 | import bg.codexio.ai.openai.api.payload.message.content.annotation.Annotation;
4 |
5 | import java.util.List;
6 |
7 | public record TextContent(
8 | String value,
9 | List annotations
10 | ) {}
11 |
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/message/content/TextMessageContent.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.message.content;
2 |
3 | import com.fasterxml.jackson.annotation.JsonCreator;
4 | import com.fasterxml.jackson.annotation.JsonProperty;
5 |
6 | public class TextMessageContent
7 | extends MessageContentAbstract {
8 |
9 | private final TextContent text;
10 |
11 | @JsonCreator
12 | public TextMessageContent(@JsonProperty("text") TextContent text) {
13 | super("text");
14 | this.text = text;
15 | }
16 |
17 | public TextContent getText() {
18 | return text;
19 | }
20 | }
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/message/content/annotation/Annotation.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.message.content.annotation;
2 |
3 | import com.fasterxml.jackson.annotation.JsonSubTypes;
4 | import com.fasterxml.jackson.annotation.JsonTypeInfo;
5 |
6 | // find way to load interface implementations dynamically
7 | @JsonTypeInfo(
8 | use = JsonTypeInfo.Id.NAME, property = "type"
9 | )
10 | @JsonSubTypes(
11 | {
12 | @JsonSubTypes.Type(
13 | value = FileCitationAnnotation.class,
14 | name = "file_citation"
15 | ), @JsonSubTypes.Type(
16 | value = FilePathAnnotation.class, name = "file_path"
17 | )
18 | }
19 | )
20 | public interface Annotation {
21 | String type();
22 |
23 | String text();
24 |
25 | Integer startIndex();
26 |
27 | Integer endIndex();
28 | }
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/message/content/annotation/AnnotationAbstract.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.message.content.annotation;
2 |
3 | public abstract class AnnotationAbstract
4 | implements Annotation {
5 |
6 | private final String type;
7 | private final String text;
8 | private final Integer startIndex;
9 | private final Integer endIndex;
10 |
11 | protected AnnotationAbstract(
12 | String type,
13 | String text,
14 | Integer startIndex,
15 | Integer endIndex
16 | ) {
17 | this.type = type;
18 | this.text = text;
19 | this.startIndex = startIndex;
20 | this.endIndex = endIndex;
21 | }
22 |
23 | @Override
24 | public String type() {
25 | return this.type;
26 | }
27 |
28 | @Override
29 | public String text() {
30 | return this.text;
31 | }
32 |
33 | @Override
34 | public Integer startIndex() {
35 | return this.startIndex;
36 | }
37 |
38 | @Override
39 | public Integer endIndex() {
40 | return this.endIndex;
41 | }
42 | }
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/message/content/annotation/FileCitation.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.message.content.annotation;
2 |
3 | public record FileCitation(
4 | String fileId,
5 | String quote
6 | ) {}
7 |
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/message/content/annotation/FileCitationAnnotation.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.message.content.annotation;
2 |
3 | import com.fasterxml.jackson.annotation.JsonCreator;
4 | import com.fasterxml.jackson.annotation.JsonProperty;
5 |
6 | public class FileCitationAnnotation
7 | extends AnnotationAbstract {
8 |
9 | private final FileCitation fileCitation;
10 |
11 | @JsonCreator
12 | public FileCitationAnnotation(
13 | @JsonProperty("text") String text,
14 | @JsonProperty("start_index") Integer startIndex,
15 | @JsonProperty("end_index") Integer endIndex,
16 | @JsonProperty("file_citation") FileCitation fileCitation
17 | ) {
18 | super(
19 | "file_citation",
20 | text,
21 | startIndex,
22 | endIndex
23 | );
24 | this.fileCitation = fileCitation;
25 | }
26 |
27 | public FileCitation getFileCitation() {
28 | return fileCitation;
29 | }
30 | }
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/message/content/annotation/FilePath.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.message.content.annotation;
2 |
3 | public record FilePath(
4 | String fileId
5 | ) {}
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/message/content/annotation/FilePathAnnotation.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.message.content.annotation;
2 |
3 | import com.fasterxml.jackson.annotation.JsonCreator;
4 | import com.fasterxml.jackson.annotation.JsonProperty;
5 |
6 | public class FilePathAnnotation
7 | extends AnnotationAbstract {
8 |
9 | private final FilePath filePath;
10 |
11 | @JsonCreator
12 | public FilePathAnnotation(
13 | @JsonProperty("text") String text,
14 | @JsonProperty("start_index") Integer startIndex,
15 | @JsonProperty("end_index") Integer endIndex,
16 | @JsonProperty("file_path") FilePath filePath
17 | ) {
18 | super(
19 | "file_path",
20 | text,
21 | startIndex,
22 | endIndex
23 | );
24 | this.filePath = filePath;
25 | }
26 |
27 | public FilePath getFilePath() {
28 | return filePath;
29 | }
30 | }
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/message/response/ListMessagesResponse.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.message.response;
2 |
3 | import bg.codexio.ai.openai.api.payload.Mergeable;
4 |
5 | import java.util.List;
6 | import java.util.Objects;
7 |
8 | public record ListMessagesResponse(
9 | String object,
10 | List data,
11 | String firstId,
12 | String lastId,
13 | Boolean hasMore
14 | )
15 | implements Mergeable {
16 |
17 | @Override
18 | public ListMessagesResponse merge(ListMessagesResponse other) {
19 | if (Objects.isNull(other)) {
20 | return this;
21 | }
22 |
23 | return null;
24 | }
25 | }
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/message/response/MessageResponse.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.message.response;
2 |
3 | import bg.codexio.ai.openai.api.payload.Mergeable;
4 | import bg.codexio.ai.openai.api.payload.message.content.MessageContent;
5 |
6 | import java.util.List;
7 | import java.util.Map;
8 | import java.util.Objects;
9 |
10 | public record MessageResponse(
11 | String id,
12 | String object,
13 | Integer createdAt,
14 | String threadId,
15 | String role,
16 | List content,
17 | String assistantId,
18 | String runId,
19 | List fileIds,
20 | Map metadata
21 | )
22 | implements Mergeable {
23 |
24 | @Override
25 | public MessageResponse merge(MessageResponse other) {
26 | if (Objects.isNull(other)) {
27 | return this;
28 | }
29 |
30 | return null;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/run/response/RunnableResponse.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.run.response;
2 |
3 | import bg.codexio.ai.openai.api.payload.Mergeable;
4 | import bg.codexio.ai.openai.api.payload.assistant.tool.AssistantTool;
5 | import bg.codexio.ai.openai.api.payload.run.response.action.RequiredAction;
6 | import bg.codexio.ai.openai.api.payload.run.response.error.LastError;
7 |
8 | import java.util.List;
9 | import java.util.Map;
10 |
11 | public record RunnableResponse(
12 | String id,
13 | String object,
14 | Integer createdAt,
15 | String assistantId,
16 | String threadId,
17 | String status,
18 | RequiredAction requiredAction,
19 | LastError lastError,
20 | Integer expiresAt,
21 | Integer startedAt,
22 | Integer cancelledAt,
23 | Integer failedAt,
24 | Integer completedAt,
25 | String model,
26 | String instructions,
27 | List tools,
28 | List fileIds,
29 | Map metadata
30 | )
31 | implements Mergeable {
32 | @Override
33 | public RunnableResponse merge(RunnableResponse other) {
34 | if (other == null) {
35 | return this;
36 | }
37 |
38 | return null;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/run/response/action/Function.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.run.response.action;
2 |
3 | public record Function(
4 | String name,
5 | String arguments
6 | ) {}
7 |
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/run/response/action/RequiredAction.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.run.response.action;
2 |
3 | import java.util.Objects;
4 |
5 | public record RequiredAction(
6 | String type,
7 | SubmitToolOutput submitToolOutput
8 | ) {
9 | @Override
10 | public String type() {
11 | return Objects.requireNonNullElse(
12 | this.type,
13 | "submit_tool_outputs"
14 | );
15 | }
16 | }
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/run/response/action/SubmitToolOutput.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.run.response.action;
2 |
3 | import java.util.List;
4 |
5 | public record SubmitToolOutput(
6 | List toolCalls
7 | ) {}
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/run/response/action/ToolCall.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.run.response.action;
2 |
3 | public record ToolCall(
4 | String id,
5 | String type,
6 | Function function
7 | ) {}
8 |
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/run/response/error/LastError.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.run.response.error;
2 |
3 | public record LastError(
4 | String code,
5 | String message
6 | ) {}
7 |
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/thread/request/ThreadCreationRequest.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.thread.request;
2 |
3 | import bg.codexio.ai.openai.api.payload.Streamable;
4 | import bg.codexio.ai.openai.api.payload.message.request.MessageRequest;
5 |
6 | import java.util.List;
7 | import java.util.Map;
8 |
9 | public record ThreadCreationRequest(
10 | List messages,
11 | Map metadata
12 | )
13 | implements Streamable,
14 | ThreadRequest {
15 |
16 | @Override
17 | public boolean stream() {
18 | return false;
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/thread/request/ThreadModificationRequest.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.thread.request;
2 |
3 | import bg.codexio.ai.openai.api.payload.Streamable;
4 |
5 | import java.util.Map;
6 |
7 | public record ThreadModificationRequest(
8 | Map metadata
9 | )
10 | implements Streamable,
11 | ThreadRequest {
12 | @Override
13 | public boolean stream() {
14 | return false;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/thread/request/ThreadRequest.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.thread.request;
2 |
3 | import bg.codexio.ai.openai.api.payload.Streamable;
4 |
5 | import java.util.Map;
6 |
7 | public interface ThreadRequest
8 | extends Streamable {
9 | Map metadata();
10 | }
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/thread/response/ThreadResponse.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.thread.response;
2 |
3 | import bg.codexio.ai.openai.api.payload.Mergeable;
4 |
5 | import java.util.Map;
6 |
7 | public record ThreadResponse(
8 | String id,
9 | String object,
10 | Integer createdAt,
11 | Map metadata
12 | )
13 | implements Mergeable {
14 | @Override
15 | public ThreadResponse merge(ThreadResponse other) {
16 | if (other == null) {
17 | return this;
18 | }
19 |
20 | return null;
21 | }
22 | }
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/vision/DetailedAnalyze.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.vision;
2 |
3 | public enum DetailedAnalyze {
4 | HIGH("high"),
5 | LOW("low");
6 |
7 | private final String detail;
8 |
9 | DetailedAnalyze(String detail) {
10 | this.detail = detail;
11 | }
12 |
13 | public String val() {
14 | return this.detail;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/vision/request/ImageUrlMessageRequest.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.vision.request;
2 |
3 | public record ImageUrlMessageRequest(
4 | ImageUrlRequest imageUrl
5 | )
6 | implements VisionMessage {
7 | @Override
8 | public String getType() {
9 | return "image_url";
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/vision/request/MessageContentHolder.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.vision.request;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | public record MessageContentHolder(
7 | List content
8 | ) {
9 | public String getRole() {
10 | return "user";
11 | }
12 |
13 | public MessageContentHolder withContent(VisionMessage message) {
14 | var content = new ArrayList<>(this.content());
15 | content.add(message);
16 |
17 | return new MessageContentHolder(content);
18 | }
19 |
20 | public MessageContentHolder withContentOn(
21 | int index,
22 | VisionMessage message
23 | ) {
24 | var content = new ArrayList<>(this.content());
25 | content.set(
26 | index,
27 | message
28 | );
29 |
30 | return new MessageContentHolder(content);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/vision/request/QuestionVisionRequest.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.vision.request;
2 |
3 | public record QuestionVisionRequest(String text)
4 | implements VisionMessage {
5 | @Override
6 | public String getType() {
7 | return "text";
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/vision/request/VisionMessage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.vision.request;
2 |
3 | public interface VisionMessage {
4 | String getType();
5 | }
6 |
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/voice/AudioFormat.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.voice;
2 |
3 | public enum AudioFormat {
4 | MP3("mp3"),
5 | OPUS("opus"),
6 | AAC("acc"),
7 | FLAC("flac");
8 |
9 | private final String format;
10 |
11 | AudioFormat(String format) {
12 | this.format = format;
13 | }
14 |
15 | public String val() {
16 | return this.format;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/voice/Speaker.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.voice;
2 |
3 | public enum Speaker {
4 | ALLOY("alloy"),
5 | ECHO("echo"),
6 | FABLE("fable"),
7 | ONYX("onyx"),
8 | NOVA("nova"),
9 | SHIMMER("shimmer");
10 |
11 | private final String name;
12 |
13 | Speaker(String name) {
14 | this.name = name;
15 | }
16 |
17 | public String val() {
18 | return this.name;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/voice/Speed.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.voice;
2 |
3 | public enum Speed {
4 | VERY_SLOW(0.25),
5 | HALF_SLOW(0.50),
6 | NORMAL(1.00),
7 | HALF_FASTER(1.50),
8 | TWICE_FASTER(2.00),
9 | VERY_FAST(4.00);
10 |
11 | private final double value;
12 |
13 | Speed(double value) {
14 | this.value = value;
15 | }
16 |
17 | public double val() {
18 | return this.value;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/openai-api-payload/src/main/java/bg/codexio/ai/openai/api/payload/voice/response/AudioBinaryResponse.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.payload.voice.response;
2 |
3 | import bg.codexio.ai.openai.api.payload.Mergeable;
4 |
5 | import java.util.Arrays;
6 | import java.util.Objects;
7 |
8 | /**
9 | * Represents an
10 | * Audio#response
10 | */
11 | public record SpeechTextResponse(
12 | String text
13 | )
14 | implements Mergeable {
15 | @Override
16 | public SpeechTextResponse merge(SpeechTextResponse other) {
17 | return new SpeechTextResponse(Objects.requireNonNullElse(
18 | this.text(),
19 | ""
20 | ) + Objects.requireNonNullElse(
21 | other.text(),
22 | ""
23 | ));
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/openai-api-sdk/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 |
8 | bg.codexio.ai
9 | openai-api
10 | 0.9.1.BETA-SNAPSHOT
11 |
12 |
13 | openai-api-sdk
14 | jar
15 |
16 |
17 | false
18 |
19 |
20 |
21 |
22 |
23 | bg.codexio.ai
24 | openai-api-http
25 | 0.9.1.BETA-SNAPSHOT
26 |
27 |
28 |
29 | com.squareup.okhttp3
30 | okhttp
31 | 5.0.0-alpha.12
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/Authenticator.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk;
2 |
3 | import bg.codexio.ai.openai.api.sdk.auth.FromEnvironment;
4 | import bg.codexio.ai.openai.api.sdk.auth.FromJson;
5 | import bg.codexio.ai.openai.api.sdk.auth.SdkAuth;
6 | import bg.codexio.ai.openai.api.sdk.auth.exception.NotValidAuthenticationMethod;
7 |
8 | import java.util.List;
9 | import java.util.function.Function;
10 |
11 | public final class Authenticator {
12 |
13 | /**
14 | * Authentication methods it will be tested against,
15 | * when using {@link #autoAuthenticate(Function)} ()}.
16 | */
17 | public static final List DEFAULT_AUTHENTICATIONS = List.of(
18 | FromEnvironment.AUTH,
19 | FromJson.AUTH
20 | );
21 |
22 | private Authenticator() {
23 | }
24 |
25 | public static T autoAuthenticate(Function authDelegate) {
26 | var error = new NotValidAuthenticationMethod(
27 | "None of the default " + "authentication " + "methods "
28 | + "worked.");
29 | for (var auth : DEFAULT_AUTHENTICATIONS) {
30 | try {
31 | return authDelegate.apply(auth);
32 | } catch (NotValidAuthenticationMethod e) {
33 | error.addCause(e);
34 | }
35 | }
36 |
37 | throw error;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/IntermediateStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk;
2 |
3 | /**
4 | * Marker Interface for all stages that are not {@link TerminalStage}
5 | */
6 | public interface IntermediateStage {}
7 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/ObjectMapperSubtypesRegistrationUtils.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk;
2 |
3 | import bg.codexio.ai.openai.api.http.DefaultOpenAIHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.Mergeable;
5 | import bg.codexio.ai.openai.api.payload.Streamable;
6 | import bg.codexio.ai.openai.api.payload.assistant.tool.AssistantTool;
7 | import com.fasterxml.jackson.databind.jsontype.NamedType;
8 |
9 | import java.util.List;
10 |
11 | public final class ObjectMapperSubtypesRegistrationUtils {
12 |
13 | private ObjectMapperSubtypesRegistrationUtils() {
14 | }
15 |
16 | public static > void registerAssistantTools(
17 | DefaultOpenAIHttpExecutor executor,
18 | List assistantTools
19 | ) {
20 | assistantTools.forEach(tool -> executor.configureMappingExternally(objectMapper -> objectMapper.registerSubtypes(new NamedType(
21 | tool.getClass(),
22 | tool.type()
23 | ))));
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/Processing.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk;
2 |
3 | /**
4 | * Processing type. Usually defines whether
5 | * server-sent events (REAL_TIME) to be used
6 | * or not.
7 | */
8 | public enum Processing {
9 | REAL_TIME(true),
10 | BATCH(false),
11 | DEFAULT(BATCH.val());
12 |
13 | private final boolean stream;
14 |
15 | Processing(boolean stream) {
16 | this.stream = stream;
17 | }
18 |
19 | public boolean val() {
20 | return this.stream;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/RuntimeExecutor.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk;
2 |
3 | /**
4 | * Marker interface for stages that send requests
5 | * on behalf of a runtime - synchronously, asynchronously or reactive.
6 | */
7 | public interface RuntimeExecutor {}
8 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/RuntimeSelectionStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk;
2 |
3 | /**
4 | * Defines all the ways the underlying runtime should act.
5 | */
6 | public interface RuntimeSelectionStage {
7 |
8 | RuntimeExecutor immediate();
9 |
10 | RuntimeExecutor async();
11 |
12 | RuntimeExecutor reactive();
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/StartStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk;
2 |
3 | public interface StartStage {}
4 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/TerminalStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk;
2 |
3 | /**
4 | * Stages which provide the ability to bypass further configurations
5 | * and go to selecting a runtime. This naturally applies to the last
6 | * stage in the chain as well.
7 | */
8 | public interface TerminalStage {
9 |
10 | RuntimeSelectionStage andRespond();
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/ThreadOperationUtils.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk;
2 |
3 | public final class ThreadOperationUtils {
4 |
5 | private ThreadOperationUtils() {
6 | }
7 |
8 | public static void sleep(Long millis) throws InterruptedException {
9 | Thread.sleep(millis);
10 | }
11 | }
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/assistant/AIModelStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.assistant;
2 |
3 | import bg.codexio.ai.openai.api.http.assistant.AssistantHttpExecutor;
4 | import bg.codexio.ai.openai.api.models.ModelType;
5 | import bg.codexio.ai.openai.api.models.v35.GPT35TurboModel;
6 | import bg.codexio.ai.openai.api.models.v40.GPT401106Model;
7 | import bg.codexio.ai.openai.api.models.v40.GPT40Model;
8 | import bg.codexio.ai.openai.api.payload.assistant.request.AssistantRequest;
9 |
10 | public class AIModelStage
11 | extends AssistantConfigurationStage {
12 |
13 | AIModelStage(
14 | AssistantHttpExecutor httpExecutor,
15 | AssistantRequest.Builder requestBuilder
16 | ) {
17 | super(
18 | httpExecutor,
19 | requestBuilder
20 | );
21 | }
22 |
23 | public ToolStage poweredBy(ModelType modelType) {
24 | return new ToolStage(
25 | this.httpExecutor,
26 | this.requestBuilder.withModel(modelType.name())
27 | );
28 | }
29 |
30 | public ToolStage poweredByGPT35() {
31 | return this.poweredBy(new GPT35TurboModel());
32 | }
33 |
34 | public ToolStage poweredByGPT40() {
35 | return this.poweredBy(new GPT40Model());
36 | }
37 |
38 | public ToolStage turboPowered() {
39 | return this.poweredBy(new GPT401106Model());
40 | }
41 | }
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/assistant/AssistantAdvancedConfigurationStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.assistant;
2 |
3 | import bg.codexio.ai.openai.api.http.assistant.AssistantHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.assistant.request.AssistantRequest;
5 | import bg.codexio.ai.openai.api.payload.assistant.response.AssistantResponse;
6 |
7 | public class AssistantAdvancedConfigurationStage
8 | extends AssistantConfigurationStage {
9 |
10 | AssistantAdvancedConfigurationStage(
11 | AssistantHttpExecutor httpExecutor,
12 | AssistantRequest.Builder requestBuilder
13 | ) {
14 | super(
15 | httpExecutor,
16 | requestBuilder
17 | );
18 | }
19 |
20 | public AssistantFileStage file() {
21 | return new AssistantFileStage(
22 | this.httpExecutor,
23 | this.requestBuilder
24 | );
25 | }
26 |
27 | public AssistantMetaStage meta() {
28 | return new AssistantMetaStage(
29 | this.httpExecutor,
30 | this.requestBuilder
31 | );
32 | }
33 |
34 | public AssistantDescriptionStage description() {
35 | return new AssistantDescriptionStage(
36 | this.httpExecutor,
37 | this.requestBuilder
38 | );
39 | }
40 |
41 | public AssistantResponse andRespond() {
42 | return this.httpExecutor.execute(this.requestBuilder.build());
43 | }
44 | }
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/assistant/AssistantConfigurationStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.assistant;
2 |
3 | import bg.codexio.ai.openai.api.http.assistant.AssistantHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.assistant.request.AssistantRequest;
5 |
6 | public abstract class AssistantConfigurationStage {
7 |
8 | protected final AssistantHttpExecutor httpExecutor;
9 | protected final AssistantRequest.Builder requestBuilder;
10 |
11 | AssistantConfigurationStage(
12 | AssistantHttpExecutor httpExecutor,
13 | AssistantRequest.Builder requestBuilder
14 | ) {
15 | this.httpExecutor = httpExecutor;
16 | this.requestBuilder = requestBuilder;
17 | }
18 | }
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/assistant/AssistantDescriptionStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.assistant;
2 |
3 | import bg.codexio.ai.openai.api.http.assistant.AssistantHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.assistant.request.AssistantRequest;
5 |
6 | public class AssistantDescriptionStage
7 | extends AssistantConfigurationStage {
8 |
9 | AssistantDescriptionStage(
10 | AssistantHttpExecutor httpExecutor,
11 | AssistantRequest.Builder requestBuilder
12 | ) {
13 | super(
14 | httpExecutor,
15 | requestBuilder
16 | );
17 | }
18 |
19 | public AssistantAdvancedConfigurationStage context(String description) {
20 | return new AssistantAdvancedConfigurationStage(
21 | this.httpExecutor,
22 | this.requestBuilder.withDescription(description)
23 | );
24 | }
25 | }
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/assistant/AssistantInstructionStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.assistant;
2 |
3 | import bg.codexio.ai.openai.api.http.assistant.AssistantHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.assistant.request.AssistantRequest;
5 |
6 | public class AssistantInstructionStage
7 | extends AssistantConfigurationStage {
8 |
9 | AssistantInstructionStage(
10 | AssistantHttpExecutor httpExecutor,
11 | AssistantRequest.Builder requestBuilder
12 | ) {
13 | super(
14 | httpExecutor,
15 | requestBuilder
16 | );
17 | }
18 |
19 | public AssistantAdvancedConfigurationStage instruct(String instruction) {
20 | return new AssistantAdvancedConfigurationStage(
21 | this.httpExecutor,
22 | this.requestBuilder.withInstructions(instruction)
23 | );
24 | }
25 | }
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/assistant/AssistantMetaStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.assistant;
2 |
3 | import bg.codexio.ai.openai.api.http.assistant.AssistantHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.assistant.request.AssistantRequest;
5 |
6 | public class AssistantMetaStage
7 | extends AssistantInstructionStage {
8 |
9 | AssistantMetaStage(
10 | AssistantHttpExecutor httpExecutor,
11 | AssistantRequest.Builder requestBuilder
12 | ) {
13 | super(
14 | httpExecutor,
15 | requestBuilder
16 | );
17 | }
18 |
19 | public AssistantAdvancedConfigurationStage awareOf(String... metadata) {
20 | return new AssistantAdvancedConfigurationStage(
21 | this.httpExecutor,
22 | this.requestBuilder.addMetadata(metadata)
23 | );
24 | }
25 | }
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/assistant/AssistantNameStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.assistant;
2 |
3 | import bg.codexio.ai.openai.api.http.assistant.AssistantHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.assistant.request.AssistantRequest;
5 |
6 | public class AssistantNameStage
7 | extends AssistantConfigurationStage {
8 |
9 | AssistantNameStage(
10 | AssistantHttpExecutor httpExecutor,
11 | AssistantRequest.Builder requestBuilder
12 | ) {
13 | super(
14 | httpExecutor,
15 | requestBuilder
16 | );
17 | }
18 |
19 | public AssistantInstructionStage called(String name) {
20 | return new AssistantInstructionStage(
21 | this.httpExecutor,
22 | this.requestBuilder.withName(name)
23 | );
24 | }
25 | }
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/assistant/ToolStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.assistant;
2 |
3 | import bg.codexio.ai.openai.api.http.assistant.AssistantHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.assistant.request.AssistantRequest;
5 | import bg.codexio.ai.openai.api.payload.assistant.tool.AssistantTool;
6 | import bg.codexio.ai.openai.api.sdk.ObjectMapperSubtypesRegistrationUtils;
7 |
8 | import java.util.Arrays;
9 |
10 | public class ToolStage
11 | extends AssistantConfigurationStage {
12 |
13 | ToolStage(
14 | AssistantHttpExecutor httpExecutor,
15 | AssistantRequest.Builder requestBuilder
16 | ) {
17 | super(
18 | httpExecutor,
19 | requestBuilder
20 | );
21 | }
22 |
23 | public AssistantNameStage from(AssistantTool... assistantTool) {
24 | ObjectMapperSubtypesRegistrationUtils.registerAssistantTools(
25 | this.httpExecutor,
26 | Arrays.asList(assistantTool)
27 | );
28 |
29 | return new AssistantNameStage(
30 | this.httpExecutor,
31 | this.requestBuilder.withTools(Arrays.asList(assistantTool))
32 | );
33 | }
34 | }
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/auth/FromDeveloper.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.auth;
2 |
3 | import bg.codexio.ai.openai.api.payload.credentials.ApiCredentials;
4 |
5 | /**
6 | * Use this for manually passing the credentials and still
7 | * conforming the {@link SdkAuth} contract.
8 | */
9 | public class FromDeveloper
10 | implements SdkAuth {
11 |
12 | private final ApiCredentials apiCredentials;
13 |
14 | FromDeveloper(ApiCredentials apiCredentials) {
15 | this.apiCredentials = apiCredentials;
16 | }
17 |
18 | /**
19 | * Factory function to by as close as possible
20 | * to the other {@link SdkAuth} implementations.
21 | *
22 | * @param apiCredentials {@link ApiCredentials}
23 | * @return new instance of the current class with configured credentials
24 | */
25 | public static FromDeveloper doPass(ApiCredentials apiCredentials) {
26 | return new FromDeveloper(apiCredentials);
27 | }
28 |
29 | /**
30 | * @return ready for usage instance of {@link ApiCredentials}
31 | */
32 | @Override
33 | public ApiCredentials credentials() {
34 | return this.apiCredentials;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/auth/SdkAuth.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.auth;
2 |
3 | import bg.codexio.ai.openai.api.payload.credentials.ApiCredentials;
4 | import bg.codexio.ai.openai.api.sdk.auth.exception.NotValidAuthenticationMethod;
5 |
6 | /**
7 | * This interface provider an instance of {@link ApiCredentials}
8 | * It can have multiple implementations according to the way the api
9 | * key is provided to the application
10 | * As easy for implementation it is, this library provides the following
11 | * default implementation for immediate usage:
12 | *
13 | * - {@link FromDeveloper}
14 | * - {@link FromEnvironment}
15 | * - {@link FromJson}
16 | *
17 | * As this is a {@link FunctionalInterface} it can also be implemented
18 | * as a lambda (supplier) in the notation of () -> new ApiCredentials(..
19 | * .)
20 | */
21 | @FunctionalInterface
22 | public interface SdkAuth {
23 | /**
24 | * @return {@link ApiCredentials}
25 | * @throws NotValidAuthenticationMethod if the API Key is not found as it
26 | * is an integral part of the
27 | * authentication
28 | */
29 | ApiCredentials credentials();
30 | }
31 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/auth/exception/NotValidAuthenticationMethod.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.auth.exception;
2 |
3 | import bg.codexio.ai.openai.api.sdk.auth.SdkAuth;
4 |
5 | /**
6 | * Usually thrown by {@link SdkAuth} if integral parts
7 | * of the authentication are missing.
8 | */
9 | public class NotValidAuthenticationMethod
10 | extends RuntimeException {
11 |
12 | private NotValidAuthenticationMethod cause;
13 | private NotValidAuthenticationMethod lastCause;
14 |
15 | public NotValidAuthenticationMethod(String message) {
16 | super(message);
17 | }
18 |
19 | /**
20 | * Used if more than one {@link SdkAuth} methods are provided
21 | * to collect all of their errors in one exception.
22 | *
23 | * @param cause {@link NotValidAuthenticationMethod} thrown by previous
24 | * {@link SdkAuth#credentials()} call.
25 | */
26 | public void addCause(NotValidAuthenticationMethod cause) {
27 | if (this.cause == null) {
28 | this.setCause(cause);
29 | } else {
30 | this.lastCause.setCause(cause);
31 | }
32 |
33 | this.lastCause = cause;
34 | }
35 |
36 | public Throwable getCause() {
37 | return this.cause;
38 | }
39 |
40 | private void setCause(NotValidAuthenticationMethod cause) {
41 | this.cause = cause;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/auth/util/StringUtil.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.auth.util;
2 |
3 | public final class StringUtil {
4 |
5 | private StringUtil() {
6 |
7 | }
8 |
9 | public static boolean isNullOrBlank(String str) {
10 | return str == null || str.trim()
11 | .isEmpty();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/chat/AsyncPromise.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.chat;
2 |
3 | import bg.codexio.ai.openai.api.http.chat.ChatHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.chat.request.ChatMessageRequest;
5 |
6 | import java.util.function.Consumer;
7 |
8 | /**
9 | * Promise abstraction.
10 | * Accepts a callback which will be called
11 | * when response is received.
12 | */
13 | public class AsyncPromise
14 | extends ChatConfigurationStage {
15 |
16 | AsyncPromise(
17 | ChatHttpExecutor executor,
18 | ChatMessageRequest.Builder requestBuilder
19 | ) {
20 | super(
21 | executor,
22 | requestBuilder
23 | );
24 | }
25 |
26 | /**
27 | * Subscribe to the answer
28 | *
29 | * @param onResponse a callback that receives the string answer
30 | */
31 | public void then(Consumer onResponse) {
32 | this.executor.executeAsync(
33 | this.requestBuilder.build(),
34 | x -> {
35 | },
36 | r -> onResponse.accept(r.choices()
37 | .get(0)
38 | .message()
39 | .content())
40 | );
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/chat/ChatConfigurationStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.chat;
2 |
3 | import bg.codexio.ai.openai.api.http.chat.ChatHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.chat.request.ChatMessageRequest;
5 |
6 | /**
7 | * Base for all Chat stages
8 | */
9 | public abstract class ChatConfigurationStage {
10 |
11 | protected final ChatHttpExecutor executor;
12 | protected final ChatMessageRequest.Builder requestBuilder;
13 |
14 | ChatConfigurationStage(
15 | ChatHttpExecutor executor,
16 | ChatMessageRequest.Builder requestBuilder
17 | ) {
18 | this.executor = executor;
19 | this.requestBuilder = requestBuilder;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/chat/SimplifiedStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.chat;
2 |
3 | import bg.codexio.ai.openai.api.http.HttpExecutorContext;
4 | import bg.codexio.ai.openai.api.payload.credentials.ApiCredentials;
5 | import bg.codexio.ai.openai.api.sdk.auth.SdkAuth;
6 | import com.fasterxml.jackson.databind.ObjectMapper;
7 |
8 | /**
9 | * A simplified stage where some things
10 | * such as AI Model Type and creativity
11 | * are already configured.
12 | */
13 | public class SimplifiedStage {
14 |
15 | private final ApiCredentials credentials;
16 |
17 | public SimplifiedStage(SdkAuth auth) {
18 | this.credentials = auth.credentials();
19 | }
20 |
21 | /**
22 | * Go ahead to directly ask question by preconfiguring
23 | * the AI Model Type and the creativity level and receiving a synchronous
24 | * response
25 | *
26 | * @return {@link ChatRuntimeSelectionStage}
27 | */
28 | public ImmediateContextStage simply() {
29 | return Chat.authenticate(new HttpExecutorContext(credentials))
30 | .understanding(new ObjectMapper())
31 | .poweredByGPT35()
32 | .predictable()
33 | .andRespond()
34 | .immediate();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/chat/constant/ExceptionMessageConstants.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.chat.constant;
2 |
3 | public class ExceptionMessageConstants {
4 |
5 | public static final String TOP_LOGPROBS_OUT_OF_RANGE = "The value "
6 | + "specifying tokens to return at each token position must be "
7 | + "between 0 and 5.";
8 |
9 | private ExceptionMessageConstants() {
10 | }
11 | }
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/chat/exception/TopLogprobsOutOfRangeException.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.chat.exception;
2 |
3 | import static bg.codexio.ai.openai.api.sdk.chat.constant.ExceptionMessageConstants.TOP_LOGPROBS_OUT_OF_RANGE;
4 |
5 | public class TopLogprobsOutOfRangeException
6 | extends RuntimeException {
7 | public TopLogprobsOutOfRangeException() {
8 | super(TOP_LOGPROBS_OUT_OF_RANGE);
9 | }
10 | }
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/file/FileConfigurationStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.file;
2 |
3 | import bg.codexio.ai.openai.api.http.DefaultOpenAIHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.Mergeable;
5 | import bg.codexio.ai.openai.api.payload.file.request.UploadFileRequest;
6 |
7 | public abstract class FileConfigurationStage> {
8 |
9 | protected final DefaultOpenAIHttpExecutor executor;
10 | protected final UploadFileRequest.Builder requestBuilder;
11 |
12 | FileConfigurationStage(
13 | DefaultOpenAIHttpExecutor executor,
14 | UploadFileRequest.Builder requestBuilder
15 | ) {
16 | this.executor = executor;
17 | this.requestBuilder = requestBuilder;
18 | }
19 | }
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/file/FileDownloadingNameTypeStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.file;
2 |
3 | import bg.codexio.ai.openai.api.http.DefaultOpenAIHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.Mergeable;
5 | import bg.codexio.ai.openai.api.payload.file.request.UploadFileRequest;
6 |
7 | public class FileDownloadingNameTypeStage>
8 | extends FileConfigurationStage {
9 |
10 | private final String fileId;
11 |
12 | public FileDownloadingNameTypeStage(
13 | DefaultOpenAIHttpExecutor executor,
14 | UploadFileRequest.Builder requestBuilder,
15 | String fileId
16 | ) {
17 | super(
18 | executor,
19 | requestBuilder
20 | );
21 | this.fileId = fileId;
22 | }
23 |
24 | public FileDownloadingStage as(String fileName) {
25 | return new FileDownloadingStage<>(
26 | this.executor,
27 | this.requestBuilder,
28 | this.fileId,
29 | fileName
30 | );
31 | }
32 | }
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/file/FileDownloadingStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.file;
2 |
3 | import bg.codexio.ai.openai.api.http.DefaultOpenAIHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.Mergeable;
5 | import bg.codexio.ai.openai.api.payload.file.request.UploadFileRequest;
6 | import bg.codexio.ai.openai.api.payload.file.response.FileContentResponse;
7 |
8 | import java.io.File;
9 | import java.io.IOException;
10 |
11 | public class FileDownloadingStage>
12 | extends FileConfigurationStage {
13 |
14 | private final String fileId;
15 | private final String fileName;
16 |
17 | FileDownloadingStage(
18 | DefaultOpenAIHttpExecutor executor,
19 | UploadFileRequest.Builder requestBuilder,
20 | String fileId,
21 | String fileName
22 | ) {
23 | super(
24 | executor,
25 | requestBuilder
26 | );
27 | this.fileId = fileId;
28 | this.fileName = fileName;
29 | }
30 |
31 | public File toFolder(File targetFolder) throws IOException {
32 | return DownloadExecutor.downloadTo(
33 | targetFolder,
34 | (FileContentResponse) this.executor.executeWithPathVariables(fileId),
35 | this.fileName
36 | );
37 | }
38 | }
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/file/FileSimplified.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.file;
2 |
3 | import bg.codexio.ai.openai.api.payload.file.response.FileResponse;
4 |
5 | import java.io.File;
6 |
7 | public final class FileSimplified {
8 |
9 | private FileSimplified() {
10 | }
11 |
12 | public static String simply(File file) {
13 | return Files.defaults()
14 | .and()
15 | .upload()
16 | .forAssistants()
17 | .feed(file);
18 | }
19 |
20 | public static FileResponse simplyRaw(File file) {
21 | return Files.defaults()
22 | .and()
23 | .upload()
24 | .forAssistants()
25 | .feedRaw(file);
26 | }
27 | }
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/file/FileTargetingStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.file;
2 |
3 | import bg.codexio.ai.openai.api.http.DefaultOpenAIHttpExecutor;
4 | import bg.codexio.ai.openai.api.http.file.UploadFileHttpExecutor;
5 | import bg.codexio.ai.openai.api.payload.Mergeable;
6 | import bg.codexio.ai.openai.api.payload.file.purpose.AssistantPurpose;
7 | import bg.codexio.ai.openai.api.payload.file.purpose.Purpose;
8 | import bg.codexio.ai.openai.api.payload.file.request.UploadFileRequest;
9 |
10 | public class FileTargetingStage>
11 | extends FileConfigurationStage {
12 |
13 | FileTargetingStage(
14 | DefaultOpenAIHttpExecutor executor,
15 | UploadFileRequest.Builder requestContext
16 | ) {
17 | super(
18 | executor,
19 | requestContext
20 | );
21 | }
22 |
23 | public FileUploadingStage targeting(Purpose purpose) {
24 | return new FileUploadingStage(
25 | (UploadFileHttpExecutor) this.executor,
26 | this.requestBuilder.withPurpose(purpose.name())
27 | );
28 | }
29 |
30 | public FileUploadingStage forAssistants() {
31 | return this.targeting(new AssistantPurpose());
32 | }
33 | }
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/file/FileUploadingStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.file;
2 |
3 | import bg.codexio.ai.openai.api.http.file.UploadFileHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.file.request.UploadFileRequest;
5 | import bg.codexio.ai.openai.api.payload.file.response.FileResponse;
6 |
7 | import java.io.File;
8 |
9 | public class FileUploadingStage {
10 |
11 | private final UploadFileHttpExecutor executor;
12 | private final UploadFileRequest.Builder requestBuilder;
13 |
14 | public FileUploadingStage(
15 | UploadFileHttpExecutor executor,
16 | UploadFileRequest.Builder requestContext
17 | ) {
18 | this.executor = executor;
19 | this.requestBuilder = requestContext;
20 | }
21 |
22 | public FileResponse feedRaw(File file) {
23 | return this.executor.execute(this.requestBuilder.withFile(file)
24 | .build());
25 | }
26 |
27 | public String feed(File file) {
28 | return this.feedRaw(file)
29 | .id();
30 | }
31 | }
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/images/AsyncApi.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.images;
2 |
3 | import bg.codexio.ai.openai.api.http.DefaultOpenAIHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.images.request.ImageRequest;
5 | import bg.codexio.ai.openai.api.payload.images.request.ImageRequestBuilder;
6 | import bg.codexio.ai.openai.api.payload.images.response.ImageDataResponse;
7 | import bg.codexio.ai.openai.api.sdk.RuntimeExecutor;
8 |
9 | /**
10 | * Reactive API to add a final instruction and proceed with the HTTP call.
11 | */
12 | public class AsyncApi
13 | extends ImageConfigurationStage
14 | implements RuntimeExecutor,
15 | ImagesPromptStage> {
16 |
17 | AsyncApi(
18 | DefaultOpenAIHttpExecutor executor,
19 | ImageRequestBuilder builder
20 | ) {
21 | super(
22 | executor,
23 | builder
24 | );
25 | }
26 |
27 | /**
28 | * @param prompt the instruction for the model, most important and
29 | * mandatory part of the configuration
30 | * @return {@link AsyncExecutor} to handle the HTTP response
31 | */
32 | public AsyncExecutor generate(String prompt) {
33 | return new AsyncExecutor(
34 | this.executor,
35 | this.builder.withPrompt(prompt)
36 | );
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/images/ImageConfigurationStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.images;
2 |
3 | import bg.codexio.ai.openai.api.http.DefaultOpenAIHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.images.request.ImageRequest;
5 | import bg.codexio.ai.openai.api.payload.images.request.ImageRequestBuilder;
6 | import bg.codexio.ai.openai.api.payload.images.response.ImageDataResponse;
7 |
8 | /**
9 | * Base for all Image stages
10 | */
11 | public class ImageConfigurationStage {
12 |
13 | protected DefaultOpenAIHttpExecutor executor;
14 | protected ImageRequestBuilder builder;
15 |
16 | public ImageConfigurationStage(
17 | DefaultOpenAIHttpExecutor executor,
18 | ImageRequestBuilder builder
19 | ) {
20 | this.executor = executor;
21 | this.builder = builder;
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/images/ImagesPromptStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.images;
2 |
3 | import bg.codexio.ai.openai.api.sdk.RuntimeExecutor;
4 |
5 | public interface ImagesPromptStage {
6 |
7 | E generate(String prompt);
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/images/ReactiveApi.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.images;
2 |
3 | import bg.codexio.ai.openai.api.http.DefaultOpenAIHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.images.request.ImageRequest;
5 | import bg.codexio.ai.openai.api.payload.images.request.ImageRequestBuilder;
6 | import bg.codexio.ai.openai.api.payload.images.response.ImageDataResponse;
7 | import bg.codexio.ai.openai.api.sdk.RuntimeExecutor;
8 |
9 | /**
10 | * Reactive API to add a final instruction and proceed with the HTTP call.
11 | */
12 | public class ReactiveApi
13 | extends ImageConfigurationStage
14 | implements RuntimeExecutor,
15 | ImagesPromptStage> {
16 |
17 | ReactiveApi(
18 | DefaultOpenAIHttpExecutor executor,
19 | ImageRequestBuilder builder
20 | ) {
21 | super(
22 | executor,
23 | builder
24 | );
25 | }
26 |
27 | /**
28 | * @param prompt the instruction for the model, most important and
29 | * mandatory part of the configuration
30 | * @return {@link ReactiveExecutor} to handle the HTTP response
31 | */
32 | public ReactiveExecutor generate(String prompt) {
33 | return new ReactiveExecutor<>(
34 | this.executor,
35 | this.builder.withPrompt(prompt)
36 | );
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/images/SynchronousApi.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.images;
2 |
3 | import bg.codexio.ai.openai.api.http.DefaultOpenAIHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.images.request.ImageRequest;
5 | import bg.codexio.ai.openai.api.payload.images.request.ImageRequestBuilder;
6 | import bg.codexio.ai.openai.api.payload.images.response.ImageDataResponse;
7 | import bg.codexio.ai.openai.api.sdk.RuntimeExecutor;
8 |
9 | /**
10 | * Synchronous API to add a final instruction and proceed with the HTTP call.
11 | */
12 | public class SynchronousApi
13 | extends ImageConfigurationStage
14 | implements RuntimeExecutor,
15 | ImagesPromptStage> {
16 |
17 | SynchronousApi(
18 | DefaultOpenAIHttpExecutor executor,
19 | ImageRequestBuilder builder
20 | ) {
21 | super(
22 | executor,
23 | builder
24 | );
25 | }
26 |
27 | /**
28 | * @param prompt the instruction for the model, most important and
29 | * mandatory part of the configuration
30 | * @return {@link SynchronousExecutor} to handle the HTTP response
31 | */
32 | public SynchronousExecutor generate(String prompt) {
33 | return new SynchronousExecutor(
34 | this.executor,
35 | this.builder.withPrompt(prompt)
36 | );
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/images/color/PopularColor.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.images.color;
2 |
3 | public enum PopularColor {
4 | RED(0x00FF0000),
5 | GREEN(0x00008000),
6 | BLUE(0x000000FF),
7 | YELLOW(0x00FFFF00),
8 | PURPLE(0x00800080),
9 | CYAN(0x0000FFFF),
10 | MAGENTA(0x00FF00FF),
11 | ORANGE(0x00FFA500),
12 | PINK(0x00FFC0CB),
13 | BROWN(0x00A52A2A),
14 | BLACK(0x00000000),
15 | WHITE(0x00FFFFFF),
16 | GRAY(0x00808080),
17 | LIGHT_GRAY(0x00D3D3D3),
18 | DARK_GRAY(0x00A9A9A9),
19 | LIME(0x0000FF00),
20 | MAROON(0x00800000),
21 | OLIVE(0x00808000),
22 | NAVY(0x00000080),
23 | TEAL(0x00008080),
24 | AQUA(0x0000FFFF),
25 | SILVER(0x00C0C0C0),
26 | GOLD(0x00FFD700),
27 | SKY_BLUE(0x0087CEEB),
28 | CORAL(0x00FF7F50),
29 | VIOLET(0x008A2BE2),
30 | INDIGO(0x004B0082),
31 | BEIGE(0x00F5F5DC),
32 | MINT(0x0098FB98),
33 | LAVENDER(0x00E6E6FA);
34 |
35 | private final int colorHex;
36 |
37 | PopularColor(int colorHex) {
38 | this.colorHex = colorHex;
39 | }
40 |
41 | public int val() {
42 | return colorHex;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/images/tolerance/ColorDeviation.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.images.tolerance;
2 |
3 | public enum ColorDeviation {
4 | THE_SAME(0.0),
5 | SMALL_DIFFERENCE(0.05),
6 | BALANCED_TOLERANCE(0.1),
7 | VISIBLE_DIFFERENCE(0.15),
8 | TWENTY_PERCENT(0.2),
9 | THIRTY_PERCENT(0.3),
10 | HALF(0.5),
11 | ALMOST_THE_WHOLE_PICTURE(0.75),
12 | EVERYTHING(1.0);
13 |
14 | private final double tolerance;
15 |
16 | ColorDeviation(double tolerance) {
17 | this.tolerance = tolerance;
18 | }
19 |
20 | public double val() {
21 | return this.tolerance;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/message/MessageActionTypeStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.message;
2 |
3 | import bg.codexio.ai.openai.api.http.message.MessageHttpExecutor;
4 | import bg.codexio.ai.openai.api.http.message.RetrieveListMessagesHttpExecutor;
5 | import bg.codexio.ai.openai.api.payload.message.request.MessageRequest;
6 | import bg.codexio.ai.openai.api.payload.message.response.MessageResponse;
7 |
8 | public class MessageActionTypeStage {
9 |
10 | private final MessageHttpExecutor messageHttpExecutor;
11 | private final RetrieveListMessagesHttpExecutor listMessagesHttpExecutor;
12 | private final String threadId;
13 |
14 | public MessageActionTypeStage(
15 | MessageHttpExecutor messageHttpExecutor,
16 | RetrieveListMessagesHttpExecutor listMessagesHttpExecutor,
17 | String threadId
18 | ) {
19 | this.messageHttpExecutor = messageHttpExecutor;
20 | this.listMessagesHttpExecutor = listMessagesHttpExecutor;
21 | this.threadId = threadId;
22 | }
23 |
24 | public MessageContentStage chat() {
25 | return new MessageContentStage<>(
26 | this.messageHttpExecutor,
27 | MessageRequest.builder(),
28 | this.threadId
29 | );
30 | }
31 |
32 | public MessageAnswersRetrievalTypeStage respond() {
33 | return new MessageAnswersRetrievalTypeStage(
34 | this.listMessagesHttpExecutor,
35 | this.threadId
36 | );
37 | }
38 | }
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/message/MessageAnswerStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.message;
2 |
3 | import bg.codexio.ai.openai.api.http.DefaultOpenAIHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.Mergeable;
5 | import bg.codexio.ai.openai.api.payload.message.request.MessageRequest;
6 | import bg.codexio.ai.openai.api.payload.thread.response.ThreadResponse;
7 |
8 | public class MessageAnswerStage>
9 | extends MessageConfigurationStage {
10 |
11 | MessageAnswerStage(
12 | DefaultOpenAIHttpExecutor httpExecutor,
13 | MessageRequest.Builder requestBuilder,
14 | String threadId
15 | ) {
16 | super(
17 | httpExecutor,
18 | requestBuilder,
19 | threadId
20 | );
21 | }
22 |
23 | public O answersRaw(ThreadResponse threadResponse) {
24 | return this.httpExecutor.executeWithPathVariables(threadResponse.id());
25 | }
26 |
27 | public O answersRaw(String threadId) {
28 | return this.httpExecutor.executeWithPathVariables(threadId);
29 | }
30 |
31 | public O answersRaw() {
32 | return this.httpExecutor.executeWithPathVariables(this.threadId);
33 | }
34 | }
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/message/MessageAssistantStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.message;
2 |
3 | import bg.codexio.ai.openai.api.http.DefaultOpenAIHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.Mergeable;
5 | import bg.codexio.ai.openai.api.payload.assistant.response.AssistantResponse;
6 | import bg.codexio.ai.openai.api.payload.message.request.MessageRequest;
7 | import bg.codexio.ai.openai.api.sdk.run.RunnableAdvancedConfigurationStage;
8 | import bg.codexio.ai.openai.api.sdk.run.Runnables;
9 |
10 | public class MessageAssistantStage>
11 | extends MessageConfigurationStage {
12 |
13 | MessageAssistantStage(
14 | DefaultOpenAIHttpExecutor httpExecutor,
15 | MessageRequest.Builder requestBuilder,
16 | String threadId
17 | ) {
18 | super(
19 | httpExecutor,
20 | requestBuilder,
21 | threadId
22 | );
23 | }
24 |
25 | public RunnableAdvancedConfigurationStage assist(String assistantId) {
26 | return Runnables.defaults(this.threadId)
27 | .and()
28 | .deepConfigure(assistantId);
29 | }
30 |
31 | public RunnableAdvancedConfigurationStage assist(AssistantResponse assistantResponse) {
32 | return Runnables.defaults(this.threadId)
33 | .and()
34 | .deepConfigure(assistantResponse);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/message/MessageConfigurationStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.message;
2 |
3 | import bg.codexio.ai.openai.api.http.DefaultOpenAIHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.Mergeable;
5 | import bg.codexio.ai.openai.api.payload.message.request.MessageRequest;
6 |
7 | public abstract class MessageConfigurationStage> {
8 |
9 | protected final DefaultOpenAIHttpExecutor httpExecutor;
10 | protected final MessageRequest.Builder requestBuilder;
11 | protected final String threadId;
12 |
13 | MessageConfigurationStage(
14 | DefaultOpenAIHttpExecutor httpExecutor,
15 | MessageRequest.Builder requestBuilder,
16 | String threadId
17 | ) {
18 | this.httpExecutor = httpExecutor;
19 | this.requestBuilder = requestBuilder;
20 | this.threadId = threadId;
21 | }
22 | }
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/message/MessageContentStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.message;
2 |
3 | import bg.codexio.ai.openai.api.http.DefaultOpenAIHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.Mergeable;
5 | import bg.codexio.ai.openai.api.payload.message.request.MessageRequest;
6 |
7 | public class MessageContentStage>
8 | extends MessageConfigurationStage {
9 |
10 | MessageContentStage(
11 | DefaultOpenAIHttpExecutor httpExecutor,
12 | MessageRequest.Builder requestBuilder,
13 | String threadId
14 | ) {
15 | super(
16 | httpExecutor,
17 | requestBuilder,
18 | threadId
19 | );
20 | }
21 |
22 | public MessageAdvancedConfigurationStage withContent(String content) {
23 | return new MessageAdvancedConfigurationStage<>(
24 | this.httpExecutor,
25 | this.requestBuilder.withContent(content),
26 | this.threadId
27 | );
28 | }
29 | }
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/message/MessageMetaStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.message;
2 |
3 | import bg.codexio.ai.openai.api.http.DefaultOpenAIHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.Mergeable;
5 | import bg.codexio.ai.openai.api.payload.message.request.MessageRequest;
6 |
7 | public class MessageMetaStage>
8 | extends MessageConfigurationStage {
9 |
10 | MessageMetaStage(
11 | DefaultOpenAIHttpExecutor httpExecutor,
12 | MessageRequest.Builder requestBuilder,
13 | String threadId
14 | ) {
15 | super(
16 | httpExecutor,
17 | requestBuilder,
18 | threadId
19 | );
20 | }
21 |
22 | public MessageAdvancedConfigurationStage awareOf(String... metadata) {
23 | return new MessageAdvancedConfigurationStage<>(
24 | this.httpExecutor,
25 | this.requestBuilder.addMetadata(metadata),
26 | this.threadId
27 | );
28 | }
29 | }
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/message/constant/MessageConstants.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.message.constant;
2 |
3 | public class MessageConstants {
4 |
5 | public static final String EMPTY = "";
6 |
7 | public static final String CREATED_IMAGE_FILE_MESSAGE = "As response "
8 | + "image was generated and downloaded to desired folder.";
9 |
10 | public static final String IMAGE_FILE_EXTENSION = ".png";
11 |
12 | private MessageConstants() {
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/run/RunnableConfigurationStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.run;
2 |
3 | import bg.codexio.ai.openai.api.http.run.RunnableHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.run.request.RunnableRequest;
5 |
6 | public abstract class RunnableConfigurationStage {
7 |
8 | protected final RunnableHttpExecutor httpExecutor;
9 | protected final RunnableRequest.Builder requestBuilder;
10 | protected final String threadId;
11 |
12 | RunnableConfigurationStage(
13 | RunnableHttpExecutor httpExecutor,
14 | RunnableRequest.Builder requestBuilder,
15 | String threadId
16 | ) {
17 | this.httpExecutor = httpExecutor;
18 | this.requestBuilder = requestBuilder;
19 | this.threadId = threadId;
20 | }
21 | }
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/run/RunnableInstructionStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.run;
2 |
3 | import bg.codexio.ai.openai.api.http.run.RunnableHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.run.request.RunnableRequest;
5 |
6 | public class RunnableInstructionStage
7 | extends RunnableConfigurationStage {
8 |
9 | RunnableInstructionStage(
10 | RunnableHttpExecutor httpExecutor,
11 | RunnableRequest.Builder requestBuilder,
12 | String threadId
13 | ) {
14 | super(
15 | httpExecutor,
16 | requestBuilder,
17 | threadId
18 | );
19 | }
20 |
21 | public RunnableAdvancedConfigurationStage instruct(String instruction) {
22 | return new RunnableAdvancedConfigurationStage(
23 | this.httpExecutor,
24 | this.requestBuilder.withAdditionalInstructions(instruction),
25 | this.threadId
26 | );
27 | }
28 | }
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/run/RunnableMessageResult.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.run;
2 |
3 | import bg.codexio.ai.openai.api.http.run.RunnableHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.run.request.RunnableRequest;
5 | import bg.codexio.ai.openai.api.sdk.message.MessageResult;
6 | import bg.codexio.ai.openai.api.sdk.message.Messages;
7 |
8 | public class RunnableMessageResult
9 | extends RunnableConfigurationStage {
10 |
11 | RunnableMessageResult(
12 | RunnableHttpExecutor httpExecutor,
13 | RunnableRequest.Builder requestBuilder,
14 | String threadId
15 | ) {
16 | super(
17 | httpExecutor,
18 | requestBuilder,
19 | threadId
20 | );
21 | }
22 |
23 | public MessageResult answers() {
24 | return Messages.defaults(this.threadId)
25 | .and()
26 | .respond()
27 | .answers();
28 | }
29 | }
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/run/RunnableMetaStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.run;
2 |
3 | import bg.codexio.ai.openai.api.http.run.RunnableHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.run.request.RunnableRequest;
5 |
6 | public class RunnableMetaStage
7 | extends RunnableConfigurationStage {
8 |
9 | RunnableMetaStage(
10 | RunnableHttpExecutor httpExecutor,
11 | RunnableRequest.Builder requestBuilder,
12 | String threadId
13 | ) {
14 | super(
15 | httpExecutor,
16 | requestBuilder,
17 | threadId
18 | );
19 | }
20 |
21 | public RunnableAdvancedConfigurationStage awareOf(String... metadata) {
22 | return new RunnableAdvancedConfigurationStage(
23 | this.httpExecutor,
24 | this.requestBuilder.addMetadata(metadata),
25 | this.threadId
26 | );
27 | }
28 | }
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/run/constant/RunnableDefaultValuesConstants.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.run.constant;
2 |
3 | public class RunnableDefaultValuesConstants {
4 |
5 | public static final long COMPLETION_SLEEP_DURATION_MILLIS = 1000L;
6 |
7 | private RunnableDefaultValuesConstants() {
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/run/constant/RunnableEnvironmentVariableNameConstants.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.run.constant;
2 |
3 | public class RunnableEnvironmentVariableNameConstants {
4 |
5 | public static final String COMPLETION_SLEEP_DURATION =
6 | "COMPLETION_SLEEP_DURATION_MILLIS";
7 |
8 | private RunnableEnvironmentVariableNameConstants() {
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/run/constant/RunnableStatusConstants.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.run.constant;
2 |
3 | public class RunnableStatusConstants {
4 |
5 | public static final String QUEUED = "queued";
6 | public static final String IN_PROGRESS = "in_progress";
7 |
8 | private RunnableStatusConstants() {
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/thread/ThreadConfigurationStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.thread;
2 |
3 | import bg.codexio.ai.openai.api.http.DefaultOpenAIHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.thread.request.ThreadRequest;
5 | import bg.codexio.ai.openai.api.payload.thread.request.ThreadRequestBuilder;
6 | import bg.codexio.ai.openai.api.payload.thread.response.ThreadResponse;
7 |
8 | public abstract class ThreadConfigurationStage {
9 |
10 | protected final DefaultOpenAIHttpExecutor httpExecutor;
11 | protected final ThreadRequestBuilder requestBuilder;
12 |
13 | ThreadConfigurationStage(
14 | DefaultOpenAIHttpExecutor httpExecutor,
15 | ThreadRequestBuilder requestBuilder
16 | ) {
17 | this.httpExecutor = httpExecutor;
18 | this.requestBuilder = requestBuilder;
19 | }
20 | }
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/thread/ThreadCreationStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.thread;
2 |
3 | import bg.codexio.ai.openai.api.http.DefaultOpenAIHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.thread.request.ThreadRequest;
5 | import bg.codexio.ai.openai.api.payload.thread.request.ThreadRequestBuilder;
6 | import bg.codexio.ai.openai.api.payload.thread.response.ThreadResponse;
7 |
8 | public class ThreadCreationStage
9 | extends ThreadConfigurationStage {
10 |
11 | ThreadCreationStage(
12 | DefaultOpenAIHttpExecutor httpExecutor,
13 | ThreadRequestBuilder requestBuilder
14 | ) {
15 | super(
16 | httpExecutor,
17 | requestBuilder
18 | );
19 | }
20 |
21 | public ThreadResponse empty() {
22 | return this.httpExecutor.execute(this.requestBuilder.specificRequestCreator()
23 | .apply(this.requestBuilder.build()));
24 | }
25 |
26 | public ThreadAdvancedConfigurationStage deepConfigure() {
27 | return new ThreadAdvancedConfigurationStage<>(
28 | this.httpExecutor,
29 | this.requestBuilder
30 | );
31 | }
32 | }
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/thread/ThreadMetaStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.thread;
2 |
3 | import bg.codexio.ai.openai.api.http.DefaultOpenAIHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.thread.request.ThreadRequest;
5 | import bg.codexio.ai.openai.api.payload.thread.request.ThreadRequestBuilder;
6 | import bg.codexio.ai.openai.api.payload.thread.response.ThreadResponse;
7 |
8 | public class ThreadMetaStage
9 | extends ThreadConfigurationStage {
10 |
11 | ThreadMetaStage(
12 | DefaultOpenAIHttpExecutor httpExecutor,
13 | ThreadRequestBuilder requestBuilder
14 | ) {
15 | super(
16 | httpExecutor,
17 | requestBuilder
18 | );
19 | }
20 |
21 | public ThreadAdvancedConfigurationStage awareOf(String... metadata) {
22 | return new ThreadAdvancedConfigurationStage<>(
23 | this.httpExecutor,
24 | this.requestBuilder.addMetadata(metadata)
25 | );
26 | }
27 | }
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/thread/constant/ThreadDefaultValuesConstants.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.thread.constant;
2 |
3 | public class ThreadDefaultValuesConstants {
4 |
5 | public static final String MESSAGE_SENDER_ROLE = "user";
6 | private ThreadDefaultValuesConstants() {
7 | }
8 | }
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/vision/VisionConfigurationStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.vision;
2 |
3 | import bg.codexio.ai.openai.api.http.vision.VisionHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.vision.request.VisionRequest;
5 |
6 | public class VisionConfigurationStage {
7 |
8 | protected final VisionHttpExecutor executor;
9 | protected final VisionRequest requestContext;
10 |
11 | VisionConfigurationStage(
12 | VisionHttpExecutor executor,
13 | VisionRequest requestContext
14 | ) {
15 | this.executor = executor;
16 | this.requestContext = requestContext;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/voice/speech/AsyncDownloadStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.voice.speech;
2 |
3 | import bg.codexio.ai.openai.api.http.voice.SpeechHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.voice.request.SpeechRequest;
5 |
6 | import java.io.File;
7 |
8 | /**
9 | * Configures target folder
10 | */
11 | public class AsyncDownloadStage
12 | extends SpeechConfigurationStage {
13 |
14 | AsyncDownloadStage(
15 | SpeechHttpExecutor executor,
16 | SpeechRequest.Builder requestBuilder
17 | ) {
18 | super(
19 | executor,
20 | requestBuilder
21 | );
22 | }
23 |
24 | /**
25 | * Configures target folder to download to
26 | *
27 | * @param targetFolder {@link File} folder where to download the produced
28 | * audio file
29 | * @return {@link AsyncPromiseStage} to register callbacks
30 | */
31 | public AsyncPromiseStage whenDownloadedTo(File targetFolder) {
32 | return new AsyncPromiseStage(
33 | this.executor,
34 | this.requestBuilder,
35 | targetFolder
36 | );
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/voice/speech/AsyncPromptStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.voice.speech;
2 |
3 | import bg.codexio.ai.openai.api.http.voice.SpeechHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.voice.request.SpeechRequest;
5 | import bg.codexio.ai.openai.api.sdk.RuntimeExecutor;
6 |
7 | /**
8 | * Registers text input
9 | */
10 | public class AsyncPromptStage
11 | extends SpeechConfigurationStage
12 | implements RuntimeExecutor {
13 |
14 | AsyncPromptStage(
15 | SpeechHttpExecutor executor,
16 | SpeechRequest.Builder requestBuilder
17 | ) {
18 | super(
19 | executor,
20 | requestBuilder
21 | );
22 | }
23 |
24 | /**
25 | * @param text input to be registered
26 | * @return {@link AsyncDownloadStage} to configure target folder
27 | */
28 | public AsyncDownloadStage dictate(String text) {
29 | return new AsyncDownloadStage(
30 | this.executor,
31 | this.requestBuilder.withInput(text)
32 | );
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/voice/speech/ReactivePromptStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.voice.speech;
2 |
3 | import bg.codexio.ai.openai.api.http.voice.SpeechHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.voice.request.SpeechRequest;
5 | import bg.codexio.ai.openai.api.sdk.RuntimeExecutor;
6 |
7 | /**
8 | * Registers text input
9 | */
10 | public class ReactivePromptStage
11 | extends SpeechConfigurationStage
12 | implements RuntimeExecutor {
13 |
14 | ReactivePromptStage(
15 | SpeechHttpExecutor executor,
16 | SpeechRequest.Builder requestBuilder
17 | ) {
18 | super(
19 | executor,
20 | requestBuilder
21 | );
22 | }
23 |
24 | /**
25 | * @param text input to be registered
26 | * @return {@link ReactiveDownloadStage} to call the API
27 | */
28 | public ReactiveDownloadStage dictate(String text) {
29 | return new ReactiveDownloadStage(
30 | this.executor,
31 | this.requestBuilder.withInput(text)
32 | );
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/voice/speech/SimplifiedStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.voice.speech;
2 |
3 | import bg.codexio.ai.openai.api.http.HttpExecutorContext;
4 | import bg.codexio.ai.openai.api.models.tts.TTS1HDModel;
5 | import bg.codexio.ai.openai.api.payload.credentials.ApiCredentials;
6 | import bg.codexio.ai.openai.api.sdk.TerminalStage;
7 |
8 | /**
9 | * Preconfigured stage with AI Model,
10 | * speaker, format and speed
11 | */
12 | public class SimplifiedStage
13 | implements TerminalStage {
14 |
15 | private final ApiCredentials credentials;
16 |
17 | public SimplifiedStage(ApiCredentials credentials) {
18 | this.credentials = credentials;
19 | }
20 |
21 | /**
22 | * Preconfigures {@link TTS1HDModel} with HD quality
23 | * the default speaker with mp3 output format and x1 speed.
24 | *
25 | * @return {@link SpeechRuntimeSelectionStage} to select the runtime
26 | */
27 | @Override
28 | public SpeechRuntimeSelectionStage andRespond() {
29 | return Speech.authenticate(new HttpExecutorContext(this.credentials))
30 | .and()
31 | .hdPowered()
32 | .defaultSpeaker()
33 | .mp3()
34 | .sameSpeed();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/voice/speech/SpeechConfigurationStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.voice.speech;
2 |
3 | import bg.codexio.ai.openai.api.http.voice.SpeechHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.voice.request.SpeechRequest;
5 |
6 | /**
7 | * Base for all Speech stages
8 | */
9 | public abstract class SpeechConfigurationStage {
10 |
11 | protected final SpeechHttpExecutor executor;
12 | protected final SpeechRequest.Builder requestBuilder;
13 |
14 | SpeechConfigurationStage(
15 | SpeechHttpExecutor executor,
16 | SpeechRequest.Builder requestBuilder
17 | ) {
18 | this.executor = executor;
19 | this.requestBuilder = requestBuilder;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/voice/speech/SynchronousDownloadStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.voice.speech;
2 |
3 | import bg.codexio.ai.openai.api.http.voice.SpeechHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.voice.request.SpeechRequest;
5 |
6 | import java.io.File;
7 | import java.io.IOException;
8 |
9 | /**
10 | * Sends blocking requests to OpenAI API
11 | */
12 | public class SynchronousDownloadStage
13 | extends SpeechConfigurationStage {
14 |
15 | SynchronousDownloadStage(
16 | SpeechHttpExecutor executor,
17 | SpeechRequest.Builder requestBuilder
18 | ) {
19 | super(
20 | executor,
21 | requestBuilder
22 | );
23 | }
24 |
25 | /**
26 | * Executes the request so far in synchronous blocking fashion,
27 | * the result of the OpenAI API response is then downloaded to the
28 | * supplied folder.
29 | *
30 | * @param targetFolder {@link File} folder where to download the produced
31 | * audio file
32 | * @return the downloaded audio {@link File}
33 | * @throws IOException if the target folder is not accessible
34 | */
35 | public File downloadTo(File targetFolder) throws IOException {
36 | return DownloadExecutor.downloadTo(
37 | targetFolder,
38 | this.executor.execute(this.requestBuilder.build()),
39 | this.requestBuilder.responseFormat()
40 | );
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/voice/speech/SynchronousPromptStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.voice.speech;
2 |
3 | import bg.codexio.ai.openai.api.http.voice.SpeechHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.voice.request.SpeechRequest;
5 | import bg.codexio.ai.openai.api.sdk.RuntimeExecutor;
6 |
7 | /**
8 | * Adds user input and proceeds
9 | * to blocking execution
10 | */
11 | public class SynchronousPromptStage
12 | extends SpeechConfigurationStage
13 | implements RuntimeExecutor {
14 |
15 | SynchronousPromptStage(
16 | SpeechHttpExecutor executor,
17 | SpeechRequest.Builder requestBuilder
18 | ) {
19 | super(
20 | executor,
21 | requestBuilder
22 | );
23 | }
24 |
25 | /**
26 | * @param text to prompt
27 | * @return {@link SynchronousDownloadStage}
28 | */
29 | public SynchronousDownloadStage dictate(String text) {
30 | return new SynchronousDownloadStage(
31 | this.executor,
32 | this.requestBuilder.withInput(text)
33 | );
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/voice/speech/VoiceStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.voice.speech;
2 |
3 | import bg.codexio.ai.openai.api.http.voice.SpeechHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.voice.Speaker;
5 | import bg.codexio.ai.openai.api.payload.voice.request.SpeechRequest;
6 | import bg.codexio.ai.openai.api.sdk.IntermediateStage;
7 |
8 | /**
9 | * Configures which person's voice to use
10 | */
11 | public class VoiceStage
12 | extends SpeechConfigurationStage
13 | implements IntermediateStage {
14 |
15 | VoiceStage(
16 | SpeechHttpExecutor executor,
17 | SpeechRequest.Builder requestBuilder
18 | ) {
19 | super(
20 | executor,
21 | requestBuilder
22 | );
23 | }
24 |
25 | /**
26 | * Sets a {@link Speaker}
27 | *
28 | * @return {@link OutputStage} to configure the output format
29 | */
30 | public OutputStage voiceOf(Speaker speaker) {
31 | return new OutputStage(
32 | this.executor,
33 | this.requestBuilder.withVoice(speaker.val())
34 | );
35 | }
36 |
37 | /**
38 | * Sets a {@link Speaker} to {@link Speaker#ECHO}
39 | *
40 | * @return {@link OutputStage} to configure the output format
41 | */
42 | public OutputStage defaultSpeaker() {
43 | return this.voiceOf(Speaker.ECHO);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/voice/transcription/AsyncPromptStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.voice.transcription;
2 |
3 | import bg.codexio.ai.openai.api.http.voice.TranscriptionHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.voice.request.TranscriptionRequest;
5 | import bg.codexio.ai.openai.api.sdk.RuntimeExecutor;
6 |
7 | /**
8 | * Registers user input optionally
9 | */
10 | public class AsyncPromptStage
11 | extends TranscriptionConfigurationStage
12 | implements RuntimeExecutor {
13 |
14 | AsyncPromptStage(
15 | TranscriptionHttpExecutor executor,
16 | TranscriptionRequest.Builder requestBuilder
17 | ) {
18 | super(
19 | executor,
20 | requestBuilder
21 | );
22 | }
23 |
24 | /**
25 | * Guides the transcription with additional prompt
26 | *
27 | * @return {@link AsyncPromiseStage} to execute the request with callbacks
28 | */
29 | public AsyncPromiseStage guide(String prompt) {
30 | return new AsyncPromiseStage(
31 | this.executor,
32 | this.requestBuilder.withPrompt(prompt)
33 | );
34 | }
35 |
36 | /**
37 | * No additional prompt is given to the OpenAI API
38 | *
39 | * @return {@link AsyncPromptStage} to execute the request with callbacks
40 | */
41 | public AsyncPromiseStage unguided() {
42 | return this.guide(null);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/voice/transcription/AudioFileStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.voice.transcription;
2 |
3 | import bg.codexio.ai.openai.api.http.voice.TranscriptionHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.voice.request.TranscriptionRequest;
5 |
6 | import java.io.File;
7 |
8 | /**
9 | * Configures which audio file to transcribe
10 | */
11 | public class AudioFileStage
12 | extends TranscriptionConfigurationStage {
13 |
14 | AudioFileStage(
15 | TranscriptionHttpExecutor executor,
16 | TranscriptionRequest.Builder requestBuilder
17 | ) {
18 | super(
19 | executor,
20 | requestBuilder
21 | );
22 | }
23 |
24 | /**
25 | * Sets local audio file to transcribe.
26 | * Must be one these formats:
27 | *
28 | * - flac
29 | * - mp3
30 | * - mp4
31 | * - mpeg
32 | * - mpga
33 | * - m4a
34 | * - ogg
35 | * - wav
36 | *
37 | *
38 | * @param audioFile local file
39 | * @return {@link TemperatureStage} to configure the temperature level
40 | */
41 | public TemperatureStage transcribe(File audioFile) {
42 | return new TemperatureStage(
43 | this.executor,
44 | this.requestBuilder.withFile(audioFile)
45 | );
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/voice/transcription/PreSimplifiedStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.voice.transcription;
2 |
3 | import bg.codexio.ai.openai.api.payload.credentials.ApiCredentials;
4 |
5 | import java.io.File;
6 |
7 | /**
8 | * Sets audio file for transcription,
9 | * before all other autoconfiguration.
10 | */
11 | public class PreSimplifiedStage {
12 |
13 | private final ApiCredentials credentials;
14 |
15 | public PreSimplifiedStage(ApiCredentials credentials) {
16 | this.credentials = credentials;
17 | }
18 |
19 | /**
20 | * @return {@link SimplifiedStage}
21 | * @see AudioFileStage#transcribe(File)
22 | */
23 | public SynchronousPromptStage transcribe(File audioFile) {
24 | return new SimplifiedStage(
25 | this.credentials,
26 | audioFile
27 | ).andRespond()
28 | .immediate();
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/voice/transcription/SynchronousPromptStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.voice.transcription;
2 |
3 | import bg.codexio.ai.openai.api.http.voice.TranscriptionHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.voice.request.TranscriptionRequest;
5 | import bg.codexio.ai.openai.api.payload.voice.response.SpeechTextResponse;
6 | import bg.codexio.ai.openai.api.sdk.RuntimeExecutor;
7 |
8 | public class SynchronousPromptStage
9 | extends TranscriptionConfigurationStage
10 | implements RuntimeExecutor {
11 |
12 | SynchronousPromptStage(
13 | TranscriptionHttpExecutor executor,
14 | TranscriptionRequest.Builder requestBuilder
15 | ) {
16 | super(
17 | executor,
18 | requestBuilder
19 | );
20 | }
21 |
22 | /**
23 | * Guides the transcription with additional prompt
24 | *
25 | * @return {@link SpeechTextResponse} the response from the API in the
26 | * configured format
27 | */
28 | public SpeechTextResponse guide(String prompt) {
29 | return this.executor.execute(this.requestBuilder.withPrompt(prompt)
30 | .build());
31 | }
32 |
33 | /**
34 | * Sends request to OpenAI API without additional prompt
35 | *
36 | * @return {@link SpeechTextResponse} the response from the API in the
37 | * configured format
38 | */
39 | public SpeechTextResponse unguided() {
40 | return this.guide(null);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/voice/transcription/TranscriptionConfigurationStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.voice.transcription;
2 |
3 | import bg.codexio.ai.openai.api.http.voice.TranscriptionHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.voice.request.TranscriptionRequest;
5 |
6 | /**
7 | * Base for all Transcription stages
8 | */
9 | public abstract class TranscriptionConfigurationStage {
10 |
11 | protected final TranscriptionHttpExecutor executor;
12 | protected final TranscriptionRequest.Builder requestBuilder;
13 |
14 | TranscriptionConfigurationStage(
15 | TranscriptionHttpExecutor executor,
16 | TranscriptionRequest.Builder requestBuilder
17 | ) {
18 | this.executor = executor;
19 | this.requestBuilder = requestBuilder;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/voice/translation/AsyncPromptStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.voice.translation;
2 |
3 | import bg.codexio.ai.openai.api.http.voice.TranslationHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.voice.request.TranslationRequest;
5 | import bg.codexio.ai.openai.api.sdk.RuntimeExecutor;
6 |
7 | /**
8 | * Registers user input optionally
9 | */
10 | public class AsyncPromptStage
11 | extends TranslationConfigurationStage
12 | implements RuntimeExecutor {
13 |
14 | AsyncPromptStage(
15 | TranslationHttpExecutor executor,
16 | TranslationRequest.Builder requestBuilder
17 | ) {
18 | super(
19 | executor,
20 | requestBuilder
21 | );
22 | }
23 |
24 | /**
25 | * Guides the translation with additional prompt
26 | *
27 | * @return {@link AsyncPromiseStage} to execute the request with callbacks
28 | */
29 | public AsyncPromiseStage guide(String prompt) {
30 | return new AsyncPromiseStage(
31 | this.executor,
32 | this.requestBuilder.withPrompt(prompt)
33 | );
34 | }
35 |
36 | /**
37 | * No additional prompt is given to the OpenAI API
38 | *
39 | * @return {@link AsyncPromiseStage} to execute the request with callbacks
40 | */
41 | public AsyncPromiseStage unguided() {
42 | return this.guide(null);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/voice/translation/AudioFileStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.voice.translation;
2 |
3 | import bg.codexio.ai.openai.api.http.voice.TranslationHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.voice.request.TranslationRequest;
5 |
6 | import java.io.File;
7 |
8 | /**
9 | * Configures which audio file to translate
10 | */
11 | public class AudioFileStage
12 | extends TranslationConfigurationStage {
13 |
14 | AudioFileStage(
15 | TranslationHttpExecutor executor,
16 | TranslationRequest.Builder requestBuilder
17 | ) {
18 | super(
19 | executor,
20 | requestBuilder
21 | );
22 | }
23 |
24 | /**
25 | * Sets local audio file to translate.
26 | * Must be one these formats:
27 | *
28 | * - flac
29 | * - mp3
30 | * - mp4
31 | * - mpeg
32 | * - mpga
33 | * - m4a
34 | * - ogg
35 | * - wav
36 | *
37 | *
38 | * @param audioFile local file
39 | * @return {@link TemperatureStage} to configure the temperature level
40 | */
41 | public TemperatureStage translate(File audioFile) {
42 | return new TemperatureStage(
43 | this.executor,
44 | this.requestBuilder.withFile(audioFile)
45 | );
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/voice/translation/PreSimplifiedStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.voice.translation;
2 |
3 | import bg.codexio.ai.openai.api.payload.credentials.ApiCredentials;
4 |
5 | import java.io.File;
6 |
7 | /**
8 | * Sets audio file for translation,
9 | * before all other autoconfiguration.
10 | */
11 | public class PreSimplifiedStage {
12 |
13 | private final ApiCredentials credentials;
14 |
15 | public PreSimplifiedStage(ApiCredentials credentials) {
16 | this.credentials = credentials;
17 | }
18 |
19 | /**
20 | * @return {@link SimplifiedStage}
21 | * @see AudioFileStage#translate(File)
22 | */
23 | public SynchronousPromptStage translate(File audioFile) {
24 | return new SimplifiedStage(
25 | this.credentials,
26 | audioFile
27 | ).andRespond()
28 | .immediate();
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/main/java/bg/codexio/ai/openai/api/sdk/voice/translation/TranslationConfigurationStage.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.voice.translation;
2 |
3 | import bg.codexio.ai.openai.api.http.voice.TranslationHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.voice.request.TranslationRequest;
5 |
6 | /**
7 | * Base for all Translation stages
8 | */
9 | public abstract class TranslationConfigurationStage {
10 |
11 | protected final TranslationHttpExecutor executor;
12 | protected final TranslationRequest.Builder requestBuilder;
13 |
14 | TranslationConfigurationStage(
15 | TranslationHttpExecutor executor,
16 | TranslationRequest.Builder requestBuilder
17 | ) {
18 | this.executor = executor;
19 | this.requestBuilder = requestBuilder;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/test/java/bg/codexio/ai/openai/api/sdk/MockedFileSimplifiedUtils.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk;
2 |
3 | import bg.codexio.ai.openai.api.sdk.file.FileActionTypeStage;
4 | import bg.codexio.ai.openai.api.sdk.file.FileSimplified;
5 | import org.mockito.MockedStatic;
6 |
7 | import static bg.codexio.ai.openai.api.sdk.CommonTestAssertions.FILE;
8 | import static bg.codexio.ai.openai.api.sdk.file.InternalAssertions.FILE_RESPONSE;
9 | import static org.mockito.ArgumentMatchers.any;
10 |
11 | public class MockedFileSimplifiedUtils {
12 | public static void mockFileSimplified(
13 | MockedStatic authUtils,
14 | HttpBuilder auth,
15 | MockedStatic filesSimplified
16 | ) {
17 | authUtils.when(() -> Authenticator.autoAuthenticate(any()))
18 | .thenReturn(auth);
19 |
20 | filesSimplified.when(() -> FileSimplified.simply(FILE))
21 | .thenReturn(FILE_RESPONSE.id());
22 | }
23 | }
--------------------------------------------------------------------------------
/openai-api-sdk/src/test/java/bg/codexio/ai/openai/api/sdk/ObjectMapperSubtypesRegistrationUtilsTest.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk;
2 |
3 | import bg.codexio.ai.openai.api.http.DefaultOpenAIHttpExecutor;
4 | import bg.codexio.ai.openai.api.payload.assistant.tool.CodeInterpreter;
5 | import org.junit.jupiter.api.Test;
6 |
7 | import java.util.List;
8 |
9 | import static org.mockito.ArgumentMatchers.any;
10 | import static org.mockito.Mockito.mock;
11 | import static org.mockito.Mockito.verify;
12 |
13 | public class ObjectMapperSubtypesRegistrationUtilsTest {
14 |
15 | @Test
16 | void testRegisterAssistantTools() {
17 | DefaultOpenAIHttpExecutor, ?> executor =
18 | mock(DefaultOpenAIHttpExecutor.class);
19 | ObjectMapperSubtypesRegistrationUtils.registerAssistantTools(
20 | executor,
21 | List.of(new CodeInterpreter())
22 | );
23 |
24 | verify(executor).configureMappingExternally(any());
25 | }
26 | }
--------------------------------------------------------------------------------
/openai-api-sdk/src/test/java/bg/codexio/ai/openai/api/sdk/ProcessingTest.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import static org.junit.jupiter.api.Assertions.assertFalse;
6 | import static org.junit.jupiter.api.Assertions.assertTrue;
7 |
8 | public class ProcessingTest {
9 |
10 | @Test
11 | public void testRealTime_shouldBeTrue() {
12 | assertTrue(Processing.REAL_TIME.val());
13 | }
14 |
15 | @Test
16 | public void testBatch_shouldBeFalse() {
17 | assertFalse(Processing.BATCH.val());
18 | }
19 |
20 | @Test
21 | public void testDefault_shouldBeFalse() {
22 | assertFalse(Processing.DEFAULT.val());
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/test/java/bg/codexio/ai/openai/api/sdk/ThreadOperationUtilsTest.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import java.time.Duration;
6 |
7 | import static org.junit.jupiter.api.Assertions.assertTimeout;
8 |
9 | public class ThreadOperationUtilsTest {
10 |
11 | @Test
12 | void testSleep_expectCorrectTimeout() {
13 | long expectedMillis = 1000;
14 | long exceedingAmount = expectedMillis + 300;
15 |
16 | assertTimeout(
17 | Duration.ofMillis(exceedingAmount),
18 | () -> ThreadOperationUtils.sleep(expectedMillis)
19 | );
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/test/java/bg/codexio/ai/openai/api/sdk/auth/FromDeveloperTest.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.auth;
2 |
3 | import bg.codexio.ai.openai.api.payload.credentials.ApiCredentials;
4 | import org.junit.jupiter.api.Test;
5 |
6 | import static org.junit.jupiter.api.Assertions.assertEquals;
7 |
8 | public class FromDeveloperTest {
9 |
10 | @Test
11 | public void testDoPass_shouldReturnSuppliedCredentials() {
12 | var auth = FromDeveloper.doPass(new ApiCredentials("test-key"));
13 |
14 | assertEquals(
15 | new ApiCredentials("test-key"),
16 | auth.credentials()
17 | );
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/test/java/bg/codexio/ai/openai/api/sdk/auth/util/StringUtilTest.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.auth.util;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import static org.junit.jupiter.api.Assertions.assertFalse;
6 | import static org.junit.jupiter.api.Assertions.assertTrue;
7 |
8 | public class StringUtilTest {
9 |
10 | @Test
11 | public void testIsNullOrBlank_withNull_shouldReturnTrue() {
12 | assertTrue(StringUtil.isNullOrBlank(null));
13 | }
14 |
15 | @Test
16 | public void testIsNullOrBlank_withEmptyString_shouldReturnTrue() {
17 | assertTrue(StringUtil.isNullOrBlank(""));
18 | }
19 |
20 | @Test
21 | public void testIsNullOrBlank_withBlankString_shouldReturnTrue() {
22 | assertTrue(StringUtil.isNullOrBlank(" "));
23 | }
24 |
25 | @Test
26 | public void testIsNullOrBlank_withNonBlankString_shouldReturnFalse() {
27 | assertFalse(StringUtil.isNullOrBlank("Codexio OpenAI sdk is great"));
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/test/java/bg/codexio/ai/openai/api/sdk/file/FileDownloadingNameTypeStageTest.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.file;
2 |
3 | import bg.codexio.ai.openai.api.payload.file.request.UploadFileRequest;
4 | import bg.codexio.ai.openai.api.payload.file.response.FileContentResponse;
5 | import org.junit.jupiter.api.BeforeEach;
6 | import org.junit.jupiter.api.Test;
7 |
8 | import static bg.codexio.ai.openai.api.sdk.CommonTestAssertions.RETRIEVE_FILE_CONTENT_HTTP_EXECUTOR;
9 | import static bg.codexio.ai.openai.api.sdk.file.InternalAssertions.FILE_TEST_ID;
10 | import static bg.codexio.ai.openai.api.sdk.file.InternalAssertions.FILE_TEST_NAME;
11 | import static org.junit.jupiter.api.Assertions.assertNotNull;
12 |
13 | public class FileDownloadingNameTypeStageTest {
14 |
15 | private FileDownloadingNameTypeStage fileDownloadingNameTypeStage;
16 |
17 | @BeforeEach
18 | void setUp() {
19 | this.fileDownloadingNameTypeStage = new FileDownloadingNameTypeStage<>(
20 | RETRIEVE_FILE_CONTENT_HTTP_EXECUTOR,
21 | UploadFileRequest.builder(),
22 | FILE_TEST_ID
23 | );
24 | }
25 |
26 | @Test
27 | void testAs_expectCorrectBuilder() {
28 | var nextStage = this.fileDownloadingNameTypeStage.as(FILE_TEST_NAME);
29 |
30 | assertNotNull(nextStage);
31 | }
32 | }
--------------------------------------------------------------------------------
/openai-api-sdk/src/test/java/bg/codexio/ai/openai/api/sdk/file/FileTargetingStageTest.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.file;
2 |
3 | import bg.codexio.ai.openai.api.payload.file.purpose.AssistantPurpose;
4 | import bg.codexio.ai.openai.api.payload.file.request.UploadFileRequest;
5 | import bg.codexio.ai.openai.api.payload.file.response.FileResponse;
6 | import org.junit.jupiter.api.BeforeEach;
7 | import org.junit.jupiter.api.Test;
8 |
9 | import static bg.codexio.ai.openai.api.sdk.CommonTestAssertions.UPLOAD_FILE_HTTP_EXECUTOR;
10 | import static org.junit.jupiter.api.Assertions.assertNotNull;
11 |
12 | public class FileTargetingStageTest {
13 |
14 | private FileTargetingStage fileTargetingStage;
15 |
16 | @BeforeEach
17 | public void setUp() {
18 | this.fileTargetingStage = new FileTargetingStage<>(
19 | UPLOAD_FILE_HTTP_EXECUTOR,
20 | UploadFileRequest.builder()
21 | );
22 | }
23 |
24 | @Test
25 | public void testTargeting_withAssistantPurpose_expectPurposeNameAssistants() {
26 | var nextStage =
27 | this.fileTargetingStage.targeting(new AssistantPurpose());
28 |
29 | assertNotNull(nextStage);
30 | }
31 |
32 | @Test
33 | public void testForAssistants_expectPurposeNameAssistants() {
34 | var nextStage = this.fileTargetingStage.forAssistants();
35 |
36 | assertNotNull(nextStage);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/test/java/bg/codexio/ai/openai/api/sdk/images/CreatingActionTypeStageTest.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.images;
2 |
3 | import org.junit.jupiter.api.BeforeEach;
4 | import org.junit.jupiter.api.Test;
5 |
6 | import static bg.codexio.ai.openai.api.sdk.images.InternalAssertions.CREATE_IMAGE_HTTP_EXECUTOR;
7 | import static bg.codexio.ai.openai.api.sdk.images.InternalAssertions.createImageRequestIsPopulated;
8 | import static org.junit.jupiter.api.Assertions.*;
9 |
10 | public class CreatingActionTypeStageTest {
11 |
12 | private CreatingActionTypeStage creatingActionTypeStage;
13 |
14 | @BeforeEach
15 | public void setUp() {
16 | this.creatingActionTypeStage =
17 | new CreatingActionTypeStage(CREATE_IMAGE_HTTP_EXECUTOR);
18 | }
19 |
20 | @Test
21 | public void testCreating_expectCreateExecutor() {
22 | var nextStage = this.creatingActionTypeStage.creating();
23 |
24 | assertAll(
25 | () -> assertEquals(
26 | nextStage.executor,
27 | CREATE_IMAGE_HTTP_EXECUTOR
28 | ),
29 | () -> assertInstanceOf(
30 | PromptfulImagesRuntimeSelectionStage.class,
31 | nextStage.runtimeSelector.apply(null)
32 | ),
33 | () -> createImageRequestIsPopulated(nextStage)
34 | );
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/test/java/bg/codexio/ai/openai/api/sdk/images/EditingActionTypeStageTest.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.images;
2 |
3 | import org.junit.jupiter.api.BeforeEach;
4 | import org.junit.jupiter.api.Test;
5 |
6 | import java.io.File;
7 |
8 | import static bg.codexio.ai.openai.api.sdk.images.InternalAssertions.*;
9 | import static org.junit.jupiter.api.Assertions.*;
10 |
11 | public class EditingActionTypeStageTest {
12 |
13 | private EditingActionTypeStage editingActionTypeStage;
14 |
15 | @BeforeEach
16 | public void setUp() {
17 | this.editingActionTypeStage =
18 | new EditingActionTypeStage(EDIT_IMAGE_HTTP_EXECUTOR);
19 | }
20 |
21 | @Test
22 | public void testEditing_expectEditExecutor() {
23 | var nextStage =
24 | this.editingActionTypeStage.editing(new File(TEST_FILE_PATH));
25 |
26 | assertAll(
27 | () -> assertEquals(
28 | nextStage.executor,
29 | EDIT_IMAGE_HTTP_EXECUTOR
30 | ),
31 | () -> assertInstanceOf(
32 | PromptfulImagesRuntimeSelectionStage.class,
33 | nextStage.runtimeSelector.apply(null)
34 | ),
35 | () -> editImageRequestIsPopulated(nextStage)
36 | );
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/test/java/bg/codexio/ai/openai/api/sdk/images/VariatingActionTypeStageTest.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.images;
2 |
3 | import org.junit.jupiter.api.BeforeEach;
4 | import org.junit.jupiter.api.Test;
5 |
6 | import java.io.File;
7 |
8 | import static bg.codexio.ai.openai.api.sdk.images.InternalAssertions.*;
9 | import static org.junit.jupiter.api.Assertions.*;
10 |
11 | public class VariatingActionTypeStageTest {
12 |
13 | private VariatingActionTypeStage variatingActionTypeStage;
14 |
15 | @BeforeEach
16 | public void setUp() {
17 | this.variatingActionTypeStage =
18 | new VariatingActionTypeStage(IMAGE_VARIATION_HTTP_EXECUTOR);
19 | }
20 |
21 | @Test
22 | public void testAnother_executorShouldBeForVariations() {
23 | var nextStage =
24 | this.variatingActionTypeStage.another(new File(TEST_FILE_PATH));
25 |
26 | assertAll(
27 | () -> assertEquals(
28 | nextStage.executor,
29 | IMAGE_VARIATION_HTTP_EXECUTOR
30 | ),
31 | () -> assertInstanceOf(
32 | PromptlessImagesRuntimeSelectionStage.class,
33 | nextStage.runtimeSelector.apply(null)
34 | ),
35 | () -> imageVariationRequestIsPopulated(nextStage)
36 | );
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/test/java/bg/codexio/ai/openai/api/sdk/message/MessageActionTypeStageTest.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.message;
2 |
3 | import org.junit.jupiter.api.BeforeEach;
4 | import org.junit.jupiter.api.Test;
5 |
6 | import static bg.codexio.ai.openai.api.sdk.message.InternalAssertions.MESSAGE_HTTP_EXECUTOR;
7 | import static bg.codexio.ai.openai.api.sdk.message.InternalAssertions.RETRIEVE_LIST_MESSAGES_HTTP_EXECUTOR;
8 | import static bg.codexio.ai.openai.api.sdk.thread.InternalAssertions.THREAD_ID;
9 | import static org.junit.jupiter.api.Assertions.assertNotNull;
10 |
11 | public class MessageActionTypeStageTest {
12 |
13 | private MessageActionTypeStage messageActionTypeStage;
14 |
15 | @BeforeEach
16 | void setUp() {
17 | this.messageActionTypeStage = new MessageActionTypeStage(
18 | MESSAGE_HTTP_EXECUTOR,
19 | RETRIEVE_LIST_MESSAGES_HTTP_EXECUTOR,
20 | THREAD_ID
21 | );
22 | }
23 |
24 | @Test
25 | void testChat_expectCorrectBuilder() {
26 | var nextStage = this.messageActionTypeStage.chat();
27 |
28 | assertNotNull(nextStage);
29 |
30 | }
31 |
32 | @Test
33 | void testRespond_expectCorrectBuilder() {
34 | var nextStage = this.messageActionTypeStage.respond();
35 |
36 | assertNotNull(nextStage);
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/test/java/bg/codexio/ai/openai/api/sdk/thread/ThreadCreationMetaStageTest.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.thread;
2 |
3 | import bg.codexio.ai.openai.api.payload.thread.request.ThreadCreationRequest;
4 | import org.junit.jupiter.api.BeforeEach;
5 | import org.junit.jupiter.api.Test;
6 |
7 | import static bg.codexio.ai.openai.api.sdk.CommonTestAssertions.METADATA_MAP;
8 | import static bg.codexio.ai.openai.api.sdk.CommonTestAssertions.METADATA_VAR_ARGS;
9 | import static bg.codexio.ai.openai.api.sdk.thread.InternalAssertions.*;
10 | import static org.junit.jupiter.api.Assertions.assertAll;
11 | import static org.junit.jupiter.api.Assertions.assertEquals;
12 |
13 | public class ThreadCreationMetaStageTest {
14 |
15 | private ThreadMetaStage threadMetaStage;
16 |
17 | @BeforeEach
18 | void setUp() {
19 | this.threadMetaStage = new ThreadMetaStage<>(
20 | CREATE_THREAD_HTTP_EXECUTOR,
21 | THREAD_CREATION_REQUEST_BUILDER
22 | );
23 | }
24 |
25 | @Test
26 | void testAwareOf_expectCorrectBuilder() {
27 | var nextStage = this.threadMetaStage.awareOf(METADATA_VAR_ARGS);
28 |
29 | assertAll(
30 | () -> messagesRemainsUnchanged(
31 | this.threadMetaStage,
32 | nextStage
33 | ),
34 | () -> assertEquals(
35 | METADATA_MAP,
36 | nextStage.requestBuilder.metadata()
37 | )
38 | );
39 |
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/test/java/bg/codexio/ai/openai/api/sdk/thread/ThreadCreationStageTest.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.thread;
2 |
3 | import bg.codexio.ai.openai.api.payload.thread.request.ThreadCreationRequest;
4 | import org.junit.jupiter.api.BeforeEach;
5 | import org.junit.jupiter.api.Test;
6 |
7 | import static bg.codexio.ai.openai.api.sdk.thread.InternalAssertions.*;
8 | import static org.junit.jupiter.api.Assertions.*;
9 |
10 | public class ThreadCreationStageTest {
11 |
12 | private ThreadCreationStage threadCreationStage;
13 |
14 | @BeforeEach
15 | void setUp() {
16 | this.threadCreationStage = new ThreadCreationStage<>(
17 | CREATE_THREAD_HTTP_EXECUTOR,
18 | THREAD_CREATION_REQUEST_BUILDER
19 | );
20 | }
21 |
22 | @Test
23 | void testEmpty_expectCorrectResponse() {
24 | execute(this.threadCreationStage);
25 | var response = this.threadCreationStage.empty();
26 |
27 | assertEquals(
28 | THREAD_RESPONSE,
29 | response
30 | );
31 | }
32 |
33 | @Test
34 | void testDeepConfigure_expectCorrectBuilder() {
35 | var nextStage = this.threadCreationStage.deepConfigure();
36 |
37 | assertAll(
38 | () -> assertNotNull(nextStage.httpExecutor),
39 | () -> createThreadRequestIsPopulated(nextStage)
40 | );
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/test/java/bg/codexio/ai/openai/api/sdk/thread/ThreadModificationMetaStageTest.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.thread;
2 |
3 | import bg.codexio.ai.openai.api.payload.thread.request.ThreadModificationRequest;
4 | import org.junit.jupiter.api.BeforeEach;
5 | import org.junit.jupiter.api.Test;
6 |
7 | import static bg.codexio.ai.openai.api.sdk.CommonTestAssertions.METADATA_MAP;
8 | import static bg.codexio.ai.openai.api.sdk.CommonTestAssertions.METADATA_VAR_ARGS;
9 | import static bg.codexio.ai.openai.api.sdk.thread.InternalAssertions.MODIFY_THREAD_HTTP_EXECUTOR;
10 | import static bg.codexio.ai.openai.api.sdk.thread.InternalAssertions.THREAD_MODIFICATION_REQUEST_THREAD_REQUEST_BUILDER;
11 | import static org.junit.jupiter.api.Assertions.assertEquals;
12 |
13 | public class ThreadModificationMetaStageTest {
14 |
15 | private ThreadMetaStage threadMetaStage;
16 |
17 | @BeforeEach
18 | void setUp() {
19 | this.threadMetaStage = new ThreadMetaStage<>(
20 | MODIFY_THREAD_HTTP_EXECUTOR,
21 | THREAD_MODIFICATION_REQUEST_THREAD_REQUEST_BUILDER
22 | );
23 | }
24 |
25 | @Test
26 | void testAwareOf_expectCorrectBuilder() {
27 | var nextStage = this.threadMetaStage.awareOf(METADATA_VAR_ARGS);
28 |
29 | assertEquals(
30 | METADATA_MAP,
31 | nextStage.requestBuilder.metadata()
32 | );
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/test/java/bg/codexio/ai/openai/api/sdk/voice/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CodexioLtd/openai-api-sdk/584766f390964541c2a0138677038e5e06bfc937/openai-api-sdk/src/test/java/bg/codexio/ai/openai/api/sdk/voice/.gitkeep
--------------------------------------------------------------------------------
/openai-api-sdk/src/test/java/bg/codexio/ai/openai/api/sdk/voice/transcription/PreSimplifiedStageTest.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.voice.transcription;
2 |
3 | import bg.codexio.ai.openai.api.payload.credentials.ApiCredentials;
4 | import org.junit.jupiter.api.BeforeEach;
5 | import org.junit.jupiter.api.Test;
6 |
7 | import static bg.codexio.ai.openai.api.sdk.voice.transcription.InternalAssertions.TEST_FILE;
8 | import static org.junit.jupiter.api.Assertions.assertAll;
9 | import static org.junit.jupiter.api.Assertions.assertEquals;
10 |
11 | public class PreSimplifiedStageTest {
12 |
13 | private PreSimplifiedStage preSimplifiedStage;
14 |
15 | @BeforeEach
16 | public void setUp() {
17 | this.preSimplifiedStage = new PreSimplifiedStage(new ApiCredentials(
18 | "testKey"));
19 | }
20 |
21 | @Test
22 | public void testEnsureRuntimeSelectionStage_expectFilledRuntimeSelectionStage() {
23 | var nextStage = this.preSimplifiedStage.transcribe(TEST_FILE);
24 |
25 | assertEquals(
26 | TEST_FILE,
27 | nextStage.requestBuilder.file()
28 | );
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/test/java/bg/codexio/ai/openai/api/sdk/voice/translation/PreSimplifiedStageTest.java:
--------------------------------------------------------------------------------
1 | package bg.codexio.ai.openai.api.sdk.voice.translation;
2 |
3 | import bg.codexio.ai.openai.api.payload.credentials.ApiCredentials;
4 | import org.junit.jupiter.api.BeforeEach;
5 | import org.junit.jupiter.api.Test;
6 |
7 | import static bg.codexio.ai.openai.api.sdk.voice.translation.InternalAssertions.TEST_FILE;
8 | import static org.junit.jupiter.api.Assertions.assertAll;
9 | import static org.junit.jupiter.api.Assertions.assertEquals;
10 |
11 | public class PreSimplifiedStageTest {
12 |
13 | private PreSimplifiedStage preSimplifiedStage;
14 |
15 | @BeforeEach
16 | public void setUp() {
17 | this.preSimplifiedStage = new PreSimplifiedStage(new ApiCredentials(
18 | "testKey"));
19 | }
20 |
21 | @Test
22 | public void testEnsureRuntimeSelectionStage_expectFilledRuntimeSelectionStage() {
23 | var nextStage = this.preSimplifiedStage.translate(TEST_FILE);
24 |
25 | assertEquals(
26 | TEST_FILE,
27 | nextStage.requestBuilder.file()
28 | );
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/test/resources/fake-file.txt:
--------------------------------------------------------------------------------
1 | test
2 |
--------------------------------------------------------------------------------
/openai-api-sdk/src/test/resources/test-key.json:
--------------------------------------------------------------------------------
1 | {
2 | "apiKey": "sk-1234"
3 | }
4 |
--------------------------------------------------------------------------------
/project-logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CodexioLtd/openai-api-sdk/584766f390964541c2a0138677038e5e06bfc937/project-logo.png
--------------------------------------------------------------------------------
/scaled-java-cat-min.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CodexioLtd/openai-api-sdk/584766f390964541c2a0138677038e5e06bfc937/scaled-java-cat-min.png
--------------------------------------------------------------------------------