openai-rs-api 1.1.3

A Rust wrapper for the OpenAI API
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
#![allow(dead_code)]


#[cfg(feature = "list_models")]
pub mod list_models {
    use serde::Deserialize;

    #[derive(Debug, Deserialize)]
    pub struct ModelPermission {
        /// The ID of the permission.
        pub id: String,
        /// The type of object returned by the API. In this case, it will always be "model_permission".
        pub object: String,
        /// The Unix timestamp (in seconds) when the permission was created.
        pub created: i64,
        /// Whether the permission allows creating engines.
        pub allow_create_engine: bool,
        /// Whether the permission allows sampling.
        pub allow_sampling: bool,
        /// Whether the permission allows log probabilities.
        pub allow_logprobs: bool,
        /// Whether the permission allows search indices.
        pub allow_search_indices: bool,
        /// Whether the permission allows viewing.
        pub allow_view: bool,
        /// Whether the permission allows fine-tuning.
        pub allow_fine_tuning: bool,
        /// The ID of the organization that the permission belongs to.
        pub organization: String,
        /// The ID of the group that the permission belongs to.
        pub group: Option<String>,
        /// Whether the permission is blocking.
        pub is_blocking: bool,
    }

    #[derive(Debug, Deserialize)]
    pub struct Model {
        /// The ID of the model.
        pub id: String,
        /// The type of object returned by the API. In this case, it will always be "model".
        pub object: String,
        /// The Unix timestamp (in seconds) when the model was created.
        pub created: i64,
        /// The ID of the organization that owns the model.
        pub owned_by: String,
        /// A list of `ModelPermission` objects representing the permissions for the model.
        pub permission: Vec<ModelPermission>,
        /// The ID of the root model that this model was created from.
        pub root: String,
        /// The ID of the parent model that this model was created from.
        pub parent: Option<String>,
    }

    #[derive(Debug, Deserialize)]
    pub struct ModelList {
        /// The type of object returned by the API. In this case, it will always be "list".
        pub object: String,
        /// A vector of `Model` objects representing the models returned by the API.
        pub data: Vec<Model>,
    }
}

#[cfg(feature = "edits")]
pub mod edits {
    use serde::{Deserialize, Serialize};

    #[derive(Debug, Deserialize, Serialize)]
    pub struct EditParameters {
        /// ID of the model to use. You can use the `text-davinci-edit-001` or `code-davinci-edit-001` model with this endpoint.
        model: String,
        /// The input text to use as a starting point for the edit.
        input: String,
        /// The instruction that tells the model how to edit the prompt.
        instructions: String,
        /// How many edits to generate for the input and instruction.
        #[serde(skip_serializing_if = "Option::is_none")]
        n_of_edits: Option<i32>,
        /// What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.
        ///
        /// We generally recommend altering this or `top_p` but not both.
        #[serde(skip_serializing_if = "Option::is_none")]
        temperature: Option<f32>,
        /// An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.
        ///
        /// We generally recommend altering this or `temperature` but not both.
        #[serde(skip_serializing_if = "Option::is_none")]
        top_p: Option<f32>,
    }

    impl EditParameters {
        // builder pattern
        pub fn new(model: String, input: String, instructions: String) -> Self {
            Self {
                model,
                input,
                instructions,
                n_of_edits: None,
                temperature: None,
                top_p: None,
            }
        }

        pub fn n_of_edits(mut self, n_of_edits: i32) -> Self {
            self.n_of_edits = Some(n_of_edits);
            self
        }

        pub fn temperature(mut self, temperature: f32) -> Self {
            self.temperature = Some(temperature);
            self
        }

        pub fn top_p(mut self, top_p: f32) -> Self {
            self.top_p = Some(top_p);
            self
        }

        pub fn build(self) -> EditParameters {
            EditParameters {
                model: self.model,
                input: self.input,
                instructions: self.instructions,
                n_of_edits: self.n_of_edits,
                temperature: self.temperature,
                top_p: self.top_p,
            }
        }
    }

    #[derive(Debug, Deserialize)]
    pub struct EditResponse {
        /// The type of object returned by the API. In this case, it will always be "text_completion".
        object: String,
        /// The Unix timestamp (in seconds) when the completion was generated.
        created: i64,
        /// A list of `Choice` objects representing the generated completions.
        choices: Vec<Choice>,
        /// An object containing information about the number of tokens used in the prompt and generated completion.
        usage: Usage,
    }

    #[derive(Debug, Deserialize)]
    pub struct Choice {
        /// The generated text for this choice.
        text: String,
        /// The index of this choice in the list of choices returned by the API.
        index: i32,
    }

    #[derive(Debug, Deserialize)]
    pub struct Usage {
        /// The number of tokens in the prompt.
        prompt_tokens: i32,
        /// The number of tokens in the generated completion.
        completion_tokens: i32,
        /// The total number of tokens used (prompt + completion).
        total_tokens: i32,
    }
}

#[cfg(feature = "completions")]
pub mod completions {

    use serde::{Deserialize, Serialize};

