-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharbitraries.js
1456 lines (1361 loc) Β· 54.6 KB
/
arbitraries.js
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
// Generated from TypeSpec using `typespec-fast-check`
import fc from "fast-check";
const ImagesN = fc.integer({
min: 1,
max: 10,
});
const User = fc.string();
/** Represents the url or the content of an image generated by the OpenAI API. */
const Image = fc.record(
{
/** The URL of the generated image, if `response_format` is `url` (default). */
url: fc.webUrl(),
/** The base64-encoded JSON of the generated image, if `response_format` is `b64_json`. */
b64_json: fc.base64String(),
},
{ withDeletedKeys: true },
);
const FineTuneEvent = fc.record({
object: fc.string(),
created_at: fc.string(),
level: fc.string(),
message: fc.string(),
});
/** The `File` object represents a document that has been uploaded to OpenAI. */
const OpenAIFile = fc.record(
{
/** The file identifier, which can be referenced in the API endpoints. */
id: fc.string(),
/** The object type, which is always "file". */
object: fc.constant("file"),
/** The size of the file in bytes. */
bytes: fc.maxSafeInteger(),
/** The Unix timestamp (in seconds) for when the file was created. */
createdAt: fc.string(),
/** The name of the file. */
filename: fc.string(),
/** The intended purpose of the file. Currently, only "fine-tune" is supported. */
purpose: fc.string(),
/**
* The current status of the file, which can be either `uploaded`, `processed`, `pending`,
* `error`, `deleting` or `deleted`.
*/
status: fc.constantFrom("uploaded", "processed", "pending", "error", "deleting", "deleted"),
/**
* Additional details about the status of the file. If the file is in the `error` state, this will
* include a message describing the error.
*/
status_details: fc.option(fc.string()),
},
{
requiredKeys: ["id", "object", "bytes", "createdAt", "filename", "purpose", "status"],
},
);
/** The `FineTune` object represents a legacy fine-tune job that has been created through the API. */
const FineTune = fc.record(
{
/** The object identifier, which can be referenced in the API endpoints. */
id: fc.string(),
/** The object type, which is always "fine-tune". */
object: fc.constant("fine-tune"),
/** The Unix timestamp (in seconds) for when the fine-tuning job was created. */
created_at: fc.string(),
/** The Unix timestamp (in seconds) for when the fine-tuning job was last updated. */
updated_at: fc.string(),
/** The base model that is being fine-tuned. */
model: fc.string(),
/** The name of the fine-tuned model that is being created. */
fine_tuned_model: fc.option(fc.string()),
/** The organization that owns the fine-tuning job. */
organization_id: fc.string(),
/**
* The current status of the fine-tuning job, which can be either `created`, `running`,
* `succeeded`, `failed`, or `cancelled`.
*/
status: fc.constantFrom("created", "running", "succeeded", "failed", "cancelled"),
/**
* The hyperparameters used for the fine-tuning job. See the
* [fine-tuning guide](/docs/guides/legacy-fine-tuning/hyperparameters) for more details.
*/
hyperparams: fc.record(
{
/**
* The number of epochs to train the model for. An epoch refers to one full cycle through the
* training dataset.
*/
n_epochs: fc.maxSafeInteger(),
/**
* The batch size to use for training. The batch size is the number of training examples used to
* train a single forward and backward pass.
*/
batch_size: fc.maxSafeInteger(),
/** The weight to use for loss on the prompt tokens. */
prompt_loss_weight: fc.double(),
/** The learning rate multiplier to use for training. */
learning_rate_multiplier: fc.double(),
/** The classification metrics to compute using the validation dataset at the end of every epoch. */
compute_classification_metrics: fc.boolean(),
/** The positive class to use for computing classification metrics. */
classification_positive_class: fc.string(),
/** The number of classes to use for computing classification metrics. */
classification_n_classes: fc.maxSafeInteger(),
},
{
requiredKeys: ["n_epochs", "batch_size", "prompt_loss_weight", "learning_rate_multiplier"],
},
),
/** The list of files used for training. */
training_files: fc.array(OpenAIFile),
/** The list of files used for validation. */
validation_files: fc.array(OpenAIFile),
/** The compiled results files for the fine-tuning job. */
result_files: fc.array(OpenAIFile),
/** The list of events that have been observed in the lifecycle of the FineTune job. */
events: fc.array(FineTuneEvent),
},
{
requiredKeys: ["id", "object", "created_at", "updated_at", "model", "fine_tuned_model", "organization_id", "status", "hyperparams", "training_files", "validation_files", "result_files"],
},
);
const SuffixString = fc.string({
minLength: 1,
maxLength: 40,
});
const FineTuningJobEvent = fc.record({
id: fc.string(),
object: fc.string(),
created_at: fc.string(),
level: fc.constantFrom("info", "warn", "error"),
message: fc.string(),
});
const NEpochs = fc.integer({
min: 1,
max: 50,
});
const FineTuningJob = fc.record({
/** The object identifier, which can be referenced in the API endpoints. */
id: fc.string(),
/** The object type, which is always "fine_tuning.job". */
object: fc.constant("fine_tuning.job"),
/** The Unix timestamp (in seconds) for when the fine-tuning job was created. */
created_at: fc.string(),
/**
* The Unix timestamp (in seconds) for when the fine-tuning job was finished. The value will be
* null if the fine-tuning job is still running.
*/
finished_at: fc.option(fc.string()),
/** The base model that is being fine-tuned. */
model: fc.string(),
/**
* The name of the fine-tuned model that is being created. The value will be null if the
* fine-tuning job is still running.
*/
fine_tuned_model: fc.option(fc.string()),
/** The organization that owns the fine-tuning job. */
organization_id: fc.string(),
/**
* The current status of the fine-tuning job, which can be either `created`, `pending`, `running`,
* `succeeded`, `failed`, or `cancelled`.
*/
status: fc.constantFrom("created", "pending", "running", "succeeded", "failed", "cancelled"),
/**
* The hyperparameters used for the fine-tuning job. See the
* [fine-tuning guide](/docs/guides/fine-tuning) for more details.
*/
hyperparameters: fc.record(
{
/**
* The number of epochs to train the model for. An epoch refers to one full cycle through the
* training dataset.
*
* "Auto" decides the optimal number of epochs based on the size of the dataset. If setting the
* number manually, we support any number between 1 and 50 epochs.
*/
n_epochs: fc.oneof(
NEpochs,
fc.constant("auto"),
),
},
{ withDeletedKeys: true },
),
/**
* The file ID used for training. You can retrieve the training data with the
* [Files API](/docs/api-reference/files/retrieve-contents).
*/
training_file: fc.string(),
/**
* The file ID used for validation. You can retrieve the validation results with the
* [Files API](/docs/api-reference/files/retrieve-contents).
*/
validation_file: fc.option(fc.string()),
/**
* The compiled results file ID(s) for the fine-tuning job. You can retrieve the results with the
* [Files API](/docs/api-reference/files/retrieve-contents).
*/
result_files: fc.array(fc.string()),
/**
* The total number of billable tokens processed by this fine tuning job. The value will be null
* if the fine-tuning job is still running.
*/
trained_tokens: fc.option(fc.maxSafeInteger()),
/**
* For fine-tuning jobs that have `failed`, this will contain more information on the cause of the
* failure.
*/
error: fc.option(fc.record(
{
/** A human-readable error message. */
message: fc.string(),
/** A machine-readable error code. */
code: fc.string(),
/**
* The parameter that was invalid, usually `training_file` or `validation_file`. This field
* will be null if the failure was not parameter-specific.
*/
param: fc.option(fc.string()),
},
{ withDeletedKeys: true },
)),
});
/** Describes an OpenAI model offering that can be used with the API. */
const Model = fc.record({
/** The model identifier, which can be referenced in the API endpoints. */
id: fc.string(),
/** The object type, which is always "model". */
object: fc.constant("model"),
/** The Unix timestamp (in seconds) when the model was created. */
created: fc.string(),
/** The organization that owns the model. */
owned_by: fc.string(),
});
/** Represents an embedding vector returned by embedding endpoint. */
const Embedding = fc.record({
/** The index of the embedding in the list of embeddings. */
index: fc.maxSafeInteger(),
/** The object type, which is always "embedding". */
object: fc.constant("embedding"),
/**
* The embedding vector, which is a list of floats. The length of vector depends on the model as\
* listed in the [embedding guide](/docs/guides/embeddings).
*/
embedding: fc.array(fc.double()),
});
const TokenArray = fc.array(fc.maxSafeInteger(), { minLength: 1 });
const TokenArrayArray = fc.array(TokenArray, { minLength: 1 });
/** Usage statistics for the completion request. */
const CompletionUsage = fc.record({
/** Number of tokens in the prompt. */
prompt_tokens: fc.maxSafeInteger(),
/** Number of tokens in the generated completion */
completion_tokens: fc.maxSafeInteger(),
/** Total number of tokens used in the request (prompt + completion). */
total_tokens: fc.maxSafeInteger(),
});
const EditN = fc.nat({ max: 20 });
const Temperature = fc.float({
min: 0,
max: 2,
});
const TopP = fc.float({
min: 0,
max: 1,
});
const N = fc.integer({
min: 1,
max: 128,
});
const MaxTokens = fc.maxSafeNat();
const StopSequences = fc.array(fc.string(), {
minLength: 1,
maxLength: 4,
});
const Stop = fc.option(fc.oneof(
fc.string(),
StopSequences,
));
const Penalty = fc.float({
min: -2,
max: 2,
});
const Prompt = fc.option(fc.oneof(
fc.string(),
fc.array(fc.string()),
TokenArray,
TokenArrayArray,
));
const ChatCompletionResponseMessage = fc.record(
{
/** The role of the author of this message. */
role: fc.constantFrom("system", "user", "assistant", "function"),
/** The contents of the message. */
content: fc.option(fc.string()),
/** The name and arguments of a function that should be called, as generated by the model. */
function_call: fc.record({
/** The name of the function to call. */
name: fc.string(),
/**
* The arguments to call the function with, as generated by the model in JSON format. Note that
* the model does not always generate valid JSON, and may hallucinate parameters not defined by
* your function schema. Validate the arguments in your code before calling your function.
*/
arguments: fc.string(),
}),
},
{
requiredKeys: ["role", "content"],
},
);
const ChatCompletionFunctionCallOption = fc.record({
/** The name of the function to call. */
name: fc.string(),
});
const ChatCompletionFunctionParameters = fc.dictionary(fc.string(), fc.anything());
const ChatCompletionFunctions = fc.record(
{
/**
* 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.
*/
name: fc.string(),
/**
* A description of what the function does, used by the model to choose when and how to call the
* function.
*/
description: fc.string(),
/**
* The parameters the functions accepts, described as a JSON Schema object. See the
* [guide](/docs/guides/gpt/function-calling) for examples, and the
* [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for documentation
* about the format.\n\nTo describe a function that accepts no parameters, provide the value
* `{\"type\": \"object\", \"properties\": {}}`.
*/
parameters: ChatCompletionFunctionParameters,
},
{
requiredKeys: ["name", "parameters"],
},
);
const ChatCompletionRequestMessage = fc.record(
{
/** The role of the messages author. One of `system`, `user`, `assistant`, or `function`. */
role: fc.constantFrom("system", "user", "assistant", "function"),
/**
* The contents of the message. `content` is required for all messages, and may be null for
* assistant messages with function calls.
*/
content: fc.option(fc.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.
*/
name: fc.string(),
/** The name and arguments of a function that should be called, as generated by the model. */
function_call: fc.record({
/** The name of the function to call. */
name: fc.string(),
/**
* The arguments to call the function with, as generated by the model in JSON format. Note that
* the model does not always generate valid JSON, and may hallucinate parameters not defined by
* your function schema. Validate the arguments in your code before calling your function.
*/
arguments: fc.string(),
}),
},
{
requiredKeys: ["role", "content"],
},
);
const Error = fc.record({
type: fc.string(),
message: fc.string(),
param: fc.option(fc.string()),
code: fc.option(fc.string()),
});
/** The OpenAI REST API. Please see https://platform.openai.com/docs/api-reference for more details. */
export const OpenAI = {
Audio: {},
Chat: {},
FineTuning: {},
Temperature: Temperature,
TopP: TopP,
N: N,
MaxTokens: MaxTokens,
Penalty: Penalty,
User: User,
EditN: EditN,
NEpochs: NEpochs,
SuffixString: SuffixString,
ImagesN: ImagesN,
Stop: Stop,
Prompt: Prompt,
CreateTranscriptionRequest: fc.record(
{
/**
* The audio file object (not file name) to transcribe, in one of these formats: flac, mp3, mp4,
* mpeg, mpga, m4a, ogg, wav, or webm.
*/
file: fc.uint8Array(),
/** ID of the model to use. Only `whisper-1` is currently available. */
model: fc.oneof(
fc.string(),
fc.constant("whisper-1"),
),
/**
* An optional text to guide the model's style or continue a previous audio segment. The
* [prompt](/docs/guides/speech-to-text/prompting) should match the audio language.
*/
prompt: fc.string(),
/**
* The format of the transcript output, in one of these options: json, text, srt, verbose_json, or
* vtt.
*/
response_format: fc.constantFrom("json", "text", "srt", "verbose_json", "vtt"),
/**
* 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](https://en.wikipedia.org/wiki/Log_probability) to
* automatically increase the temperature until certain thresholds are hit.
*/
temperature: fc.oneof(
fc.float({
min: 0,
max: 1,
}),
fc.constant(0),
),
/**
* 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.
*/
language: fc.string(),
},
{
requiredKeys: ["file", "model"],
},
),
CreateTranscriptionResponse: fc.record({
text: fc.string(),
}),
ErrorResponse: fc.record({
error: Error,
}),
Error: Error,
CreateTranslationRequest: fc.record(
{
/**
* The audio file object (not file name) to translate, in one of these formats: flac, mp3, mp4,
* mpeg, mpga, m4a, ogg, wav, or webm.
*/
file: fc.uint8Array(),
/** ID of the model to use. Only `whisper-1` is currently available. */
model: fc.oneof(
fc.string(),
fc.constant("whisper-1"),
),
/**
* An optional text to guide the model's style or continue a previous audio segment. The
* [prompt](/docs/guides/speech-to-text/prompting) should match the audio language.
*/
prompt: fc.string(),
/**
* The format of the transcript output, in one of these options: json, text, srt, verbose_json, or
* vtt.
*/
response_format: fc.constantFrom("json", "text", "srt", "verbose_json", "vtt"),
/**
* 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](https://en.wikipedia.org/wiki/Log_probability) to
* automatically increase the temperature until certain thresholds are hit.
*/
temperature: fc.oneof(
fc.float({
min: 0,
max: 1,
}),
fc.constant(0),
),
},
{
requiredKeys: ["file", "model"],
},
),
CreateTranslationResponse: fc.record({
text: fc.string(),
}),
CreateChatCompletionRequest: fc.record(
{
/**
* 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.
*/
temperature: fc.option(fc.oneof(
Temperature,
fc.constant(1),
)),
/**
* 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.
*/
top_p: fc.option(fc.oneof(
TopP,
fc.constant(1),
)),
/**
* 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`.
*/
n: fc.option(fc.oneof(
N,
fc.constant(1),
)),
/**
* The maximum number of [tokens](/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.
*/
max_tokens: fc.option(fc.oneof(
MaxTokens,
fc.constant(16),
)),
/** Up to 4 sequences where the API will stop generating further tokens. */
stop: fc.option(Stop),
/**
* 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.](/docs/guides/gpt/parameter-details)
*/
presence_penalty: fc.option(Penalty),
/**
* 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.](/docs/guides/gpt/parameter-details)
*/
frequency_penalty: fc.option(Penalty),
/**
* 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.
*/
logit_bias: fc.option(fc.dictionary(fc.string(), fc.maxSafeInteger())),
/**
* A unique identifier representing your end-user, which can help OpenAI to monitor and detect
* abuse. [Learn more](/docs/guides/safety-best-practices/end-user-ids).
*/
user: User,
/**
* If set, partial message deltas will be sent, like in ChatGPT. Tokens will be sent as data-only
* [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format)
* 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).
*/
stream: fc.option(fc.boolean()),
/**
* ID of the model to use. See the [model endpoint compatibility](/docs/models/model-endpoint-compatibility)
* table for details on which models work with the Chat API.
*/
model: fc.oneof(
fc.string(),
fc.constantFrom("gpt4", "gpt-4-0314", "gpt-4-0613", "gpt-4-32k", "gpt-4-32k-0314", "gpt-4-32k-0613", "gpt-3.5-turbo", "gpt-3.5-turbo-16k", "gpt-3.5-turbo-0301", "gpt-3.5-turbo-0613", "gpt-3.5-turbo-16k-0613"),
),
/**
* A list of messages comprising the conversation so far.
* [Example Python code](https://github.com/openai/openai-cookbook/blob/main/examples/How_to_format_inputs_to_ChatGPT_models.ipynb).
*/
messages: fc.array(ChatCompletionRequestMessage, { minLength: 1 }),
/** A list of functions the model may generate JSON inputs for. */
functions: fc.array(ChatCompletionFunctions, {
minLength: 1,
maxLength: 128,
}),
/**
* 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.
*/
function_call: fc.oneof(
ChatCompletionFunctionCallOption,
fc.constantFrom("none", "auto"),
),
},
{
requiredKeys: ["model", "messages"],
},
),
ChatCompletionRequestMessage: ChatCompletionRequestMessage,
ChatCompletionFunctions: ChatCompletionFunctions,
ChatCompletionFunctionParameters: ChatCompletionFunctionParameters,
ChatCompletionFunctionCallOption: ChatCompletionFunctionCallOption,
StopSequences: StopSequences,
/** Represents a chat completion response returned by model, based on the provided input. */
CreateChatCompletionResponse: fc.record(
{
/** A unique identifier for the chat completion. */
id: fc.string(),
/** The object type, which is always `chat.completion`. */
object: fc.string(),
/** The Unix timestamp (in seconds) of when the chat completion was created. */
created: fc.string(),
/** The model used for the chat completion. */
model: fc.string(),
/** A list of chat completion choices. Can be more than one if `n` is greater than 1. */
choices: fc.array(fc.record({
/** The index of the choice in the list of choices. */
index: fc.maxSafeInteger(),
message: ChatCompletionResponseMessage,
/**
* The reason the model stopped generating tokens. This will be `stop` if the model hit a
* natural stop point or a provided stop sequence, `length` if the maximum number of tokens
* specified in the request was reached, `content_filter` if the content was omitted due to
* a flag from our content filters, or `function_call` if the model called a function.
*/
finish_reason: fc.constantFrom("stop", "length", "function_call", "content_filter"),
})),
usage: CompletionUsage,
},
{
requiredKeys: ["id", "object", "created", "model", "choices"],
},
),
ChatCompletionResponseMessage: ChatCompletionResponseMessage,
/** Usage statistics for the completion request. */
CompletionUsage: CompletionUsage,
CreateCompletionRequest: fc.record(
{
/**
* 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.
*/
temperature: fc.option(fc.oneof(
Temperature,
fc.constant(1),
)),
/**
* 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.
*/
top_p: fc.option(fc.oneof(
TopP,
fc.constant(1),
)),
/**
* 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`.
*/
n: fc.option(fc.oneof(
N,
fc.constant(1),
)),
/**
* The maximum number of [tokens](/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.
*/
max_tokens: fc.option(fc.oneof(
MaxTokens,
fc.constant(16),
)),
/** Up to 4 sequences where the API will stop generating further tokens. */
stop: fc.option(Stop),
/**
* 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.](/docs/guides/gpt/parameter-details)
*/
presence_penalty: fc.option(Penalty),
/**
* 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.](/docs/guides/gpt/parameter-details)
*/
frequency_penalty: fc.option(Penalty),
/**
* 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.
*/
logit_bias: fc.option(fc.dictionary(fc.string(), fc.maxSafeInteger())),
/**
* A unique identifier representing your end-user, which can help OpenAI to monitor and detect
* abuse. [Learn more](/docs/guides/safety-best-practices/end-user-ids).
*/
user: User,
/**
* If set, partial message deltas will be sent, like in ChatGPT. Tokens will be sent as data-only
* [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format)
* 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).
*/
stream: fc.option(fc.boolean()),
/**
* ID of the model to use. You can use the [List models](/docs/api-reference/models/list) API to
* see all of your available models, or see our [Model overview](/docs/models/overview) for
* descriptions of them.
*/
model: fc.oneof(
fc.string(),
fc.constantFrom("babbage-002", "davinci-002", "text-davinci-003", "text-davinci-002", "text-davinci-001", "code-davinci-002", "text-curie-001", "text-babbage-001", "text-ada-001"),
),
/**
* 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.
*/
prompt: fc.oneof(
Prompt,
fc.constant("<|endoftext|>"),
),
/** The suffix that comes after a completion of inserted text. */
suffix: fc.option(fc.string()),
/**
* 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.
*/
logprobs: fc.option(fc.maxSafeInteger()),
/** Echo back the prompt in addition to the completion */
echo: fc.option(fc.boolean()),
/**
* 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`.
*/
best_of: fc.option(fc.oneof(
fc.maxSafeInteger(),
fc.constant(1),
)),
},
{
requiredKeys: ["model"],
},
),
TokenArray: TokenArray,
TokenArrayArray: TokenArrayArray,
/**
* Represents a completion response from the API. Note: both the streamed and non-streamed response
* objects share the same shape (unlike the chat endpoint).
*/
CreateCompletionResponse: fc.record(
{
/** A unique identifier for the completion. */
id: fc.string(),
/** The object type, which is always `text_completion`. */
object: fc.string(),
/** The Unix timestamp (in seconds) of when the completion was created. */
created: fc.string(),
/** The model used for the completion. */
model: fc.string(),
/** The list of completion choices the model generated for the input. */
choices: fc.array(fc.record({
index: fc.maxSafeInteger(),
text: fc.string(),
logprobs: fc.option(fc.record({
tokens: fc.array(fc.string()),
token_logprobs: fc.array(fc.double()),
top_logprobs: fc.array(fc.dictionary(fc.string(), fc.maxSafeInteger())),
text_offset: fc.array(fc.maxSafeInteger()),
})),
/**
* The reason the model stopped generating tokens. This will be `stop` if the model hit a
* natural stop point or a provided stop sequence, or `content_filter` if content was omitted
* due to a flag from our content filters, `length` if the maximum number of tokens specified
* in the request was reached, or `content_filter` if content was omitted due to a flag from our
* content filters.
*/
finish_reason: fc.constantFrom("stop", "length", "content_filter"),
})),
usage: CompletionUsage,
},
{
requiredKeys: ["id", "object", "created", "model", "choices"],
},
),
CreateEditRequest: fc.record(
{
/**
* ID of the model to use. You can use the `text-davinci-edit-001` or `code-davinci-edit-001`
* model with this endpoint.
*/
model: fc.oneof(
fc.string(),
fc.constantFrom("text-davinci-edit-001", "code-davinci-edit-001"),
),
/** The input text to use as a starting point for the edit. */
input: fc.option(fc.oneof(
fc.string(),
fc.constant(""),
)),
/** The instruction that tells the model how to edit the prompt. */
instruction: fc.string(),
/** How many edits to generate for the input and instruction. */
n: fc.option(fc.oneof(
EditN,
fc.constant(1),
)),
/**
* 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.
*/
temperature: fc.option(fc.oneof(
Temperature,
fc.constant(1),
)),
/**
* 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.
*/
top_p: fc.option(fc.oneof(
TopP,
fc.constant(1),
)),
},
{
requiredKeys: ["model", "instruction"],
},
),
CreateEditResponse: fc.record({
/** The object type, which is always `edit`. */
object: fc.constant("edit"),
/** The Unix timestamp (in seconds) of when the edit was created. */
created: fc.string(),
/** description: A list of edit choices. Can be more than one if `n` is greater than 1. */
choices: fc.array(fc.record({
/** The edited result. */
text: fc.string(),
/** The index of the choice in the list of choices. */
index: fc.maxSafeInteger(),
/**
* The reason the model stopped generating tokens. This will be `stop` if the model hit a
* natural stop point or a provided stop sequence, or `length` if the maximum number of tokens
* specified in the request was reached.
*/
finish_reason: fc.constantFrom("stop", "length"),
})),
usage: CompletionUsage,
}),
CreateEmbeddingRequest: fc.record(
{
/** ID of the model to use. You can use the [List models](/docs/api-reference/models/list) API to see all of your available models, or see our [Model overview](/docs/models/overview) for descriptions of them. */
model: fc.oneof(
fc.string(),
fc.constant("text-embedding-ada-002"),
),
/**
* Input 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`) and cannot be an empty string.
* [Example Python code](https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb)
* for counting tokens.
*/
input: fc.oneof(
fc.string(),
fc.array(fc.string()),
TokenArray,
TokenArrayArray,
),
user: User,
},
{
requiredKeys: ["model", "input"],
},
),
CreateEmbeddingResponse: fc.record({
/** The object type, which is always "embedding". */
object: fc.constant("embedding"),
/** The name of the model used to generate the embedding. */
model: fc.string(),
/** The list of embeddings generated by the model. */
data: fc.array(Embedding),
/** The usage information for the request. */
usage: fc.record({
/** The number of tokens used by the prompt. */
prompt_tokens: fc.maxSafeInteger(),
/** The total number of tokens used by the request. */
total_tokens: fc.maxSafeInteger(),
}),
}),
/** Represents an embedding vector returned by embedding endpoint. */
Embedding: Embedding,
ListModelsResponse: fc.record({
object: fc.string(),
data: fc.array(Model),
}),