@@ -24,6 +24,8 @@ import sttp.openai.requests.completions.chat.ChatRequestResponseData.ChatRespons
24
24
import sttp .openai .requests .embeddings .EmbeddingsRequestBody .EmbeddingsBody
25
25
import sttp .openai .requests .embeddings .EmbeddingsResponseBody .EmbeddingResponse
26
26
import sttp .openai .requests .files .FilesResponseData ._
27
+ import sttp .openai .requests .finetuning
28
+ import sttp .openai .requests .finetuning ._
27
29
import sttp .openai .requests .images .ImageResponseData .ImageResponse
28
30
import sttp .openai .requests .images .creation .ImageCreationRequestBody .ImageCreationBody
29
31
import sttp .openai .requests .images .edit .ImageEditsConfig
@@ -82,7 +84,7 @@ class OpenAI(authToken: String, baseUri: Uri = OpenAIUris.OpenAIBaseUri) {
82
84
* @param completionBody
83
85
* Create completion request body.
84
86
* @deprecated
85
- * This is marked as Legacy in OpenAI API and might be removed in the future. Please use createChatCompletion instead.
87
+ * This is marked as Legacy in OpenAI API and might be removed in the future. Please use [[ createChatCompletion ]] instead.
86
88
*/
87
89
def createCompletion (completionBody : CompletionsBody ): Request [Either [OpenAIException , CompletionsResponse ]] =
88
90
openAIAuthRequest
@@ -541,6 +543,100 @@ class OpenAI(authToken: String, baseUri: Uri = OpenAIUris.OpenAIBaseUri) {
541
543
}
542
544
.response(asJson_parseErrors[AudioResponse ])
543
545
546
+ /** Creates a fine-tuning job which begins the process of creating a new model from a given dataset.
547
+ *
548
+ * Response includes details of the enqueued job including job status and the name of the fine-tuned models once complete.
549
+ *
550
+ * [[https://platform.openai.com/docs/api-reference/fine-tuning/create ]]
551
+ *
552
+ * @param fineTuningRequestBody
553
+ * Request body that will be used to create a fine-tuning job.
554
+ */
555
+ def createFineTuningJob (fineTuningRequestBody : FineTuningJobRequestBody ): Request [Either [OpenAIException , FineTuningJobResponse ]] =
556
+ openAIAuthRequest
557
+ .post(openAIUris.FineTuningJobs )
558
+ .body(fineTuningRequestBody)
559
+ .response(asJson_parseErrors[FineTuningJobResponse ])
560
+
561
+ /** List your organization's fine-tuning jobs
562
+ *
563
+ * [[https://platform.openai.com/docs/api-reference/fine-tuning/list ]]
564
+ */
565
+ def listFineTuningJobs (
566
+ queryParameters : finetuning.QueryParameters = finetuning.QueryParameters .empty
567
+ ): Request [Either [OpenAIException , ListFineTuningJobResponse ]] = {
568
+ val uri = openAIUris.FineTuningJobs
569
+ .withParams(queryParameters.toMap)
570
+
571
+ openAIAuthRequest
572
+ .get(uri)
573
+ .response(asJson_parseErrors[ListFineTuningJobResponse ])
574
+ }
575
+
576
+ /** Get status updates for a fine-tuning job.
577
+ *
578
+ * [[https://platform.openai.com/docs/api-reference/fine-tuning/list-events ]]
579
+ *
580
+ * @param fineTuningJobId
581
+ * The ID of the fine-tuning job to get checkpoints for.
582
+ */
583
+ def listFineTuningJobEvents (
584
+ fineTuningJobId : String ,
585
+ queryParameters : finetuning.QueryParameters = finetuning.QueryParameters .empty
586
+ ): Request [Either [OpenAIException , ListFineTuningJobEventResponse ]] = {
587
+ val uri = openAIUris
588
+ .fineTuningJobEvents(fineTuningJobId)
589
+ .withParams(queryParameters.toMap)
590
+
591
+ openAIAuthRequest
592
+ .get(uri)
593
+ .response(asJson_parseErrors[ListFineTuningJobEventResponse ])
594
+ }
595
+
596
+ /** List checkpoints for a fine-tuning job.
597
+ *
598
+ * [[https://platform.openai.com/docs/api-reference/fine-tuning/list-checkpoints ]]
599
+ *
600
+ * @param fineTuningJobId
601
+ * The ID of the fine-tuning job to get checkpoints for.
602
+ */
603
+ def listFineTuningJobCheckpoints (
604
+ fineTuningJobId : String ,
605
+ queryParameters : finetuning.QueryParameters = finetuning.QueryParameters .empty
606
+ ): Request [Either [OpenAIException , ListFineTuningJobCheckpointResponse ]] = {
607
+ val uri = openAIUris
608
+ .fineTuningJobCheckpoints(fineTuningJobId)
609
+ .withParams(queryParameters.toMap)
610
+
611
+ openAIAuthRequest
612
+ .get(uri)
613
+ .response(asJson_parseErrors[ListFineTuningJobCheckpointResponse ])
614
+ }
615
+
616
+ /** Get info about a fine-tuning job.
617
+ *
618
+ * [[https://platform.openai.com/docs/api-reference/fine-tuning/retrieve ]]
619
+ *
620
+ * @param fineTuningJobId
621
+ * The ID of the fine-tuning job.
622
+ */
623
+ def retrieveFineTuningJob (fineTuningJobId : String ): Request [Either [OpenAIException , FineTuningJobResponse ]] =
624
+ openAIAuthRequest
625
+ .get(openAIUris.fineTuningJob(fineTuningJobId))
626
+ .response(asJson_parseErrors[FineTuningJobResponse ])
627
+
628
+ /** Immediately cancel a fine-tune job.
629
+ *
630
+ * [[https://platform.openai.com/docs/api-reference/fine-tuning/cancel ]]
631
+ *
632
+ * @param fineTuningJobId
633
+ * The ID of the fine-tuning job to cancel.
634
+ */
635
+ def cancelFineTuningJob (fineTuningJobId : String ): Request [Either [OpenAIException , FineTuningJobResponse ]] =
636
+ openAIAuthRequest
637
+ .post(openAIUris.cancelFineTuningJob(fineTuningJobId))
638
+ .response(asJson_parseErrors[FineTuningJobResponse ])
639
+
544
640
/** Gets info about the fine-tune job.
545
641
*
546
642
* [[https://platform.openai.com/docs/api-reference/embeddings/create ]]
@@ -1036,6 +1132,7 @@ private class OpenAIUris(val baseUri: Uri) {
1036
1132
val Files : Uri = uri " $baseUri/files "
1037
1133
val Models : Uri = uri " $baseUri/models "
1038
1134
val Moderations : Uri = uri " $baseUri/moderations "
1135
+ val FineTuningJobs : Uri = uri " $baseUri/fine_tuning/jobs "
1039
1136
val Transcriptions : Uri = audioBase.addPath(" transcriptions" )
1040
1137
val Translations : Uri = audioBase.addPath(" translations" )
1041
1138
val VariationsImage : Uri = imageBase.addPath(" variations" )
@@ -1045,6 +1142,11 @@ private class OpenAIUris(val baseUri: Uri) {
1045
1142
val ThreadsRuns : Uri = uri " $baseUri/threads/runs "
1046
1143
val VectorStores : Uri = uri " $baseUri/vector_stores "
1047
1144
1145
+ def fineTuningJob (fineTuningJobId : String ): Uri = FineTuningJobs .addPath(fineTuningJobId)
1146
+ def fineTuningJobEvents (fineTuningJobId : String ): Uri = fineTuningJob(fineTuningJobId).addPath(" events" )
1147
+ def fineTuningJobCheckpoints (fineTuningJobId : String ): Uri = fineTuningJob(fineTuningJobId).addPath(" checkpoints" )
1148
+ def cancelFineTuningJob (fineTuningJobId : String ): Uri = fineTuningJob(fineTuningJobId).addPath(" cancel" )
1149
+
1048
1150
def file (fileId : String ): Uri = Files .addPath(fileId)
1049
1151
def fileContent (fileId : String ): Uri = Files .addPath(fileId, " content" )
1050
1152
def model (modelId : String ): Uri = Models .addPath(modelId)
0 commit comments