    #[derive(Debug, Deserialize, Serialize)]
    pub struct CompletionParameters {
        /// ID of the model to use. You can use the List models API to see all of your available models,
        /// or see our [Model overview](https://platform.openai.com/docs/models/overview) for descriptions of them.
        ///
        /// List models example:
        /// ```rust
        /// use openai_rs_api::core::{OpenAI, models::list_models::ModelList};
        /// use tokio;
        ///
        /// #[tokio::main]
        /// async fn main() -> Result<(), Box<dyn std::error::Error>> {
        ///     let openai = OpenAI::new("your_api_key", "your_organization_id");
        ///     let models: ModelList = openai.list_models().await?;
        ///     println!("{:#?}", models);
        /// }
        /// ```
        ///
        pub model: String,
        /// The prompt(s) to generate completions for, encoded as a string, array of strings,
        /// array of tokens, or array of token arrays.
        ///
        /// Note that <|endoftext|> is the document separator that the model sees during training,
        /// so if a prompt is not specified the model will generate as if from the beginning of a new document.
        pub prompt: String,
        /// The maximum number of [tokens](https://platform.openai.com/tokenizer) to generate in the completion.
        ///
        /// The token count of your prompt plus `max_tokens` cannot exceed the model's context length.
        /// [Example Python code](https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb)
        /// for counting tokens.
        #[serde(skip_serializing_if = "Option::is_none")]
        pub max_tokens: Option<i32>,
        /// What sampling temperature to use, between 0 and 2.
        /// Higher values like 0.8 will make the output more random, while lower values
        /// like 0.2 will make it more focused and deterministic.
        ///
        /// We generally recommend altering this or `top_p` but not both.
        #[serde(skip_serializing_if = "Option::is_none")]
        pub temperature: Option<f32>,
        /// The suffix that comes after a completion of inserted text.
        #[serde(skip_serializing_if = "Option::is_none")]
        pub suffix: Option<String>,
        /// An alternative to sampling with temperature, called nucleus sampling,
        /// where the model considers the results of the tokens with top_p probability mass.
        /// So 0.1 means only the tokens comprising the top 10% probability mass are considered.
        ///
        /// We generally recommend altering this or `temperature` but not both.
        #[serde(skip_serializing_if = "Option::is_none")]
        pub top_p: Option<f32>,
        /// How many completions to generate for each prompt.
        ///
        /// Note: Because this parameter generates many completions, it can quickly consume your token quota.
        /// Use carefully and ensure that you have reasonable settings for `max_tokens` and `stop`.
        #[serde(skip_serializing_if = "Option::is_none")]
        pub n: Option<i32>,
        /// Whether to stream back partial progress. If set, tokens
        /// will be sent as data-only server-sent events as they become available,
        /// with the stream terminated by a `data: [DONE]` message.
        /// [Example Python code.](https://github.com/openai/openai-cookbook/blob/main/examples/How_to_stream_completions.ipynb)
        #[serde(skip_serializing_if = "Option::is_none")]
        pub stream: Option<bool>,
        /// Include the log probabilities on the `logprobs` most likely tokens, as well the chosen tokens.
        /// For example, if `logprobs` is 5, the API will return a list of the 5 most likely tokens.
        /// The API will always return the `logprob` of the sampled token, so there may be up to `logprobs+1` elements in the response.
        ///
        /// The maximum value for logprobs is 5.
        #[serde(skip_serializing_if = "Option::is_none")]
        pub logprobs: Option<i32>,
        /// Up to 4 sequences where the API will stop generating further tokens.
        /// The returned text will not contain the stop sequence.
        #[serde(skip_serializing_if = "Option::is_none")]
        pub stop: Option<String>,
        /// Number between -2.0 and 2.0. Positive values penalize new tokens based on whether
        /// they appear in the text so far, increasing the model's likelihood to talk about new topics.
        ///
        /// [See more information about frequency and presence penalties.](https://platform.openai.com/docs/api-reference/parameter-details)
        #[serde(skip_serializing_if = "Option::is_none")]
        pub presence_penalty: Option<f32>,
        /// Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency
        /// in the text so far, decreasing the model's likelihood to repeat the same line verbatim.
        ///
        /// [See more information about frequency and presence penalties.](https://platform.openai.com/docs/api-reference/parameter-details)
        #[serde(skip_serializing_if = "Option::is_none")]
        pub frequency_penalty: Option<f32>,
        /// Generates `best_of` completions server-side and returns the "best" (the one with the highest log probability per token). Results cannot be streamed.
        ///
        /// When used with `n`, `best_of` controls the number of candidate completions and `n` specifies how many to return – `best_of` must be greater than `n`.
        ///
        /// Note: Because this parameter generates many completions, it can quickly consume your token quota.
        /// Use carefully and ensure that you have reasonable settings for `max_tokens` and `stop`.
        #[serde(skip_serializing_if = "Option::is_none")]
        pub best_of: Option<i32>,
        /// Modify the likelihood of specified tokens appearing in the completion.
        ///
        /// Accepts a json object that maps tokens (specified by their token ID in the GPT tokenizer)
        /// to an associated bias value from -100 to 100. You can use this [tokenizer tool](https://platform.openai.com/tokenizer?view=bpe)
        /// (which works for both GPT-2 and GPT-3) to convert text to token IDs.
        /// Mathematically, the bias is added to the logits generated by the model prior to sampling.
        /// The exact effect will vary per model, but values between -1 and 1 should decrease or
        /// increase likelihood of selection; values like -100 or 100 should result in a ban or
        /// exclusive selection of the relevant token.
        ///
        /// As an example, you can pass `{"50256": -100}` to prevent the <|endoftext|> token from being generated.
        #[serde(skip_serializing_if = "Option::is_none")]
        pub logit_bias: Option<serde_json::Value>,
        /// A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](https://platform.openai.com/docs/guides/safety-best-practices/end-user-ids).
        #[serde(skip_serializing_if = "Option::is_none")]
        pub user: Option<String>,
        /// Echo back the prompt in addition to the completion
        #[serde(skip_serializing_if = "Option::is_none")]
        pub echo: Option<bool>,
    }

    #[derive(Debug, Serialize, Deserialize)]
    pub struct CompletionResponse {
        /// The unique identifier for the completion request.
        pub id: String,
        /// The type of object, which is always "text_completion".
        pub object: String,
        /// The Unix timestamp (in seconds) when the completion request was created.
        pub created: i64,
        /// The ID of the model used to generate the completion.
        pub model: String,
        /// A vector of `CompletionChoice` objects, each representing a possible completion.
        pub choices: Vec<CompletionChoice>,
        /// An object containing usage statistics for the completion request.
        pub usage: Usage,
    }

    #[derive(Debug, Serialize, Deserialize)]
    pub struct CompletionChoice {
        /// The generated text for this completion choice.
        pub text: String,
        /// The index of this completion choice in the list of all possible choices.
        pub index: i32,
        /// The log probabilities of the tokens in the generated text.
        /// If the `logprobs` parameter was not set in the request, this field will be `None`.
        pub logprobs: Option<i32>,
        /// The reason why the completion was finished.
        /// Possible values are "stop", "length", "temperature", "top_p", "nucleus_sampling", and "incomplete".
        pub finish_reason: String,
    }

