@@ -13,6 +13,7 @@ import com.fasterxml.jackson.databind.module.SimpleModule
1313import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
1414import okhttp3.OkHttpClient
1515import org.jetbrains.annotations.ApiStatus
16+ import org.jetbrains.annotations.Contract
1617
1718interface OpenAI {
1819
@@ -28,6 +29,7 @@ interface OpenAI {
2829 * @return The response from the API
2930 */
3031 @ApiStatus.Obsolete
32+ @Contract(pure = true )
3133 fun createCompletion (request : CompletionRequest ): CompletionResponse
3234
3335 /* *
@@ -52,6 +54,7 @@ interface OpenAI {
5254 * @return The response from the API
5355 */
5456 @ApiStatus.Obsolete
57+ @Contract(pure = true )
5558 fun streamCompletion (request : CompletionRequest ): Iterable <CompletionResponseChunk >
5659
5760 /* *
@@ -61,6 +64,7 @@ interface OpenAI {
6164 * @param request The request to send to the API
6265 * @return The response from the API
6366 */
67+ @Contract(pure = true )
6468 fun createChatCompletion (request : ChatRequest ): ChatResponse
6569
6670 /* *
@@ -79,6 +83,7 @@ interface OpenAI {
7983 * @param request The request to send to the API
8084 * @return The response from the API
8185 */
86+ @Contract(pure = true )
8287 fun streamChatCompletion (request : ChatRequest ): Iterable <ChatResponseChunk >
8388
8489 @OpenAIDslMarker
@@ -91,6 +96,7 @@ interface OpenAI {
9196 fun organization (organization : String? ) = apply { this .organization = organization }
9297 fun client (client : OkHttpClient ) = apply { this .client = client }
9398
99+ @Contract(pure = true )
94100 open fun build (): OpenAI {
95101 return OpenAIImpl (
96102 apiKey ? : throw IllegalStateException (" apiKey must be defined to use OpenAI" ),
@@ -110,6 +116,7 @@ interface OpenAI {
110116 fun apiVersion (apiVersion : String ) = apply { this .apiVersion = apiVersion }
111117 fun modelName (modelName : String ) = apply { this .modelName = modelName }
112118
119+ @Contract(pure = true )
113120 override fun build (): OpenAI {
114121 return AzureOpenAI (
115122 apiKey ? : throw IllegalStateException (" apiKey must be defined to use OpenAI" ),
@@ -129,18 +136,21 @@ interface OpenAI {
129136 * OpenAI, use [azureBuilder] instead.
130137 */
131138 @JvmStatic
139+ @Contract(pure = true )
132140 fun builder () = Builder ()
133141
134142 /* *
135143 * Instantiates a builder for an Azure OpenAI.
136144 */
137145 @JvmStatic
146+ @Contract(pure = true )
138147 fun azureBuilder () = AzureBuilder ()
139148
140149 /* *
141150 * Returns an ObjectMapper instance with the default OpenAI adapters registered.
142151 * This can be used to save conversations (and other data) to file.
143152 */
153+ @Contract(pure = true )
144154 fun createObjectMapper (): ObjectMapper = jacksonObjectMapper().apply {
145155 setSerializationInclusion(JsonInclude .Include .NON_NULL )
146156 configure(DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES , false )
@@ -172,6 +182,8 @@ interface OpenAI {
172182 }
173183}
174184
185+ @Contract(pure = true )
175186fun openAI (init : OpenAI .Builder .() -> Unit ) = OpenAI .builder().apply (init ).build()
176187
188+ @Contract(pure = true )
177189fun azureOpenAI (init : OpenAI .AzureBuilder .() -> Unit ) = OpenAI .azureBuilder().apply (init ).build()
0 commit comments