@@ -13,6 +13,7 @@ import com.fasterxml.jackson.databind.module.SimpleModule
13
13
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
14
14
import okhttp3.OkHttpClient
15
15
import org.jetbrains.annotations.ApiStatus
16
+ import org.jetbrains.annotations.Contract
16
17
17
18
interface OpenAI {
18
19
@@ -28,6 +29,7 @@ interface OpenAI {
28
29
* @return The response from the API
29
30
*/
30
31
@ApiStatus.Obsolete
32
+ @Contract(pure = true )
31
33
fun createCompletion (request : CompletionRequest ): CompletionResponse
32
34
33
35
/* *
@@ -52,6 +54,7 @@ interface OpenAI {
52
54
* @return The response from the API
53
55
*/
54
56
@ApiStatus.Obsolete
57
+ @Contract(pure = true )
55
58
fun streamCompletion (request : CompletionRequest ): Iterable <CompletionResponseChunk >
56
59
57
60
/* *
@@ -61,6 +64,7 @@ interface OpenAI {
61
64
* @param request The request to send to the API
62
65
* @return The response from the API
63
66
*/
67
+ @Contract(pure = true )
64
68
fun createChatCompletion (request : ChatRequest ): ChatResponse
65
69
66
70
/* *
@@ -79,6 +83,7 @@ interface OpenAI {
79
83
* @param request The request to send to the API
80
84
* @return The response from the API
81
85
*/
86
+ @Contract(pure = true )
82
87
fun streamChatCompletion (request : ChatRequest ): Iterable <ChatResponseChunk >
83
88
84
89
@OpenAIDslMarker
@@ -91,6 +96,7 @@ interface OpenAI {
91
96
fun organization (organization : String? ) = apply { this .organization = organization }
92
97
fun client (client : OkHttpClient ) = apply { this .client = client }
93
98
99
+ @Contract(pure = true )
94
100
open fun build (): OpenAI {
95
101
return OpenAIImpl (
96
102
apiKey ? : throw IllegalStateException (" apiKey must be defined to use OpenAI" ),
@@ -110,6 +116,7 @@ interface OpenAI {
110
116
fun apiVersion (apiVersion : String ) = apply { this .apiVersion = apiVersion }
111
117
fun modelName (modelName : String ) = apply { this .modelName = modelName }
112
118
119
+ @Contract(pure = true )
113
120
override fun build (): OpenAI {
114
121
return AzureOpenAI (
115
122
apiKey ? : throw IllegalStateException (" apiKey must be defined to use OpenAI" ),
@@ -129,18 +136,21 @@ interface OpenAI {
129
136
* OpenAI, use [azureBuilder] instead.
130
137
*/
131
138
@JvmStatic
139
+ @Contract(pure = true )
132
140
fun builder () = Builder ()
133
141
134
142
/* *
135
143
* Instantiates a builder for an Azure OpenAI.
136
144
*/
137
145
@JvmStatic
146
+ @Contract(pure = true )
138
147
fun azureBuilder () = AzureBuilder ()
139
148
140
149
/* *
141
150
* Returns an ObjectMapper instance with the default OpenAI adapters registered.
142
151
* This can be used to save conversations (and other data) to file.
143
152
*/
153
+ @Contract(pure = true )
144
154
fun createObjectMapper (): ObjectMapper = jacksonObjectMapper().apply {
145
155
setSerializationInclusion(JsonInclude .Include .NON_NULL )
146
156
configure(DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES , false )
@@ -172,6 +182,8 @@ interface OpenAI {
172
182
}
173
183
}
174
184
185
+ @Contract(pure = true )
175
186
fun openAI (init : OpenAI .Builder .() -> Unit ) = OpenAI .builder().apply (init ).build()
176
187
188
+ @Contract(pure = true )
177
189
fun azureOpenAI (init : OpenAI .AzureBuilder .() -> Unit ) = OpenAI .azureBuilder().apply (init ).build()
0 commit comments