    #[derive(Debug, Serialize, Deserialize)]
    pub struct Usage {
        /// prompt_tokens: an integer representing the number of tokens in the prompt used for the completion request.
        pub prompt_tokens: i32,
        /// completion_tokens: an integer representing the number of tokens in the generated completion text.
        pub completion_tokens: i32,
        /// total_tokens: an integer representing the total number of tokens used in the completion request, including both the prompt and the generated completion text.
        pub total_tokens: i32,
    }
}

#[cfg(feature = "chat")]
pub mod chat {
    use serde::{Deserialize, Serialize};

    #[derive(Debug, Serialize, Deserialize)]
    pub struct ChatParameters {
        /// ID of the model to use. See the
        /// [model endpoint compatibility](https://platform.openai.com/docs/models/model-endpoint-compatibility) table
        /// for details on which models work with the Chat API.
        pub model: String,
        /// A list of messages comprising the conversation so far.
        pub messages: Vec<Message>,
        /// A list of functions the model may generate JSON inputs for.
        #[serde(skip_serializing_if = "Option::is_none")]
        pub functions: Option<Vec<Function>>,
        /// Controls how the model responds to function calls. "none" means the model does not call a function,
        /// and responds to the end-user. "auto" means the model can pick between an end-user or calling a
        /// function. Specifying a particular function via `{"name":\ "my_function"}` forces the model to call
        /// that function. "none" is the default when no functions are present. "auto" is the default if functions
        /// are present.
        #[serde(skip_serializing_if = "Option::is_none")]
        pub function_call: Option<serde_json::Value>,
        /// What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output
        /// more random, while lower values like 0.2 will make it more focused and deterministic.
        ///
        /// We generally recommend altering this or `top_p` but not both.
        #[serde(skip_serializing_if = "Option::is_none")]
        pub temperature: Option<f32>,
        /// An alternative to sampling with temperature, called nucleus sampling, where the
        /// model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.
        ///
        /// We generally recommend altering this or `temperature` but not both.
        #[serde(skip_serializing_if = "Option::is_none")]
        pub top_p: Option<f32>,
        /// How many chat completion choices to generate for each input message.
        #[serde(skip_serializing_if = "Option::is_none")]
        pub n: Option<i32>,
        /// If set, partial message deltas will be sent, like in ChatGPT.
        /// Tokens will be sent as data-only server-sent events as they become available,
        /// with the stream terminated by a `data: [DONE]` message. Example Python code.
        #[serde(skip_serializing_if = "Option::is_none")]
        pub stream: Option<bool>,
        /// Up to 4 sequences where the API will stop generating further tokens.
        #[serde(skip_serializing_if = "Option::is_none")]
        pub stop: Option<Vec<String>>,
        /// The maximum number of tokens to generate in the chat completion.
        #[serde(skip_serializing_if = "Option::is_none")]
        pub max_tokens: Option<i32>,
        /// Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the
        /// text so far, increasing the model's likelihood to talk about new topics.
        ///
        /// [See more information about frequency and presence penalties.](https://platform.openai.com/docs/api-reference/parameter-details)
        #[serde(skip_serializing_if = "Option::is_none")]
        pub presence_penalty: Option<f32>,
        /// Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in
        /// the text so far, decreasing the model's likelihood to repeat the same line verbatim.
        ///
        /// [See more information about frequency and presence penalties.](https://platform.openai.com/docs/api-reference/parameter-details)
        #[serde(skip_serializing_if = "Option::is_none")]
        pub frequency_penalty: Option<f32>,
        /// Modify the likelihood of specified tokens appearing in the completion.
        ///
        /// Accepts a json object that maps tokens (specified by their token ID in the tokenizer) to an associated bias value from -100 to 100.
        /// Mathematically, the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model,
        /// but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should result in a ban or
        /// exclusive selection of the relevant token.
        #[serde(skip_serializing_if = "Option::is_none")]
        pub logit_bias: Option<serde_json::Value>,
        ///A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. [Learn more](https://platform.openai.com/docs/guides/safety-best-practices/end-user-ids).
        #[serde(skip_serializing_if = "Option::is_none")]
        pub user: Option<String>,
    }

    impl ChatParameters {
        // realize the builder pattern
        pub fn new(model: String, messages: Vec<Message>) -> Self {
            Self {
                model,
                messages,
                functions: None,
                function_call: None,
                temperature: None,
                top_p: None,
                n: None,
                stream: None,
                stop: None,
                max_tokens: None,
                presence_penalty: None,
                frequency_penalty: None,
                logit_bias: None,
                user: None,
            }
        }

        pub fn functions(mut self, functions: Vec<Function>) -> Self {
            self.functions = Some(functions);
            self
        }

        pub fn function_call(mut self, function_call: serde_json::Value) -> Self {
            self.function_call = Some(function_call);
            self
        }

        pub fn temperature(mut self, temperature: f32) -> Self {
            self.temperature = Some(temperature);
            self
        }

        pub fn top_p(mut self, top_p: f32) -> Self {
            self.top_p = Some(top_p);
            self
        }

        pub fn n(mut self, n: i32) -> Self {
            self.n = Some(n);
            self
        }

        pub fn stream(mut self, stream: bool) -> Self {
            self.stream = Some(stream);
            self
        }

        pub fn stop(mut self, stop: Vec<String>) -> Self {
            self.stop = Some(stop);
            self
        }

        pub fn max_tokens(mut self, max_tokens: i32) -> Self {
            self.max_tokens = Some(max_tokens);
            self
        }

        pub fn presence_penalty(mut self, presence_penalty: f32) -> Self {
            self.presence_penalty = Some(presence_penalty);
            self
        }

        pub fn frequency_penalty(mut self, frequency_penalty: f32) -> Self {
            self.frequency_penalty = Some(frequency_penalty);
            self
        }

        pub fn logit_bias(mut self, logit_bias: serde_json::Value) -> Self {
            self.logit_bias = Some(logit_bias);
            self
        }

        pub fn user(mut self, user: String) -> Self {
            self.user = Some(user);
            self
        }

