@@ -4,13 +4,7 @@ import sttp.capabilities.Streams
4
4
import sttp .client4 ._
5
5
import sttp .model .{Header , Uri }
6
6
import sttp .openai .OpenAIExceptions .OpenAIException
7
- import sttp .openai .json .SttpUpickleApiExtension .{
8
- asInputStreamUnsafe_parseErrors ,
9
- asJson_parseErrors ,
10
- asStreamUnsafe_parseErrors ,
11
- asStringEither ,
12
- upickleBodySerializer
13
- }
7
+ import sttp .openai .json .SttpUpickleApiExtension ._
14
8
import sttp .openai .requests .admin .{QueryParameters => _ , _ }
15
9
import sttp .openai .requests .assistants .AssistantsRequestBody .{CreateAssistantBody , ModifyAssistantBody }
16
10
import sttp .openai .requests .assistants .AssistantsResponseData .{AssistantData , DeleteAssistantResponse , ListAssistantsResponse }
@@ -99,7 +93,7 @@ class OpenAI(authToken: String, baseUri: Uri = OpenAIUris.OpenAIBaseUri) {
99
93
def createCompletion (completionBody : CompletionsBody ): Request [Either [OpenAIException , CompletionsResponse ]] =
100
94
openAIAuthRequest
101
95
.post(openAIUris.Completions )
102
- .body(completionBody)
96
+ .body(asJson( completionBody) )
103
97
.response(asJson_parseErrors[CompletionsResponse ])
104
98
105
99
/** Creates an image given a prompt in request body.
@@ -112,7 +106,7 @@ class OpenAI(authToken: String, baseUri: Uri = OpenAIUris.OpenAIBaseUri) {
112
106
def createImage (imageCreationBody : ImageCreationBody ): Request [Either [OpenAIException , ImageResponse ]] =
113
107
openAIAuthRequest
114
108
.post(openAIUris.CreateImage )
115
- .body(imageCreationBody)
109
+ .body(asJson( imageCreationBody) )
116
110
.response(asJson_parseErrors[ImageResponse ])
117
111
118
112
/** Creates edited or extended images given an original image and a prompt.
@@ -175,7 +169,7 @@ class OpenAI(authToken: String, baseUri: Uri = OpenAIUris.OpenAIBaseUri) {
175
169
Some (multipartFile(" image" , image)),
176
170
Some (multipart(" prompt" , prompt)),
177
171
mask.map(multipartFile(" mask" , _)),
178
- n.map(multipart(" n" , _ )),
172
+ n.map(i => multipart(" n" , i.toString )),
179
173
size.map(s => multipart(" size" , s.value)),
180
174
responseFormat.map(format => multipart(" response_format" , format.value))
181
175
).flatten
@@ -236,7 +230,7 @@ class OpenAI(authToken: String, baseUri: Uri = OpenAIUris.OpenAIBaseUri) {
236
230
import imageVariationsConfig ._
237
231
Seq (
238
232
Some (multipartFile(" image" , image)),
239
- n.map(multipart(" n" , _ )),
233
+ n.map(i => multipart(" n" , i.toString )),
240
234
size.map(s => multipart(" size" , s.value)),
241
235
responseFormat.map(format => multipart(" response_format" , format.value)),
242
236
user.map(multipart(" user" , _))
@@ -254,7 +248,7 @@ class OpenAI(authToken: String, baseUri: Uri = OpenAIUris.OpenAIBaseUri) {
254
248
def createChatCompletion (chatBody : ChatBody ): Request [Either [OpenAIException , ChatResponse ]] =
255
249
openAIAuthRequest
256
250
.post(openAIUris.ChatCompletions )
257
- .body(chatBody)
251
+ .body(asJson( chatBody) )
258
252
.response(asJson_parseErrors[ChatResponse ])
259
253
260
254
/** Creates a model response for the given chat conversation defined in chatBody.
@@ -272,7 +266,7 @@ class OpenAI(authToken: String, baseUri: Uri = OpenAIUris.OpenAIBaseUri) {
272
266
def createChatCompletionAsBinaryStream [S ](s : Streams [S ], chatBody : ChatBody ): StreamRequest [Either [OpenAIException , s.BinaryStream ], S ] =
273
267
openAIAuthRequest
274
268
.post(openAIUris.ChatCompletions )
275
- .body(ChatBody .withStreaming(chatBody))
269
+ .body(asJson( ChatBody .withStreaming(chatBody) ))
276
270
.response(asStreamUnsafe_parseErrors(s))
277
271
278
272
/** Creates a model response for the given chat conversation defined in chatBody.
@@ -287,7 +281,7 @@ class OpenAI(authToken: String, baseUri: Uri = OpenAIUris.OpenAIBaseUri) {
287
281
def createChatCompletionAsInputStream (chatBody : ChatBody ): Request [Either [OpenAIException , InputStream ]] =
288
282
openAIAuthRequest
289
283
.post(openAIUris.ChatCompletions )
290
- .body(ChatBody .withStreaming(chatBody))
284
+ .body(asJson( ChatBody .withStreaming(chatBody) ))
291
285
.response(asInputStreamUnsafe_parseErrors)
292
286
293
287
/** Get a stored chat completion. Only chat completions that have been created with the store parameter set to true will be returned.
@@ -366,7 +360,7 @@ class OpenAI(authToken: String, baseUri: Uri = OpenAIUris.OpenAIBaseUri) {
366
360
): Request [Either [OpenAIException , ChatResponse ]] =
367
361
openAIAuthRequest
368
362
.post(openAIUris.chatCompletion(completionId))
369
- .body(requestBody)
363
+ .body(asJson( requestBody) )
370
364
.response(asJson_parseErrors[ChatResponse ])
371
365
372
366
/** Delete a stored chat completion. Only chat completions that have been created with the store parameter set to true can be deleted.
@@ -546,7 +540,7 @@ class OpenAI(authToken: String, baseUri: Uri = OpenAIUris.OpenAIBaseUri) {
546
540
.post(openAIUris.Translations )
547
541
.multipartBody(
548
542
multipartFile(" file" , Paths .get(systemPath).toFile),
549
- multipart(" model" , model)
543
+ multipart(" model" , asJson( model) )
550
544
)
551
545
.response(asJson_parseErrors[AudioResponse ])
552
546
@@ -566,8 +560,8 @@ class OpenAI(authToken: String, baseUri: Uri = OpenAIUris.OpenAIBaseUri) {
566
560
Some (multipartFile(" file" , file)),
567
561
Some (multipart(" model" , model.value)),
568
562
prompt.map(multipart(" prompt" , _)),
569
- responseFormat.map(format => multipart(" response_format" , format)),
570
- temperature.map(multipart(" temperature" , _ )),
563
+ responseFormat.map(format => multipart(" response_format" , asJson( format) )),
564
+ temperature.map(i => multipart(" temperature" , i.toString )),
571
565
language.map(multipart(" language" , _))
572
566
).flatten
573
567
}
@@ -583,7 +577,7 @@ class OpenAI(authToken: String, baseUri: Uri = OpenAIUris.OpenAIBaseUri) {
583
577
def createModeration (moderationsBody : ModerationsBody ): Request [Either [OpenAIException , ModerationData ]] =
584
578
openAIAuthRequest
585
579
.post(openAIUris.Moderations )
586
- .body(moderationsBody)
580
+ .body(asJson( moderationsBody) )
587
581
.response(asJson_parseErrors[ModerationData ])
588
582
589
583
/** Transcribes audio into the input language.
@@ -642,7 +636,7 @@ class OpenAI(authToken: String, baseUri: Uri = OpenAIUris.OpenAIBaseUri) {
642
636
Some (multipart(" model" , model.value)),
643
637
prompt.map(multipart(" prompt" , _)),
644
638
responseFormat.map(format => multipart(" response_format" , format.value)),
645
- temperature.map(multipart(" temperature" , _ )),
639
+ temperature.map(t => multipart(" temperature" , t.toString )),
646
640
language.map(lang => multipart(" language" , lang.value))
647
641
).flatten
648
642
}
@@ -672,7 +666,7 @@ class OpenAI(authToken: String, baseUri: Uri = OpenAIUris.OpenAIBaseUri) {
672
666
def createUpload (uploadRequestBody : UploadRequestBody ): Request [Either [OpenAIException , UploadResponse ]] =
673
667
openAIAuthRequest
674
668
.post(openAIUris.Uploads )
675
- .body(uploadRequestBody)
669
+ .body(asJson( uploadRequestBody) )
676
670
.response(asJson_parseErrors[UploadResponse ])
677
671
678
672
/** Adds a Part to an Upload object. A Part represents a chunk of bytes from the file you are trying to upload.
@@ -719,7 +713,7 @@ class OpenAI(authToken: String, baseUri: Uri = OpenAIUris.OpenAIBaseUri) {
719
713
def completeUpload (uploadId : String , requestBody : CompleteUploadRequestBody ): Request [Either [OpenAIException , UploadResponse ]] =
720
714
openAIAuthRequest
721
715
.post(openAIUris.completeUpload(uploadId))
722
- .body(requestBody)
716
+ .body(asJson( requestBody) )
723
717
.response(asJson_parseErrors[UploadResponse ])
724
718
725
719
/** Cancels the Upload. No Parts may be added after an Upload is cancelled.
@@ -749,7 +743,7 @@ class OpenAI(authToken: String, baseUri: Uri = OpenAIUris.OpenAIBaseUri) {
749
743
def createFineTuningJob (fineTuningRequestBody : FineTuningJobRequestBody ): Request [Either [OpenAIException , FineTuningJobResponse ]] =
750
744
openAIAuthRequest
751
745
.post(openAIUris.FineTuningJobs )
752
- .body(fineTuningRequestBody)
746
+ .body(asJson( fineTuningRequestBody) )
753
747
.response(asJson_parseErrors[FineTuningJobResponse ])
754
748
755
749
/** List your organization's fine-tuning jobs
@@ -841,7 +835,7 @@ class OpenAI(authToken: String, baseUri: Uri = OpenAIUris.OpenAIBaseUri) {
841
835
def createEmbeddings (embeddingsBody : EmbeddingsBody ): Request [Either [OpenAIException , EmbeddingResponse ]] =
842
836
openAIAuthRequest
843
837
.post(openAIUris.Embeddings )
844
- .body(embeddingsBody)
838
+ .body(asJson( embeddingsBody) )
845
839
.response(asJson_parseErrors[EmbeddingResponse ])
846
840
847
841
/** Create a thread.
@@ -854,7 +848,7 @@ class OpenAI(authToken: String, baseUri: Uri = OpenAIUris.OpenAIBaseUri) {
854
848
def createThread (createThreadBody : CreateThreadBody ): Request [Either [OpenAIException , ThreadData ]] =
855
849
betaOpenAIAuthRequest
856
850
.post(openAIUris.Threads )
857
- .body(createThreadBody)
851
+ .body(asJson( createThreadBody) )
858
852
.response(asJson_parseErrors[ThreadData ])
859
853
860
854
/** Retrieves a thread.
@@ -904,7 +898,7 @@ class OpenAI(authToken: String, baseUri: Uri = OpenAIUris.OpenAIBaseUri) {
904
898
def createThreadMessage (threadId : String , message : CreateMessage ): Request [Either [OpenAIException , MessageData ]] =
905
899
betaOpenAIAuthRequest
906
900
.post(openAIUris.threadMessages(threadId))
907
- .body(message)
901
+ .body(asJson( message) )
908
902
.response(asJson_parseErrors[MessageData ])
909
903
910
904
/** Returns a list of messages for a given thread.
@@ -989,7 +983,7 @@ class OpenAI(authToken: String, baseUri: Uri = OpenAIUris.OpenAIBaseUri) {
989
983
def createAssistant (createAssistantBody : CreateAssistantBody ): Request [Either [OpenAIException , AssistantData ]] =
990
984
betaOpenAIAuthRequest
991
985
.post(openAIUris.Assistants )
992
- .body(createAssistantBody)
986
+ .body(asJson( createAssistantBody) )
993
987
.response(asJson_parseErrors[AssistantData ])
994
988
995
989
/** Returns a list of assistants.
@@ -1032,7 +1026,7 @@ class OpenAI(authToken: String, baseUri: Uri = OpenAIUris.OpenAIBaseUri) {
1032
1026
def modifyAssistant (assistantId : String , modifyAssistantBody : ModifyAssistantBody ): Request [Either [OpenAIException , AssistantData ]] =
1033
1027
betaOpenAIAuthRequest
1034
1028
.post(openAIUris.assistant(assistantId))
1035
- .body(modifyAssistantBody)
1029
+ .body(asJson( modifyAssistantBody) )
1036
1030
.response(asJson_parseErrors[AssistantData ])
1037
1031
1038
1032
/** Delete an assistant.
@@ -1059,7 +1053,7 @@ class OpenAI(authToken: String, baseUri: Uri = OpenAIUris.OpenAIBaseUri) {
1059
1053
def createRun (threadId : String , createRun : CreateRun ): Request [Either [OpenAIException , RunData ]] =
1060
1054
betaOpenAIAuthRequest
1061
1055
.post(openAIUris.threadRuns(threadId))
1062
- .body(createRun)
1056
+ .body(asJson( createRun) )
1063
1057
.response(asJson_parseErrors[RunData ])
1064
1058
1065
1059
/** Create a thread and run it in one request.
@@ -1072,7 +1066,7 @@ class OpenAI(authToken: String, baseUri: Uri = OpenAIUris.OpenAIBaseUri) {
1072
1066
def createThreadAndRun (createThreadAndRun : CreateThreadAndRun ): Request [Either [OpenAIException , RunData ]] =
1073
1067
betaOpenAIAuthRequest
1074
1068
.post(openAIUris.ThreadsRuns )
1075
- .body(createThreadAndRun)
1069
+ .body(asJson( createThreadAndRun) )
1076
1070
.response(asJson_parseErrors[RunData ])
1077
1071
1078
1072
/** Returns a list of runs belonging to a thread..
@@ -1157,7 +1151,7 @@ class OpenAI(authToken: String, baseUri: Uri = OpenAIUris.OpenAIBaseUri) {
1157
1151
def modifyRun (threadId : String , runId : String , metadata : Map [String , String ]): Request [Either [OpenAIException , RunData ]] =
1158
1152
betaOpenAIAuthRequest
1159
1153
.post(openAIUris.threadRun(threadId, runId))
1160
- .body(ModifyRun (metadata))
1154
+ .body(asJson( ModifyRun (metadata) ))
1161
1155
.response(asJson_parseErrors[RunData ])
1162
1156
1163
1157
/** When a run has the status: "requires_action" and required_action.type is submit_tool_outputs, this endpoint can be used to submit the
@@ -1175,7 +1169,7 @@ class OpenAI(authToken: String, baseUri: Uri = OpenAIUris.OpenAIBaseUri) {
1175
1169
def submitToolOutputs (threadId : String , runId : String , toolOutputs : Seq [ToolOutput ]): Request [Either [OpenAIException , RunData ]] =
1176
1170
betaOpenAIAuthRequest
1177
1171
.post(openAIUris.threadRunSubmitToolOutputs(threadId, runId))
1178
- .body(SubmitToolOutputsToRun (toolOutputs))
1172
+ .body(asJson( SubmitToolOutputsToRun (toolOutputs) ))
1179
1173
.response(asJson_parseErrors[RunData ])
1180
1174
1181
1175
/** Cancels a run that is in_progress.
@@ -1203,7 +1197,7 @@ class OpenAI(authToken: String, baseUri: Uri = OpenAIUris.OpenAIBaseUri) {
1203
1197
def createVectorStore (createVectorStoreBody : CreateVectorStoreBody ): Request [Either [OpenAIException , VectorStore ]] =
1204
1198
betaOpenAIAuthRequest
1205
1199
.post(openAIUris.VectorStores )
1206
- .body(createVectorStoreBody)
1200
+ .body(asJson( createVectorStoreBody) )
1207
1201
.response(asJson_parseErrors[VectorStore ])
1208
1202
1209
1203
/** Lists vector store
@@ -1247,7 +1241,7 @@ class OpenAI(authToken: String, baseUri: Uri = OpenAIUris.OpenAIBaseUri) {
1247
1241
): Request [Either [OpenAIException , VectorStore ]] =
1248
1242
betaOpenAIAuthRequest
1249
1243
.post(openAIUris.vectorStore(vectorStoreId))
1250
- .body(modifyVectorStoreBody)
1244
+ .body(asJson( modifyVectorStoreBody) )
1251
1245
.response(asJson_parseErrors[VectorStore ])
1252
1246
1253
1247
/** Deletes vector store
@@ -1277,7 +1271,7 @@ class OpenAI(authToken: String, baseUri: Uri = OpenAIUris.OpenAIBaseUri) {
1277
1271
): Request [Either [OpenAIException , VectorStoreFile ]] =
1278
1272
betaOpenAIAuthRequest
1279
1273
.post(openAIUris.vectorStoreFiles(vectorStoreId))
1280
- .body(createVectorStoreFileBody)
1274
+ .body(asJson( createVectorStoreFileBody) )
1281
1275
.response(asJson_parseErrors[VectorStoreFile ])
1282
1276
1283
1277
/** List files belonging to particular datastore
@@ -1337,7 +1331,7 @@ class OpenAI(authToken: String, baseUri: Uri = OpenAIUris.OpenAIBaseUri) {
1337
1331
def createBatch (createBatchRequest : BatchRequestBody ): Request [Either [OpenAIException , BatchResponse ]] =
1338
1332
openAIAuthRequest
1339
1333
.post(openAIUris.Batches )
1340
- .body(createBatchRequest)
1334
+ .body(asJson( createBatchRequest) )
1341
1335
.response(asJson_parseErrors[BatchResponse ])
1342
1336
1343
1337
/** Retrieves a batch.
@@ -1399,7 +1393,7 @@ class OpenAI(authToken: String, baseUri: Uri = OpenAIUris.OpenAIBaseUri) {
1399
1393
def createAdminApiKey (createAdminApiKeyRequest : AdminApiKeyRequestBody ): Request [Either [OpenAIException , AdminApiKeyResponse ]] =
1400
1394
openAIAuthRequest
1401
1395
.post(openAIUris.AdminApiKeys )
1402
- .body(createAdminApiKeyRequest)
1396
+ .body(asJson( createAdminApiKeyRequest) )
1403
1397
.response(asJson_parseErrors[AdminApiKeyResponse ])
1404
1398
1405
1399
/** Retrieve a single organization API key
0 commit comments