-
Notifications
You must be signed in to change notification settings - Fork 743
/
OpenAI.h
1008 lines (894 loc) · 34 KB
/
OpenAI.h
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
/* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include "cJSON.h"
/*<! Enum for image sizes */
typedef enum {
OPENAI_IMAGE_SIZE_1024x1024,
OPENAI_IMAGE_SIZE_512x512,
OPENAI_IMAGE_SIZE_256x256
} OpenAI_Image_Size;
/*<! Enum for image response formats */
typedef enum {
OPENAI_IMAGE_RESPONSE_FORMAT_URL,
OPENAI_IMAGE_RESPONSE_FORMAT_B64_JSON
} OpenAI_Image_Response_Format;
/*<! Enum for audio response formats */
typedef enum {
OPENAI_AUDIO_RESPONSE_FORMAT_JSON,
OPENAI_AUDIO_RESPONSE_FORMAT_TEXT,
OPENAI_AUDIO_RESPONSE_FORMAT_SRT,
OPENAI_AUDIO_RESPONSE_FORMAT_VERBOSE_JSON,
OPENAI_AUDIO_RESPONSE_FORMAT_VTT
} OpenAI_Audio_Response_Format;
/*<! Enum for audio input formats */
typedef enum {
OPENAI_AUDIO_INPUT_FORMAT_MP3,
OPENAI_AUDIO_INPUT_FORMAT_MP4,
OPENAI_AUDIO_INPUT_FORMAT_MPEG,
OPENAI_AUDIO_INPUT_FORMAT_MPGA,
OPENAI_AUDIO_INPUT_FORMAT_M4A,
OPENAI_AUDIO_INPUT_FORMAT_WAV,
OPENAI_AUDIO_INPUT_FORMAT_WEBM
} OpenAI_Audio_Input_Format;
/*<! Enum for audio output formats */
typedef enum {
OPENAI_AUDIO_OUTPUT_FORMAT_MP3,
OPENAI_AUDIO_OUTPUT_FORMAT_OPUS,
OPENAI_AUDIO_OUTPUT_FORMAT_AAC,
OPENAI_AUDIO_OUTPUT_FORMAT_FLAC
} OpenAI_Audio_Output_Format;
/**
* @brief Struct for Embedding data
*
*/
typedef struct {
uint32_t len; /*!< Length of the data */
double *data; /*!< Pointer to the data */
} OpenAI_EmbeddingData_t;
/**
* @brief To get an embedding, send your text string to the embeddings API
* endpoint along with a choice of embedding model ID (e.g., text-embedding-ada-002).
* The response will contain an embedding, which you can extract, save, and use.
*/
typedef struct OpenAI_EmbeddingResponse {
/**
* @brief Get the usage of OpenAI_EmbeddingResponse
*
* @param stringResponse[in] The pointer to OpenAI_EmbeddingResponse
* @return uint32_t
*/
uint32_t (*getUsage)(struct OpenAI_EmbeddingResponse *stringResponse);
/**
* @brief Get the length of OpenAI_EmbeddingResponse
*
* @param embeddingData[in] The pointer to OpenAI_EmbeddingResponse
* @return uint32_t
*/
uint32_t (*getLen)(struct OpenAI_EmbeddingResponse *embeddingData);
/**
* @brief Get the data of OpenAI_EmbeddingResponse
*
* @param embeddingData[in] The pointer to OpenAI_EmbeddingResponse
* @param index[in] The index of the data
* @return OpenAI_EmbeddingData_t*
*/
OpenAI_EmbeddingData_t *(*getData)(struct OpenAI_EmbeddingResponse *embeddingData, uint32_t index);
/**
* @brief Get the error of OpenAI_EmbeddingResponse
*
* @param embeddingData[in] The pointer to OpenAI_EmbeddingResponse
* @return char*
*/
char *(*getError)(struct OpenAI_EmbeddingResponse *embeddingData);
/**
* @brief delete the embedding response, should free it after use.
*
* @param embeddingData[in] the point of OpenAI_EmbeddingResponse
*/
void (*deleteResponse)(struct OpenAI_EmbeddingResponse *embeddingData);
} OpenAI_EmbeddingResponse_t;
/**
* @brief The moderations endpoint is a tool you can use to check whether content complies with OpenAI's usage policies.
* Developers can thus identify content that our usage policies prohibits and take action, for instance by filtering it.
*/
typedef struct OpenAI_ModerationResponse {
/**
* @brief Get the length of OpenAI_ModerationResponse
*
* @param moderationResponse[in] The pointer to OpenAI_ModerationResponse
* @return uint32_t
*/
uint32_t (*getLen)(struct OpenAI_ModerationResponse *moderationResponse);
/**
* @brief Get the moderation result of OpenAI_ModerationResponse
*
* @param moderationResponse[in] The pointer to OpenAI_ModerationResponse
* @param index[in] The index of the moderation result
* @return bool
*/
bool (*getData)(struct OpenAI_ModerationResponse *moderationResponse, uint32_t index);
/**
* @brief Get the error message of OpenAI_ModerationResponse
*
* @param moderationResponse[in] The pointer to OpenAI_ModerationResponse
* @return char*
*/
char *(*getError)(struct OpenAI_ModerationResponse *moderationResponse);
/**
* @brief delete the moderation response, should free it after use.
*
* @param moderationResponse[in] the point of } OpenAI_ModerationResponse_t
*/
void (*deleteResponse)(struct OpenAI_ModerationResponse *moderationResponse);
} OpenAI_ModerationResponse_t;
/**
* @brief Save the image which is generated by OpenAI
*
*/
typedef struct OpenAI_ImageResponse {
/**
* @brief Get the length of OpenAI_ImageResponse
*
* @param imageResponse[in] The pointer to OpenAI_ImageResponse
* @return uint32_t
*/
uint32_t (*getLen)(struct OpenAI_ImageResponse *imageResponse);
/**
* @brief Get the data of OpenAI_ImageResponse
*
* @param imageResponse[in] The pointer to OpenAI_ImageResponse
* @param index[in] The index of the image data
* @return char*
*/
char *(*getData)(struct OpenAI_ImageResponse *imageResponse, uint32_t index);
/**
* @brief Get the error message of OpenAI_ImageResponse
*
* @param imageResponse[in] The pointer to OpenAI_ImageResponse
* @return char*
*/
char *(*getError)(struct OpenAI_ImageResponse *imageResponse);
/**
* @brief delete the image response
*
* @param imageResponse[in] the point of } OpenAI_ImageResponse_t
*/
void (*deleteResponse)(struct OpenAI_ImageResponse *imageResponse);
} OpenAI_ImageResponse_t;
/**
* @brief Parse the returned json data into OpenAI_StringResponse_t
*/
typedef struct OpenAI_StringResponse {
/**
* @brief get the usage of openai response
*
* @param stringResponse[in] the point of OpenAI_StringResponse_t
* @return uint32_t
*/
uint32_t (*getUsage)(struct OpenAI_StringResponse *stringResponse);
/**
* @brief get the len of openai response
*
* @param stringResponse[in] the point of OpenAI_StringResponse_t
* @return uint32_t
*/
uint32_t (*getLen)(struct OpenAI_StringResponse *stringResponse);
/**
* @brief get the data of openai response
*
* @param stringResponse[in] the point of OpenAI_StringResponse_t
* @param index[in] the index of data
* @return char*
*/
char *(*getData)(struct OpenAI_StringResponse *stringResponse, uint32_t index);
/**
* @brief get the error of openai response
*
* @param stringResponse[in] the point of OpenAI_StringResponse_t
* @return char*
*/
char *(*getError)(struct OpenAI_StringResponse *stringResponse);
/**
* @brief delete the openai response
*
* @param stringResponse[in] the point of OpenAI_StringResponse_t
*/
void (*deleteResponse)(struct OpenAI_StringResponse *stringResponse);
} OpenAI_StringResponse_t;
/**
* @brief Store the returned data into a OpenAI_SpeechResponse_t structure
*/
typedef struct OpenAI_SpeechResponse {
/**
* @brief get the len of openai speech response
*
* @param speechResponse[in] the point of OpenAI_SpeechResponse_t
* @return uint32_t
*/
uint32_t (*getLen)(struct OpenAI_SpeechResponse *SpeechResponse);
/**
* @brief get the data of openai response
*
* @param SpeechResponse[in] the point of OpenAI_SpeechResponse_t
* @return char*
*/
char *(*getData)(struct OpenAI_SpeechResponse *SpeechResponse);
/**
* @brief delete the openai response
*
* @param SpeechResponse[in] the point of OpenAI_SpeechResponse_t
*/
void (*deleteResponse)(struct OpenAI_SpeechResponse *SpeechResponse);
} OpenAI_SpeechResponse_t;
/**
* @brief Given a prompt, the model will return one or more predicted completions,
* and can also return the probabilities of alternative tokens at each position.
*
*/
typedef struct OpenAI_Completion {
/**
* @brief Set the model to use for completion
*
* @param completion[in] the point of OpenAI_Completion_t
* @param m[in] the name of the model to use for completion
*/
void (*setModel)(struct OpenAI_Completion *completion, const char *m);
/**
* @brief Set the maximum number of tokens to generate in the completion.
*
* @param completion[in] the point of OpenAI_Completion_t
* @param mt[in] the maximum number of tokens to generate in the completion
*/
void (*setMaxTokens)(struct OpenAI_Completion *completion, uint32_t mt);
/**
* @brief Set the temperature of the completion.
*
* @param completion[in] the point of OpenAI_Completion_t
* @param t[in] float between 0 and 2. Higher value gives more random results.
*/
void (*setTemperature)(struct OpenAI_Completion *completion, float t);
/**
* @brief Set the value of top_p for the completion.
*
* @param completion[in] the point of OpenAI_Completion_t
* @param tp[in] float between 0 and 1. recommended to alter this or temperature but not both.
*/
void (*setTopP)(struct OpenAI_Completion *completion, float tp);
/**
* @brief Set the number of completions to generate for each prompt.
*
* @param completion[in] the point of OpenAI_Completion_t
* @param n[in] the number of completions to generate for each prompt
*/
void (*setN)(struct OpenAI_Completion *completion, uint32_t n);
/**
* @brief Echo back the prompt in addition to the completion.
*
* @param completion[in] the point of OpenAI_Completion_t
* @param e[in] true if the prompt should be echoed back, false otherwise
*/
void (*setEcho)(struct OpenAI_Completion *completion, bool e);
/**
* @brief Set up to 4 sequences where the API will stop generating further tokens.
*
* @param completion[in] the point of OpenAI_Completion_t
* @param s[in] the sequences where the API will stop generating further tokens
*/
void (*setStop)(struct OpenAI_Completion *completion, const char *s);
/**
* @brief Set the presence penalty for the completion.
*
* @param completion[in] the point of OpenAI_Completion_t
* @param pp[in] float between -2.0 and 2.0. Positive values increase the model's likelihood to talk about new topics.
*/
void (*setPresencePenalty)(struct OpenAI_Completion *completion, float pp);
/**
* @brief Set the frequency penalty for the completion.
*
* @param completion[in] the point of OpenAI_Completion_t
* @param fp[in] float between -2.0 and 2.0. Positive values decrease the model's likelihood to repeat the same line verbatim.
*/
void (*setFrequencyPenalty)(struct OpenAI_Completion *completion, float fp);
/**
* @brief Generates best_of completions server-side and returns the "best". "best_of" must be greater than "n".
*
* @param completion[in] the point of OpenAI_Completion_t
* @param bo[in] the number of best_of completions to generate server-side and return the "best"
*/
void (*setBestOf)(struct OpenAI_Completion *completion, uint32_t bo);
/**
* @brief A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.
*
* @param completion[in] the point of OpenAI_Completion_t
* @param u[in] the unique identifier representing your end-user
*/
void (*setUser)(struct OpenAI_Completion *completion, const char *u);
/**
* @brief Send the prompt for completion.
*
* @param completion[in] the point of OpenAI_Completion_t
* @param p[in] the prompt for completion
* @return OpenAI_StringResponse_t*
*/
OpenAI_StringResponse_t *(*prompt)(struct OpenAI_Completion *completion, char *p);
} OpenAI_Completion_t;
/**
* @brief Given a list of messages comprising a conversation, the model will return a response.
*
*/
typedef struct OpenAI_ChatCompletion {
/**
* @brief Set the model to use for completion
*
* @param chatCompletion[in] the point of OpenAI_ChatCompletion
* @param m[in] the name of the model to use for chatCompletion
*/
void (*setModel)(struct OpenAI_ChatCompletion *chatCompletion, const char *m);
/**
* @brief Set the system to use for completion
*
* @param chatCompletion[in] the point of OpenAI_ChatCompletion
* @param s[in] description of the required assistant
*/
void (*setSystem)(struct OpenAI_ChatCompletion *chatCompletion, const char *s);
/**
* @brief Set the maximum number of tokens to generate in the completion.
*
* @param chatCompletion[in] the point of OpenAI_ChatCompletion
* @param mt[in] the maximum number of tokens to generate in the completion
*/
void (*setMaxTokens)(struct OpenAI_ChatCompletion *chatCompletion, uint32_t mt);
/**
* @brief Set the temperature for the completion.
*
* @param chatCompletion[in] the point of OpenAI_ChatCompletion
* @param t[in] float between 0 and 2. Higher value gives more random results.
*/
void (*setTemperature)(struct OpenAI_ChatCompletion *chatCompletion, float t);
/**
* @brief Set the top_p for the completion.
*
* @param chatCompletion[in] the point of OpenAI_ChatCompletion
* @param tp[in] float between 0 and 1. recommended to alter this or temperature but not both.
*/
void (*setTopP)(struct OpenAI_ChatCompletion *chatCompletion, float tp);
/**
* @brief Set up to 4 sequences where the API will stop generating further tokens.
*
* @param chatCompletion[in] the point of OpenAI_ChatCompletion
* @param s[in] the sequences where the API will stop generating further tokens
*/
void (*setStop)(struct OpenAI_ChatCompletion *chatCompletion, const char *s);
/**
* @brief Set the presence penalty for the completion.
*
* @param chatCompletion[in] the point of OpenAI_ChatCompletion
* @param pp[in] float between -2.0 and 2.0. Positive values increase the model's likelihood to talk about new topics.
*/
void (*setPresencePenalty)(struct OpenAI_ChatCompletion *chatCompletion, float pp);
/**
* @brief Set the frequency penalty for the completion.
*
* @param chatCompletion[in] the point of OpenAI_ChatCompletion
* @param fp[in] float between -2.0 and 2.0. Positive values decrease the model's likelihood to repeat the same line verbatim.
*/
void (*setFrequencyPenalty)(struct OpenAI_ChatCompletion *chatCompletion, float fp);
/**
* @brief A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.
*
* @param chatCompletion[in] the point of OpenAI_ChatCompletion
* @param u[in] the unique identifier representing your end-user
*/
void (*setUser)(struct OpenAI_ChatCompletion *chatCompletion, const char *u);
/**
* @brief Clears the accumulated conversation.
*
* @param chatCompletion[in] the point of OpenAI_ChatCompletion
*/
void (*clearConversation)(struct OpenAI_ChatCompletion *chatCompletion);
/**
* @brief Send the message for completion. Save it with the first response if selected.
*
* @param chatCompletion[in] the point of OpenAI_ChatCompletion
* @param p[in] the message for completion
* @param save[in] save it with the first response if selected
* @return OpenAI_StringResponse_t*
*/
OpenAI_StringResponse_t *(*message)(struct OpenAI_ChatCompletion *chatCompletion, const char *p, bool save);
} OpenAI_ChatCompletion_t;
/**
* @brief Given a prompt and an instruction, the model will return an edited version of the prompt.
*
*/
typedef struct OpenAI_Edit {
/**
* @brief Set the model to use for edit
*
* @param edit[in] the point of OpenAI_Edit_t
* @param m[in] the name of the model to use for edit
*/
void (*setModel)(struct OpenAI_Edit *edit, const char *m);
/**
* @brief Set the temperature for the edit.
*
* @param edit[in] the point of OpenAI_Edit_t
* @param t[in] float between 0 and 2. Higher value gives more random results.
*/
void (*setTemperature)(struct OpenAI_Edit *edit, float t);
/**
* @brief Set the top_p for the edit.
*
* @param edit[in] the point of OpenAI_Edit_t
* @param tp[in] float between 0 and 1. recommended to alter this or temperature but not both.
*/
void (*setTopP)(struct OpenAI_Edit *edit, float tp);
/**
* @brief Set the number of edits to generate for the input and instruction.
*
* @param edit[in] the point of OpenAI_Edit_t
* @param n[in] the number of edits to generate for the input and instruction
*/
void (*setN)(struct OpenAI_Edit *edit, uint32_t n);
/**
* @brief Creates a new edit for the provided input, instruction, and parameters.
*
* @param edit[in] the point of OpenAI_Edit_t
* @param instruction[in] the instruction for the edit
* @param input[in] the input text to be edited
* @return OpenAI_StringResponse_t* the edited text
*/
OpenAI_StringResponse_t *(*process)(struct OpenAI_Edit *edit, char *instruction, char *input);
} OpenAI_Edit_t;
/**
* @brief Creates an image given a prompt.
*
*/
typedef struct OpenAI_ImageGeneration {
/**
* @brief Set the size of the generated images.
*
* @param imageGeneration[in] the point of OpenAI_ImageGeneration
* @param s[in] the size of the generated images
*/
void (*setSize)(struct OpenAI_ImageGeneration *imageGeneration, OpenAI_Image_Size s);
/**
* @brief Set the format in which the generated images are returned.
*
* @param imageGeneration[in] the point of OpenAI_ImageGeneration
* @param rf[in] the format in which the generated images are returned
*/
void (*setResponseFormat)(struct OpenAI_ImageGeneration *imageGeneration, OpenAI_Image_Response_Format rf);
/**
* @brief Set the number of images to generate. Must be between 1 and 10.
*
* @param imageGeneration[in] the point of OpenAI_ImageGeneration
* @param n[in] the number of images to generate
*/
void (*setN)(struct OpenAI_ImageGeneration *imageGeneration, uint32_t n);
/**
* @brief Set a unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.
*
* @param imageGeneration[in] the point of OpenAI_ImageGeneration
* @param u[in] the unique identifier representing your end-user
*/
void (*setUser)(struct OpenAI_ImageGeneration *imageGeneration, const char *u);
/**
* @brief Creates image/images from given a prompt.
*
* @param imageGeneration[in] the point of OpenAI_ImageGeneration
* @param p[in] the prompt for image generation
* @return OpenAI_ImageResponse_t* the generated image/images
*/
OpenAI_ImageResponse_t *(*prompt)(struct OpenAI_ImageGeneration *imageGeneration, char *p);
} OpenAI_ImageGeneration_t;
/**
* @brief Creates a variation of a given image.
*
*/
typedef struct OpenAI_ImageVariation {
/**
* @brief Set the size of the generated images.
*
* @param imageVariation[in] the point of OpenAI_ImageVariation
* @param s[in] the size of the generated images
*/
void (*setSize)(struct OpenAI_ImageVariation *imageVariation, OpenAI_Image_Size s);
/**
* @brief Set the format in which the generated images are returned.
*
* @param imageVariation[in] the point of OpenAI_ImageVariation
* @param rf[in] the format in which the generated images are returned
*/
void (*setResponseFormat)(struct OpenAI_ImageVariation *imageVariation, OpenAI_Image_Response_Format rf);
/**
* @brief Set the number of images to generate. Must be between 1 and 10.
*
* @param imageVariation[in] the point of OpenAI_ImageVariation
* @param n[in] the number of images to generate
*/
void (*setN)(struct OpenAI_ImageVariation *imageVariation, uint32_t n);
/**
* @brief Set a unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.
*
* @param imageVariation[in] the point of OpenAI_ImageVariation
* @param u[in] the unique identifier representing your end-user
*/
void (*setUser)(struct OpenAI_ImageVariation *imageVariation, const char *u);
/**
* @brief Creates an image variation from given image data.
*
* @param imageVariation[in] the point of OpenAI_ImageVariation
* @param data[in] the input image data
* @param len[in] the length of the input image data
* @return OpenAI_ImageResponse_t* the generated image variation
*/
OpenAI_ImageResponse_t *(*image)(struct OpenAI_ImageVariation *imageVariation, uint8_t *data, size_t len);
} OpenAI_ImageVariation_t;
/**
* @brief Creates an edited or extended image given an original image and a prompt.
*
*/
typedef struct OpenAI_ImageEdit {
/**
* @brief Set the prompt for the image edit.
*
* @param imageEdit[in] the point of OpenAI_ImageEdit_t
* @param p[in] the prompt for the image edit
*/
void (*setPrompt)(struct OpenAI_ImageEdit *imageEdit, const char *p);
/**
* @brief Set the size of the generated images.
*
* @param imageEdit[in] the point of OpenAI_ImageEdit_t
* @param s[in] the size of the generated images
*/
void (*setSize)(struct OpenAI_ImageEdit *imageEdit, OpenAI_Image_Size s);
/**
* @brief Set the format in which the generated images are returned.
*
* @param imageEdit[in] the point of OpenAI_ImageEdit_t
* @param rf[in] the format in which the generated images are returned
*/
void (*setResponseFormat)(struct OpenAI_ImageEdit *imageEdit, OpenAI_Image_Response_Format rf);
/**
* @brief Set the number of images to generate. Must be between 1 and 10.
*
* @param imageEdit[in] the point of OpenAI_ImageEdit_t
* @param n[in] the number of images to generate
*/
void (*setN)(struct OpenAI_ImageEdit *imageEdit, uint32_t n);
/**
* @brief Set a unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse.
*
* @param imageEdit[in] the point of OpenAI_ImageEdit_t
* @param u[in] the unique identifier representing your end-user
*/
void (*setUser)(struct OpenAI_ImageEdit *imageEdit, const char *u);
/**
* @brief Creates an edited or extended image given an original image, a mask, and a prompt.
*
* @param imageEdit[in] the point of OpenAI_ImageEdit_t
* @param data[in] the input image data
* @param len[in] the length of the input image data
* @param mask_data[in] the input mask data
* @param mask_len[in] the length of the input mask data
* @return OpenAI_ImageResponse_t* the edited or extended image
*/
OpenAI_ImageResponse_t *(*image)(struct OpenAI_ImageEdit *imageEdit, uint8_t *data, size_t len, uint8_t *mask_data, size_t mask_len);
} OpenAI_ImageEdit_t;
/**
* @brief Transcribes audio into the input language.
*
*/
typedef struct OpenAI_AudioTranscription {
/**
* @brief Set the prompt for the audio transcription.
*
* @param audioTranscription[in] the point of OpenAI_AudioTranscription_t
* @param p[in] the prompt for the audio transcription
*/
void (*setPrompt)(struct OpenAI_AudioTranscription *audioTranscription, const char *p);
/**
* @brief Set the format of the transcript output.
*
* @param audioTranscription[in] the point of OpenAI_AudioTranscription_t
* @param rf[in] the format of the transcript output
*/
void (*setResponseFormat)(struct OpenAI_AudioTranscription *audioTranscription, OpenAI_Audio_Response_Format rf);
/**
* @brief Set the temperature for the audio transcription.
*
* @param audioTranscription[in] the point of OpenAI_AudioTranscription_t
* @param t[in] float between 0 and 1
*/
void (*setTemperature)(struct OpenAI_AudioTranscription *audioTranscription, float t);
/**
* @brief Set the language of the input audio.
*
* @param audioTranscription[in] the point of OpenAI_AudioTranscription_t
* @param l[in] the language in ISO-639-1 format of the input audio. NULL for Auto.
*/
void (*setLanguage)(struct OpenAI_AudioTranscription *audioTranscription, const char *l);
/**
* @brief Transcribe an audio file.
*
* @param audioTranscription[in] the point of OpenAI_AudioTranscription_t
* @param data[in] the input audio data
* @param len[in] the length of the input audio data
* @param f[in] the format of the input audio data
* @return char* the transcribed text, you should free it after use.
*/
char *(*file)(struct OpenAI_AudioTranscription *audioTranscription, uint8_t *data, size_t len, OpenAI_Audio_Input_Format f);
} OpenAI_AudioTranscription_t;
/**
* @brief Given a list of messages comprising a conversation, the model will return a response.
*
*/
typedef struct OpenAI_AudioSpeech {
/**
* @brief Set the model to use for completion
*
* @param createSpeech[in] the point of OpenAI_SpeechResponse_t
* @param m[in] the name of the model to use for audio response
*/
void (*setModel)(struct OpenAI_AudioSpeech *createSpeech, const char *m);
/**
* @brief Set the voice to use for completion
*
* @param createSpeech[in] the point of OpenAI_SpeechResponse_t
* @param m[in] the name of the model to use for audio response
*/
void (*setVoice)(struct OpenAI_AudioSpeech *createSpeech, const char *m);
/**
* @brief Set the speed of the output audio.
*
* @param createSpeech[in] the point of OpenAI_SpeechResponse_t
* @param t[in] float between 0.25 to 4.0
*/
void (*setSpeed)(struct OpenAI_AudioSpeech *createSpeech, float t);
/**
* @brief Set the format of the output.
*
* @param createSpeech[in] the point of OpenAI_SpeechResponse_t
* @param rf[in] the format of the output audio
*/
void (*setResponseFormat)(struct OpenAI_AudioSpeech *createSpeech, OpenAI_Audio_Output_Format rf);
/**
* @brief Send the message for completion. Save it with the first response if selected.
*
* @param createSpeech[in] the point of OpenAI_SpeechResponse_t
* @param p[in] the message for audio generation
* @return *
*/
OpenAI_SpeechResponse_t *(*speech)(struct OpenAI_AudioSpeech *createSpeech, char *p);
} OpenAI_AudioSpeech_t;
/**
* @brief Translates audio into English.
*
*/
typedef struct OpenAI_AudioTranslation {
/**
* @brief Set the prompt for the audio translation.
*
* @param audioTranslation[in] the point of OpenAI_AudioTranslation_t
* @param p[in] the prompt for the audio translation
*/
void (*setPrompt)(struct OpenAI_AudioTranslation *audioTranslation, const char *p);
/**
* @brief Set the format of the transcript output.
*
* @param audioTranslation[in] the point of OpenAI_AudioTranslation_t
* @param rf[in] the format of the transcript output
*/
void (*setResponseFormat)(struct OpenAI_AudioTranslation *audioTranslation, OpenAI_Audio_Response_Format rf);
/**
* @brief Set the temperature for the audio translation.
*
* @param audioTranslation[in] the point of OpenAI_AudioTranslation_t
* @param t[in] float between 0 and 2. Higher value gives more random results.
*/
void (*setTemperature)(struct OpenAI_AudioTranslation *audioTranslation, float t);
/**
* @brief Transcribe and translate an audio file into English.
*
* @param audioTranslation[in] the point of OpenAI_AudioTranslation_t
* @param data[in] the input audio data
* @param len[in] the length of the input audio data
* @param f[in] the format of the input audio data
* @return char* the translated text in English, you should free it after use.
*/
char *(*file)(struct OpenAI_AudioTranslation *audioTranslation, uint8_t *data, size_t len, OpenAI_Audio_Input_Format f);
} OpenAI_AudioTranslation_t;
/**
* @brief The entry point for calling the Openai api
*
*/
typedef struct OpenAI {
#if CONFIG_ENABLE_EMBEDDING || defined __DOXYGEN__
/**
* @brief Create an embedding vector representing the input text.
*
* @param openai[in] The OpenAI object
* @param input[in] The input text
* @param model[in] The model to use for creating the embedding
* @param user[in] The unique identifier representing the end-user
* @return OpenAI_EmbeddingResponse_t* The embedding response object
*/
OpenAI_EmbeddingResponse_t *(*embeddingCreate)(struct OpenAI *openai, char *input, const char *model, const char *user);
#endif
#if CONFIG_ENABLE_MODERATION || defined __DOXYGEN__
/**
* @brief Classify if text violates OpenAI's Content Policy.
*
* @param openai[in] The OpenAI object
* @param input[in] The input text
* @param model[in] The model to use for moderation
* @return OpenAI_ModerationResponse_t* The moderation response object
*/
OpenAI_ModerationResponse_t *(*moderationCreate)(struct OpenAI *openai, char *input, const char *model);
#endif
#if CONFIG_ENABLE_COMPLETION || defined __DOXYGEN__
/**
* @brief Generate text according to the prompt.
*
* @param openai[in] The OpenAI object
* @return OpenAI_Completion_t* The completion object
*/
OpenAI_Completion_t *(*completionCreate)(struct OpenAI *openai);
/**
* @brief Delete created completion handle.
*
* @param completion[in] The completion object
*/
void (*completionDelete)(OpenAI_Completion_t *completion);
#endif
#if CONFIG_ENABLE_CHAT_COMPLETION || defined __DOXYGEN__
/**
* @brief Create a chat completion object for chatting.
*
* @param openai[in] The OpenAI object
* @return OpenAI_ChatCompletion_t* The chat completion object
*/
OpenAI_ChatCompletion_t *(*chatCreate)(struct OpenAI *openai);
/**
* @brief Delete created chat completion handle.
*
* @param chatCompletion[in] The chat completion object
*/
void (*chatDelete)(OpenAI_ChatCompletion_t *chatCompletion);
#endif
#if CONFIG_ENABLE_EDIT || defined __DOXYGEN__
/**
* @brief Create an edit object for editing text.
*
* @param openai[in] The OpenAI object
* @return OpenAI_Edit_t* The edit object
*/
OpenAI_Edit_t *(*editCreate)(struct OpenAI *openai);
/**
* @brief Delete created edit handle.
*
* @param edit[in] The edit object
*/
void (*editDelete)(OpenAI_Edit_t *edit);
#endif
#if CONFIG_ENABLE_IMAGE_GENERATION || defined __DOXYGEN__
/**
* @brief Create an image generation object.
*
* @param openai[in] The OpenAI object
* @return OpenAI_ImageGeneration_t* The image generation object
*/
OpenAI_ImageGeneration_t *(*imageGenerationCreate)(struct OpenAI *openai);
/**
* @brief Delete created image generation handle.
*
* @param imageGeneration[in] The image generation object
*/
void (*imageGenerationDelete)(OpenAI_ImageGeneration_t *imageGeneration);
#endif
#if CONFIG_ENABLE_IMAGE_VARIATION || defined __DOXYGEN__
/**
* @brief Create an image variation object.
*
* @param openai[in] The OpenAI object
* @return OpenAI_ImageVariation_t* The image variation object
*/
OpenAI_ImageVariation_t *(*imageVariationCreate)(struct OpenAI *openai);
/**
* @brief Delete created image variation handle.
*
* @param imageVariation[in] The image variation object
*/
void (*imageVariationDelete)(OpenAI_ImageVariation_t *imageVariation);
#endif
#if CONFIG_ENABLE_IMAGE_EDIT || defined __DOXYGEN__
/**
* @brief Create an image editing object.
*
* @param openai[in] The OpenAI object
* @return OpenAI_ImageEdit_t* The image editing object
*/
OpenAI_ImageEdit_t *(*imageEditCreate)(struct OpenAI *openai);
/**
* @brief Delete created image editing handle.
*
* @param imageEdit[in] The image editing object
*/
void (*imageEditDelete)(OpenAI_ImageEdit_t *imageEdit);
#endif
#if CONFIG_ENABLE_AUDIO_TRANSCRIPTION || defined __DOXYGEN__
/**
* @brief Create an audio transcription object.
*
* @param openai[in] The OpenAI object
* @return OpenAI_AudioTranscription_t* The audio transcription object
*/
OpenAI_AudioTranscription_t *(*audioTranscriptionCreate)(struct OpenAI *openai);
/**
* @brief Delete created audio transcription handle.
*
* @param audioTranscription[in] The audio transcription object
*/
void (*audioTranscriptionDelete)(OpenAI_AudioTranscription_t *audioTranscription);
#endif
#if CONFIG_ENABLE_AUDIO_TRANSLATION || defined __DOXYGEN__
/**
* @brief Create an audio translation object.
*
* @param openai[in] The OpenAI object
* @return OpenAI_AudioTranslation_t* The audio translation object
*/
OpenAI_AudioTranslation_t *(*audioTranslationCreate)(struct OpenAI *openai);
/**
* @brief Delete created audio translation handle.
*
* @param audioTranslation[in] The audio translation object
*/
void (*audioTranslationDelete)(OpenAI_AudioTranslation_t *audioTranslation);
#endif
#if CONFIG_ENABLE_AUDIO_SPEECH || defined __DOXYGEN__
/**
* @brief Create an audio speech object.
*
* @param openai[in] The OpenAI object
* @return OpenAI_AudioSpeech_t* The audio speech object
*/
OpenAI_AudioSpeech_t *(*audioSpeechCreate)(struct OpenAI *openai);
/**
* @brief Delete an audio speech object.
*
* @param openai[in] The OpenAI object
* @return OpenAI_AudioSpeech_t* The audio speech object
*/
void (*audioSpeechDelete)(OpenAI_AudioSpeech_t *audioSpeech);
#endif
} OpenAI_t;
/**
* @brief Create an OpenAI object
*
* @param api_key The key of openai
* @return OpenAI_t* The OpenAI object
*/
OpenAI_t *OpenAICreate(const char *api_key);
/**
* @brief Clear the OpenAI object and release resources
*
* @param oai The OpenAI object
*/
void OpenAIDelete(OpenAI_t *oai);
/**