        pub fn build(self) -> ChatParameters {
            ChatParameters {
                model: self.model,
                messages: self.messages,
                functions: self.functions,
                function_call: self.function_call,
                temperature: self.temperature,
                top_p: self.top_p,
                n: self.n,
                stream: self.stream,
                stop: self.stop,
                max_tokens: self.max_tokens,
                presence_penalty: self.presence_penalty,
                frequency_penalty: self.frequency_penalty,
                logit_bias: self.logit_bias,
                user: self.user,
            }
        }
    }

    #[derive(Debug, Serialize, Deserialize)]
    pub struct Function {
        /// The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes,
        /// with a maximum length of 64.
        pub name: String,
        /// The description of what the function does.
        #[serde(skip_serializing_if = "Option::is_none")]
        pub description: Option<String>,
        /// The parameters the functions accepts, described as a JSON Schema object.
        /// See the [guide](https://platform.openai.com/docs/guides/gpt/function-calling) for examples,
        /// and the [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for
        /// documentation about the format.
        #[serde(skip_serializing_if = "Option::is_none")]
        #[serde(rename = "parameters")]
        pub params: Option<serde_json::Value>,
    }

    #[derive(Debug, Serialize, Deserialize, Clone)]
    pub struct ChatResponse {
        /// The unique identifier for this chat response.
        pub id: String,
        /// The type of object, which is always "text_completion".
        pub object: String,
        /// The Unix timestamp (in seconds) when this chat response was created.
        pub created: i64,
        /// A vector of `CompletionChoice` structs, representing the different choices for the chat response.
        pub choices: Vec<CompletionChoice>,
        /// An object containing usage information for this API request.
        pub usage: Usage,
    }

    #[derive(Debug, Serialize, Deserialize, Clone)]
    pub struct CompletionChoice {
        /// The index of this choice in the list of choices returned by the API.
        pub index: i32,
        /// The message generated by the API for this choice.
        pub message: Message,
        /// The reason why the API stopped generating further tokens for this choice.
        pub finish_reason: String,
    }

    #[derive(Debug, Serialize, Deserialize, Clone)]
    pub struct Message {
        /// The role of the messages author. One of `system`, `user`, `assistant` or `function`.
        pub role: String,
        /// The contents of the message. `content` is required for
        /// all messages except assistant messages with function calls.
        #[serde(skip_serializing_if = "Option::is_none")]
        pub content: Option<String>,
        /// The name of the author of this message. `name` is required if role is `function`,
        /// and it should be the name of the function whose response is in the `content`.
        /// May contain a-z, A-Z, 0-9, and underscores, with a maximum length of 64 characters.
        #[serde(skip_serializing_if = "Option::is_none")]
        pub name: Option<String>,
        /// The name and arguments of a function that should be called, as generated by the model.
        ///
        ///**Now this optional field dont support in this crate.**
        #[serde(skip_serializing_if = "Option::is_none")]
        pub function_call: Option<serde_json::Value>,
    }

    #[derive(Debug, Serialize, Deserialize, Clone)]
    pub struct Usage {
        pub prompt_tokens: i32,
        pub completion_tokens: i32,
        pub total_tokens: i32,
    }
}

#[cfg(feature = "images")]
pub mod images {
    use serde::{Deserialize, Serialize};

    #[derive(Debug, Serialize, Deserialize)]
    pub struct ImageCreateParameters {
        pub prompt: String,
        /// The number of images to generate. Must be between 1 and 10.
        #[serde(skip_serializing_if = "Option::is_none")]
        #[serde(rename = "n")]
        pub num_images: Option<i32>,
        /// The size of the generated images. Must be one of `256x256`, `512x512`, or `1024x1024.
        #[serde(skip_serializing_if = "Option::is_none")]
        #[serde(rename = "size")]
        pub image_size: Option<String>,
        /// The format in which the generated images are returned. Must be one of `url` or `b64_json`.
        #[serde(skip_serializing_if = "Option::is_none")]
        pub response_format: Option<String>, // url of b64_json
        /// A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.
        /// [Learn more](https://platform.openai.com/docs/guides/safety-best-practices/end-user-ids).
        #[serde(skip_serializing_if = "Option::is_none")]
        pub user: Option<String>,
    }

    impl ImageCreateParameters {
        pub fn new(prompt: String) -> Self {
            Self {
                prompt,
                num_images: None,
                image_size: None,
                response_format: None,
                user: None,
            }
        }

        pub fn num_images(mut self, num_images: i32) -> Self {
            self.num_images = Some(num_images);
            self
        }

        pub fn image_size(mut self, image_size: String) -> Self {
            self.image_size = Some(image_size);
            self
        }

        pub fn response_format(mut self, response_format: String) -> Self {
            self.response_format = Some(response_format);
            self
        }

        pub fn user(mut self, user: String) -> Self {
            self.user = Some(user);
            self
        }

        pub fn build(self) -> ImageCreateParameters {
            self
        }
    }

    #[derive(Debug, Serialize, Deserialize)]
    pub struct ImageEditParameters {
        /// The image to edit. Must be a valid PNG file, less than 4MB, and square.
        /// If mask is not provided, image must have transparency, which will be used as the mask.
        pub image: String,
        /// An additional image whose fully transparent areas (e.g. where alpha is zero) indicate where `image` should be edited.
        /// Must be a valid PNG file, less than 4MB, and have the same dimensions as `image`.
        #[serde(skip_serializing_if = "Option::is_none")]
        pub mask: Option<String>,
        /// A text description of the desired image(s). The maximum length is 1000 characters.
        pub prompt: String,
        /// The number of images to generate. Must be between 1 and 10.
        #[serde(skip_serializing_if = "Option::is_none")]
        #[serde(rename = "n")]
        pub num_images: Option<i32>,
        /// The size of the generated images. Must be one of `256x256`, `512x512`, or `1024x1024.
        #[serde(skip_serializing_if = "Option::is_none")]
        #[serde(rename = "size")]
        pub image_size: Option<String>,
        /// The format in which the generated images are returned. Must be one of `url` or `b64_json`.
        #[serde(skip_serializing_if = "Option::is_none")]
        pub response_format: Option<String>, // url of b64_json
        /// A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.
        /// [Learn more](https://platform.openai.com/docs/guides/safety-best-practices/end-user-ids).
        #[serde(skip_serializing_if = "Option::is_none")]
        pub user: Option<String>,
    }

    impl ImageEditParameters {
        // builder pattern
        pub fn new(image: String, prompt: String) -> Self {
            Self {
                image,
                mask: None,
                prompt,
                num_images: None,
                image_size: None,
                response_format: None,
                user: None,
            }
        }

        pub fn mask(mut self, mask: String) -> Self {
            self.mask = Some(mask);
            self
        }

        pub fn num_images(mut self, num_images: i32) -> Self {
            self.num_images = Some(num_images);
            self
        }

        pub fn image_size(mut self, image_size: String) -> Self {
            self.image_size = Some(image_size);
            self
        }

        pub fn response_format(mut self, response_format: String) -> Self {
            self.response_format = Some(response_format);
            self
        }

        pub fn user(mut self, user: String) -> Self {
            self.user = Some(user);
            self
        }

        pub fn build(self) -> ImageEditParameters {
            self
        }
    }

    #[derive(Debug, Serialize, Deserialize)]
    pub struct ImageVariationParameters {
        /// The image to edit. Must be a valid PNG file, less than 4MB, and square.
        /// If mask is not provided, image must have transparency, which will be used as the mask.
        pub image: String,
        /// The number of images to generate. Must be between 1 and 10.
        #[serde(skip_serializing_if = "Option::is_none")]
        #[serde(rename = "n")]
        pub num_images: Option<i32>,
        /// The size of the generated images. Must be one of `256x256`, `512x512`, or `1024x1024.
        #[serde(skip_serializing_if = "Option::is_none")]
        #[serde(rename = "size")]
        pub image_size: Option<String>,
        /// The format in which the generated images are returned. Must be one of `url` or `b64_json`.
        #[serde(skip_serializing_if = "Option::is_none")]
        pub response_format: Option<String>, // url of b64_json
        /// A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.
        /// [Learn more](https://platform.openai.com/docs/guides/safety-best-practices/end-user-ids).
        #[serde(skip_serializing_if = "Option::is_none")]
        pub user: Option<String>,
    }

    #[derive(Debug, Serialize, Deserialize)]
    pub struct ImageResponse {
        /// The timestamp (in seconds since the Unix epoch) when the request was made.
        pub created: usize,
        /// A vector of ImageData structs containing the URLs of the generated images.
        pub data: Vec<ImageData>,
    }

    #[derive(Debug, Serialize, Deserialize)]
    pub struct ImageData {
        /// The URL of the generated image.
        pub url: String,
    }
}

#[cfg(feature = "embeddings")]
pub mod embeddings {
    use serde::{Deserialize, Serialize};

    #[derive(Debug, Serialize, Deserialize)]
    pub struct EmbeddingParameters {
        /// ID of the model to use. You can use the List models API to see all of your available models,
        /// or see our Model overview for descriptions of them.
        pub model: String,
        ///nput text to embed, encoded as a string or array of tokens. To embed multiple
        /// inputs in a single request, pass an array of strings or array of token arrays.
        /// Each input must not exceed the max input tokens for the model (8191 tokens for text-embedding-ada-002).
        pub input: String,
        /// A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.
        /// [Learn more](https://platform.openai.com/docs/guides/safety-best-practices/end-user-ids).
        #[serde(skip_serializing_if = "Option::is_none")]
        pub user: Option<String>,
    }

    impl EmbeddingParameters {
        // builder pattern
        pub fn new(model: String, input: String) -> Self {
            Self {
                model,
                input,
                user: None,
            }
        }

        pub fn user(mut self, user: String) -> Self {
            self.user = Some(user);
            self
        }

        pub fn build(self) -> EmbeddingParameters {
            self
        }
    }

    #[derive(Debug, Serialize, Deserialize)]
    pub struct EmbeddingResponse {
        /// A string representing the type of object returned. In this case, it should always be "embedding".
        pub object: String,
        /// A vector of `EmbeddingData` representing the embedding of the input text.
        pub data: Vec<EmbeddingData>,
        /// ID of the model used for the embedding.
        pub model: String,
        /// An object containing information about the API usage for the request.
        pub usage: Usage,
    }

    #[derive(Debug, Serialize, Deserialize)]
    pub struct EmbeddingData {
        /// object: A string representing the type of object returned. In this case, it should always be "embedding".
        pub object: String,
        /// embedding: A vector of 32-bit floating point numbers representing the embedding of the input text. The length of the vector depends on the model used for the embedding.
        pub embedding: Vec<f32>,
        /// index: An integer representing the index of the input text in the request. This is useful when multiple inputs are passed in a single request.
        pub index: i32,
    }

    #[derive(Debug, Serialize, Deserialize)]
    pub struct Usage {
        /// prompt_tokens: An integer representing the number of tokens used in the prompt for the API request.
        pub prompt_tokens: i32,
        /// total_tokens: An integer representing the total number of tokens used in the API request, including the prompt tokens.
        pub total_tokens: i32,
    }
}

#[cfg(feature = "audio")]
pub mod audio {
    use serde::{Deserialize, Serialize};

    #[derive(Debug, Serialize)]
    pub struct TranscriptionParameters {
        /// The audio file object (not file name) to transcribe, in one of these formats: mp3, mp4, mpeg, mpga, m4a, wav, or webm.
        pub file: String,
        /// ID of the model to use. Only `whisper-1` is currently available.
        pub model: String,
        /// An optional text to guide the model's style or continue a previous audio segment. The prompt should match the audio language.
        #[serde(skip_serializing_if = "Option::is_none")]
        pub prompt: Option<String>,
        /// The format of the transcript output, in one of these options: json, text, srt, verbose_json, or vtt.
        #[serde(skip_serializing_if = "Option::is_none")]
        pub respone_format: Option<String>,
        /// The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2
        /// will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature
        /// until certain thresholds are hit.
        #[serde(skip_serializing_if = "Option::is_none")]
        pub temperature: Option<f32>,
        /// The language of the input audio. Supplying the input language in [ISO-639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) format will improve accuracy and latency.
        #[serde(skip_serializing_if = "Option::is_none")]
        pub language: Option<String>,
    }

    impl TranscriptionParameters {
        pub fn new(file: String, model: String) -> Self {
            Self {
                file,
                model,
                prompt: None,
                respone_format: None,
                temperature: None,
                language: None,
            }
        }

        pub fn prompt(mut self, prompt: String) -> Self {
            self.prompt = Some(prompt);
            self
        }

        pub fn respone_format(mut self, respone_format: String) -> Self {
            self.respone_format = Some(respone_format);
            self
        }

        pub fn temperature(mut self, temperature: f32) -> Self {
            self.temperature = Some(temperature);
            self
        }

        pub fn language(mut self, language: String) -> Self {
            self.language = Some(language);
            self
        }

        pub fn build(self) -> TranscriptionParameters {
            self
        }
    }

    #[derive(Debug, Serialize)]
    pub struct TranslationParameters {
        /// The audio file object (not file name) to transcribe, in one of these formats: mp3, mp4, mpeg, mpga, m4a, wav, or webm.
        pub file: String,
        /// ID of the model to use. Only `whisper-1` is currently available.
        pub model: String,
        /// An optional text to guide the model's style or continue a previous audio segment. The prompt should match the audio language.
        #[serde(skip_serializing_if = "Option::is_none")]
        pub prompt: Option<String>,
        /// The format of the transcript output, in one of these options: json, text, srt, verbose_json, or vtt.
        /// The default is json.
        #[serde(skip_serializing_if = "Option::is_none")]
        pub respone_format: Option<String>,
        /// The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, while lower values like 0.2
        /// will make it more focused and deterministic. If set to 0, the model will use log probability to automatically increase the temperature
        /// until certain thresholds are hit.
        /// The default is 1.
        #[serde(skip_serializing_if = "Option::is_none")]
        pub temperature: Option<f32>,
    }

    impl TranslationParameters {
        pub fn new(file: String, model: String) -> Self {
            Self {
                file,
                model,
                prompt: None,
                respone_format: None,
                temperature: None,
            }
        }

        pub fn prompt(mut self, prompt: String) -> Self {
            self.prompt = Some(prompt);
            self
        }

        pub fn respone_format(mut self, respone_format: String) -> Self {
            self.respone_format = Some(respone_format);
            self
        }

        pub fn temperature(mut self, temperature: f32) -> Self {
            self.temperature = Some(temperature);
            self
        }

        pub fn build(self) -> TranslationParameters {
            self
        }
    }

    #[derive(Debug, Deserialize)]
    pub struct TextResponse {
        /// The generated text from the OpenAI API.
        pub text: String,
    }
}

#[cfg(feature = "files")]
pub mod files {
    use serde::{Deserialize, Serialize};

    #[derive(Debug, Serialize, Deserialize)]
    pub struct FileList {
        /// A vector of `FileData` objects representing the files returned by the API.
        pub data: Vec<FileData>,
        /// A string representing the object type returned by the API. This should always be "list".
        pub object: String,
    }

    #[derive(Debug, Serialize, Deserialize)]
    pub struct FileData {
        /// The unique identifier for the file.
        pub id: String,
        /// The type of object, which should always be "file".
        pub object: String,
        /// The size of the file in bytes.
        pub bytes: u32,
        /// The Unix timestamp (in seconds) when the file was created.
        pub created_at: u64,
        /// The name of the file.
        pub filename: String,
        /// The intended purpose of the file.
        pub purpose: String,
    }

    #[derive(Debug, Serialize, Deserialize)]
    pub struct FileUpload {
        /// Name of the [JSON Lines](https://jsonlines.readthedocs.io/en/latest/) file to be uploaded.
        ///
        /// If the purpose is set to "fine-tune", each line is a JSON record with "prompt" and "completion"
        /// fields representing your [training examples.](https://platform.openai.com/docs/guides/fine-tuning/prepare-training-data)
        pub file: String,
        /// The intended purpose of the uploaded documents.
        ///
        /// Use "fine-tune" for Fine-tuning. This allows us to validate the format of the uploaded file.
        pub purpose: String,
    }

    #[derive(Debug, Serialize, Deserialize)]
    pub struct DeleteResponse {
        /// The unique identifier for the deleted object.
        pub id: String,
        /// The type of object that was deleted.
        pub object: String,
        /// A boolean indicating whether the object was successfully deleted.
        pub deleted: bool,
    }
}

#[cfg(feature = "fine_tunes")]
pub mod fine_tunes {
    use serde::{Deserialize, Serialize};

    #[derive(Debug, Serialize, Deserialize)]
    pub struct CreateFineTuneParameters {
        /// The ID of an uploaded file that contains training data.
        pub training_file: String,
        /// The ID of an uploaded file that contains validation data.
        #[serde(skip_serializing_if = "Option::is_none")]
        pub validation_file: Option<String>,
        /// The name of the base model to use for fine-tuning.
        #[serde(skip_serializing_if = "Option::is_none")]
        pub model: Option<String>,
        /// The number of epochs to train the model for.
        #[serde(skip_serializing_if = "Option::is_none")]
        pub epochs: Option<u32>,
        /// The batch size to use for training.
        #[serde(skip_serializing_if = "Option::is_none")]
        pub batch_size: Option<u32>,
        /// The learning rate multiplier to use for training.
        /// The fine-tuning learning rate is the original learning rate used for pretraining multiplied by this value.
        #[serde(skip_serializing_if = "Option::is_none")]
        pub learning_rate_multiplier: Option<f32>,
        /// The weight to use for loss on the prompt tokens. This controls how much the model tries
        /// to learn to generate the prompt (as compared to the completion which always has a weight of 1.0),
        /// and can add a stabilizing effect to training when completions are short.
        #[serde(skip_serializing_if = "Option::is_none")]
        pub prompt_loss_weight: Option<f32>,
        /// If set, we calculate classification-specific metrics such as accuracy and F-1 score using
        /// the validation set at the end of every epoch. These metrics can be viewed in the results file.
        ///
        /// In order to compute classification metrics, you must provide a `validation_file`.
        /// Additionally, you must specify `classification_n_classes` for multiclass classification or
        /// `classification_positive_class` for binary classification.
        #[serde(skip_serializing_if = "Option::is_none")]
        pub compute_classification_metrics: Option<bool>,
        /// The number of classes in a classification task.
        ///
        /// This parameter is required for multiclass classification.
        #[serde(skip_serializing_if = "Option::is_none")]
        pub classification_n_classes: Option<u32>,
        /// The positive class in binary classification.
        ///
        /// This parameter is needed to generate precision, recall,
        /// and F1 metrics when doing binary classification.
        #[serde(skip_serializing_if = "Option::is_none")]
        pub classification_positive_class: Option<String>,
        /// If this is provided, we calculate F-beta scores at the specified beta values.
        /// The F-beta score is a generalization of F-1 score. This is only used for binary classification.
        ///
        /// With a beta of 1 (i.e. the F-1 score), precision and recall are given the same weight.
        /// A larger beta score puts more weight on recall and less on precision. A smaller beta score puts
        /// more weight on precision and less on recall.
        #[serde(skip_serializing_if = "Option::is_none")]
        pub classification_beta: Option<f32>,
        ///A string of up to 40 characters that will be added to your fine-tuned model name.
        ///
        /// For example, a suffix of "custom-model-name" would produce a model name like ada:ft-your-org:custom-model-name-2022-02-15-04-21-04.
        #[serde(skip_serializing_if = "Option::is_none")]
        pub suffix: Option<String>,
    }

    impl CreateFineTuneParameters {
        pub fn new(training_file: String) -> Self {
            Self {
                training_file,
                validation_file: None,
                model: None,
                epochs: None,
                batch_size: None,
                learning_rate_multiplier: None,
                prompt_loss_weight: None,
                compute_classification_metrics: None,
                classification_n_classes: None,
                classification_positive_class: None,
                classification_beta: None,
                suffix: None,
            }
        }

        pub fn validation_file(mut self, validation_file: String) -> Self {
            self.validation_file = Some(validation_file);
            self
        }

        pub fn model(mut self, model: String) -> Self {
            self.model = Some(model);
            self
        }

        pub fn epochs(mut self, epochs: u32) -> Self {
            self.epochs = Some(epochs);
            self
        }

        pub fn batch_size(mut self, batch_size: u32) -> Self {
            self.batch_size = Some(batch_size);
            self
        }

        pub fn learning_rate_multiplier(mut self, learning_rate_multiplier: f32) -> Self {
            self.learning_rate_multiplier = Some(learning_rate_multiplier);
            self
        }

        pub fn prompt_loss_weight(mut self, prompt_loss_weight: f32) -> Self {
            self.prompt_loss_weight = Some(prompt_loss_weight);
            self
        }

        pub fn compute_classification_metrics(
            mut self,
            compute_classification_metrics: bool,
        ) -> Self {
            self.compute_classification_metrics = Some(compute_classification_metrics);
            self
        }

        pub fn classification_n_classes(mut self, classification_n_classes: u32) -> Self {
            self.classification_n_classes = Some(classification_n_classes);
            self
        }

        pub fn classification_positive_class(
            mut self,
            classification_positive_class: String,
        ) -> Self {
            self.classification_positive_class = Some(classification_positive_class);
            self
        }

        pub fn classification_beta(mut self, classification_beta: f32) -> Self {
            self.classification_beta = Some(classification_beta);
            self
        }

        pub fn suffix(mut self, suffix: String) -> Self {
            self.suffix = Some(suffix);
            self
        }

        pub fn build(self) -> Result<CreateFineTuneParameters, String> {
            if self.validation_file.is_some() && self.compute_classification_metrics.is_none() {
                return Err("You must set compute_classification_metrics to true if you provide a validation_file.".to_string());
            }

            if self.classification_n_classes.is_some()
                && self.classification_positive_class.is_none()
            {
                return Err("You must set classification_positive_class if you provide classification_n_classes.".to_string());
            }

            if self.classification_positive_class.is_some()
                && self.classification_n_classes.is_none()
            {
                return Err("You must set classification_n_classes if you provide classification_positive_class.".to_string());
            }

            if self.classification_beta.is_some() && self.classification_positive_class.is_none() {
                return Err("You must set classification_positive_class if you provide classification_beta.".to_string());
            }

            Ok(self)
        }
    }

    #[derive(Debug, Serialize, Deserialize)]
    pub struct FineTuneList {
        /// The object type, which is always "list".
        pub object: String,
        /// A vector of `FineTuneData` structs representing the fine-tuned models.
        pub data: Vec<FineTuneListData>,
    }

    #[derive(Debug, Serialize, Deserialize)]
    pub struct FineTuneRetriveData {
        /// The ID of the fine-tuned model.
        pub id: String,
        /// The object type, which is always "fine_tune".
        pub object: String,
        /// The name of the base model that was fine-tuned.
        pub model: String,
        /// The Unix timestamp (in seconds) when the fine-tuned model was created.
        pub created_at: i64,
        /// The vector of `FineTuneEvent` structs representing the events that occurred during fine-tuning.
        pub events: Vec<FineTuneEvent>,
        /// The ID of the fine-tuned model that was created.
        pub fine_tuned_model: Option<String>,
        /// The hyperparameters used for fine-tuning the model.
        pub hyperparams: FineTuneHyperparams,
        /// The ID of the organization that created the fine-tuned model.
        pub organization_id: String,
        /// A vector of URLs pointing to the result files generated during fine-tuning.
        pub result_files: Vec<String>,
        /// The status of the fine-tuned model.
        pub status: String,
        /// A vector of `FineTuneFiles` structs representing the validation files used during fine-tuning.
        pub validation_files: Vec<FineTuneFiles>,
        /// A vector of `FineTuneFiles` structs representing the training files used during fine-tuning.
        pub training_files: Vec<FineTuneFiles>,
        /// The Unix timestamp (in seconds) when the fine-tuned model was last updated.
        pub updated_at: i64,
    }

    #[derive(Debug, Serialize, Deserialize)]
    pub struct FineTuneListData {
        /// The ID of the fine-tuned model.
        pub id: String,
        /// The object type, which is always "fine_tune".
        pub object: String,
        /// The name of the base model that was fine-tuned.
        pub model: String,
        /// The Unix timestamp (in seconds) when the fine-tuned model was created.
        pub created_at: i64,
        /// The ID of the fine-tuned model that was created.
        pub fine_tuned_model: Option<String>,
        /// The hyperparameters used for fine-tuning the model.
        pub hyperparams: FineTuneHyperparams,
        /// The ID of the organization that created the fine-tuned model.
        pub organization_id: String,
        /// A vector of URLs pointing to the result files generated during fine-tuning.
        pub result_files: Vec<String>,
        /// The status of the fine-tuned model.
        pub status: String,
        /// A vector of `FineTuneFiles` structs representing the validation files used during fine-tuning.
        pub validation_files: Vec<FineTuneFiles>,
        /// A vector of `FineTuneFiles` structs representing the training files used during fine-tuning.
        pub training_files: Vec<FineTuneFiles>,
        /// The Unix timestamp (in seconds) when the fine-tuned model was last updated.
        pub updated_at: i64,
    }

    #[derive(Debug, Serialize, Deserialize)]
    /// A struct representing the hyperparameters used for fine-tuning a model.
    pub struct FineTuneHyperparams {
        /// The batch size used during fine-tuning.
        pub batch_size: u32,
        /// The number of epochs used during fine-tuning.
        pub epochs: u32,
        /// A multiplier applied to the learning rate during fine-tuning.
        pub learning_rate_multiplier: f32,
        /// The weight given to the prompt loss during fine-tuning.
        pub prompt_loss_weight: f32,
    }

    #[derive(Debug, Serialize, Deserialize)]
    /// A struct representing a file used during fine-tuning a model.
    pub struct FineTuneFiles {
        /// The ID of the file.
        pub id: String,
        /// The object type, which is always "file".
        pub object: String,
        /// The size of the file in bytes.
        pub bytes: u32,
        /// The Unix timestamp (in seconds) when the file was created.
        pub created_at: i64,
        /// The name of the file.
        pub filename: String,
        /// The purpose of the file, which can be "training" or "validation".
        pub purpose: String,
    }

    #[derive(Debug, Serialize, Deserialize)]
    pub struct FineTuneEventList {
        /// The object type, which is always "list".
        pub object: String,
        /// A vector of `FineTuneEvent` structs representing the fine-tuned events.
        pub data: Vec<FineTuneEvent>,
    }

    #[derive(Debug, Serialize, Deserialize)]
    /// A struct representing a fine-tuned event.
    pub struct FineTuneEvent {
        /// The object type, which is always "fine_tune_event".
        pub object: String,
        /// The Unix timestamp (in seconds) when the fine-tuned event was created.
        pub created_at: i64,
        /// The level of the fine-tuned event, which can be "info", "warning", or "error".
        pub level: String,
        /// The message associated with the fine-tuned event.
        pub message: String,
    }

    #[derive(Debug, Serialize, Deserialize)]
    pub struct FineTuneDelete {
        /// The ID of the fine-tuned model that was deleted.
        pub id: String,
        /// The object type, which is always "fine_tune".
        pub object: String,
        /// A boolean indicating whether the fine-tuned model was successfully deleted.
        pub deleted: bool,
    }
}

#[cfg(feature = "moderations")]
pub mod moderations {
    use serde::{Deserialize, Serialize};

    #[derive(Debug, Serialize, Deserialize)]
    pub struct TextModerationParameters {
        /// The ID of the model to use for moderation.
        #[serde(skip_serializing_if = "Option::is_none")]
        pub model: Option<String>,
        /// The text to moderate.
        pub input: String,
    }

    #[derive(Debug, Serialize, Deserialize)]
    pub struct TextModerationResult {
        /// The ID of the moderation result.
        pub id: String,
        /// The name of the model used for moderation.
        pub model: String,
        /// The moderation results.
        pub results: Vec<TextModerationCategory>,
    }

    #[derive(Debug, Serialize, Deserialize)]
    pub struct TextModerationCategory {
        /// Whether the text was flagged for this category.
        pub flagged: bool,
        /// The categories and their corresponding boolean values.
        pub categories: TextModerationCategoryValues,
        /// The scores for each category.
        pub category_scores: TextModerationCategoryScores,
    }

    #[derive(Debug, Serialize, Deserialize)]
    pub struct TextModerationCategoryValues {
        /// Whether the text was flagged for sexual content.
        pub sexual: bool,
        /// Whether the text was flagged for hate speech.
        pub hate: bool,
        /// Whether the text was flagged for harassment.
        pub harassment: bool,
        /// Whether the text was flagged for self-harm.
        pub self_harm: bool,
        /// Whether the text was flagged for sexual content involving minors.
        pub sexual_minors: bool,
        /// Whether the text was flagged for hate speech with threatening language.
        pub hate_threatening: bool,
        /// Whether the text was flagged for graphic violence.
        pub violence_graphic: bool,
        /// Whether the text was flagged for self-harm with intent.
        pub self_harm_intent: bool,
        /// Whether the text was flagged for self-harm instructions.
        pub self_harm_instructions: bool,
        /// Whether the text was flagged for harassment with threatening language.
        pub harassment_threatening: bool,
        /// Whether the text was flagged for violence.
        pub violence: bool,
    }

    #[derive(Debug, Serialize, Deserialize)]
    pub struct TextModerationCategoryScores {
        /// The score for sexual content.
        pub sexual: f64,
        /// The score for hate speech.
        pub hate: f64,
        /// The score for harassment.
        pub harassment: f64,
        /// The score for self-harm.
        pub self_harm: f64,
        /// The score for sexual content involving minors.
        pub sexual_minors: f64,
        /// The score for hate speech with threatening language.
        pub hate_threatening: f64,
        /// The score for graphic violence.
        pub violence_graphic: f64,
        /// The score for self-harm with intent.
        pub self_harm_intent: f64,
        /// The score for self-harm instructions.
        pub self_harm_instructions: f64,
        /// The score for harassment with threatening language.
        pub harassment_threatening: f64,
        /// The score for violence.
        pub violence: f64,
    }
}