OpenAI
openai 组件是 OpenAI-ESP32 Arduino 库的移植版本,它简化了在 ESP-IDF 上调用 OpenAI API 的过程。该库广泛支持大部分 OpenAI API 的功能,但不包括 files 和 fine-tunes。更多详情,请参考 OpenAI 的 API 参考文档。
FAQ
使用 audioTranscription->file 报错 Failed to allocate request buffer!
该错误表明动态内存分配失败,通常是由于可用内存不足导致的。所需的内存大小取决于当前剩余的 RAM 或 PSRAM 大小。
解决方法
开启 PSRAM:如果设备支持 PSRAM,可以开启 PSRAM ,以增加可用内存,并打开宏 CONFIG_SPIRAM_USE_MALLOC 以使用 PSRAM。
减少音频的数据量:减少音频的数据量,例如减少音频的采样率、音频的长度等。
API 参考
Header File
Functions
-
OpenAI_t *OpenAICreate(const char *api_key)
Create an OpenAI object.
- 参数
api_key – The key of openai
- 返回
OpenAI_t* The OpenAI object
Structures
-
struct OpenAI_EmbeddingData_t
Struct for Embedding data.
-
struct OpenAI_EmbeddingResponse
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.
Public Members
-
uint32_t (*getUsage)(struct OpenAI_EmbeddingResponse *stringResponse)
Get the usage of OpenAI_EmbeddingResponse.
- Param stringResponse[in]
The pointer to OpenAI_EmbeddingResponse
- Return
uint32_t
-
uint32_t (*getLen)(struct OpenAI_EmbeddingResponse *embeddingData)
Get the length of OpenAI_EmbeddingResponse.
- Param embeddingData[in]
The pointer to OpenAI_EmbeddingResponse
- Return
uint32_t
-
OpenAI_EmbeddingData_t *(*getData)(struct OpenAI_EmbeddingResponse *embeddingData, uint32_t index)
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*
-
char *(*getError)(struct OpenAI_EmbeddingResponse *embeddingData)
Get the error of OpenAI_EmbeddingResponse.
- Param embeddingData[in]
The pointer to OpenAI_EmbeddingResponse
- Return
char*
-
void (*deleteResponse)(struct OpenAI_EmbeddingResponse *embeddingData)
delete the embedding response, should free it after use.
- Param embeddingData[in]
the point of OpenAI_EmbeddingResponse
-
uint32_t (*getUsage)(struct OpenAI_EmbeddingResponse *stringResponse)
-
struct OpenAI_ModerationResponse
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.
Public Members
-
uint32_t (*getLen)(struct OpenAI_ModerationResponse *moderationResponse)
Get the length of OpenAI_ModerationResponse.
- Param moderationResponse[in]
The pointer to OpenAI_ModerationResponse
- Return
uint32_t
-
bool (*getData)(struct OpenAI_ModerationResponse *moderationResponse, uint32_t index)
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
-
char *(*getError)(struct OpenAI_ModerationResponse *moderationResponse)
Get the error message of OpenAI_ModerationResponse.
- Param moderationResponse[in]
The pointer to OpenAI_ModerationResponse
- Return
char*
-
void (*deleteResponse)(struct OpenAI_ModerationResponse *moderationResponse)
delete the moderation response, should free it after use.
- Param moderationResponse[in]
the point of } OpenAI_ModerationResponse_t
-
uint32_t (*getLen)(struct OpenAI_ModerationResponse *moderationResponse)
-
struct OpenAI_ImageResponse
Save the image which is generated by OpenAI.
Public Members
-
uint32_t (*getLen)(struct OpenAI_ImageResponse *imageResponse)
Get the length of OpenAI_ImageResponse.
- Param imageResponse[in]
The pointer to OpenAI_ImageResponse
- Return
uint32_t
-
char *(*getData)(struct OpenAI_ImageResponse *imageResponse, uint32_t index)
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 *(*getError)(struct OpenAI_ImageResponse *imageResponse)
Get the error message of OpenAI_ImageResponse.
- Param imageResponse[in]
The pointer to OpenAI_ImageResponse
- Return
char*
-
void (*deleteResponse)(struct OpenAI_ImageResponse *imageResponse)
delete the image response
- Param imageResponse[in]
the point of } OpenAI_ImageResponse_t
-
uint32_t (*getLen)(struct OpenAI_ImageResponse *imageResponse)
-
struct OpenAI_StringResponse
Parse the returned json data into OpenAI_StringResponse_t.
Public Members
-
uint32_t (*getUsage)(struct OpenAI_StringResponse *stringResponse)
get the usage of openai response
- Param stringResponse[in]
the point of OpenAI_StringResponse_t
- Return
uint32_t
-
uint32_t (*getLen)(struct OpenAI_StringResponse *stringResponse)
get the len of openai response
- Param stringResponse[in]
the point of OpenAI_StringResponse_t
- Return
uint32_t
-
char *(*getData)(struct OpenAI_StringResponse *stringResponse, uint32_t index)
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 *(*getError)(struct OpenAI_StringResponse *stringResponse)
get the error of openai response
- Param stringResponse[in]
the point of OpenAI_StringResponse_t
- Return
char*
-
void (*deleteResponse)(struct OpenAI_StringResponse *stringResponse)
delete the openai response
- Param stringResponse[in]
the point of OpenAI_StringResponse_t
-
uint32_t (*getUsage)(struct OpenAI_StringResponse *stringResponse)
-
struct OpenAI_SpeechResponse
Store the returned data into a OpenAI_SpeechResponse_t structure.
Public Members
-
uint32_t (*getLen)(struct OpenAI_SpeechResponse *SpeechResponse)
get the len of openai speech response
- Param speechResponse[in]
the point of OpenAI_SpeechResponse_t
- Return
uint32_t
-
char *(*getData)(struct OpenAI_SpeechResponse *SpeechResponse)
get the data of openai response
- Param SpeechResponse[in]
the point of OpenAI_SpeechResponse_t
- Return
char*
-
void (*deleteResponse)(struct OpenAI_SpeechResponse *SpeechResponse)
delete the openai response
- Param SpeechResponse[in]
the point of OpenAI_SpeechResponse_t
-
uint32_t (*getLen)(struct OpenAI_SpeechResponse *SpeechResponse)
-
struct OpenAI_Completion
Given a prompt, the model will return one or more predicted completions, and can also return the probabilities of alternative tokens at each position.
Public Members
-
void (*setModel)(struct OpenAI_Completion *completion, const char *m)
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 (*setMaxTokens)(struct OpenAI_Completion *completion, uint32_t mt)
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 (*setTemperature)(struct OpenAI_Completion *completion, float t)
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 (*setTopP)(struct OpenAI_Completion *completion, float tp)
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 (*setN)(struct OpenAI_Completion *completion, uint32_t n)
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 (*setEcho)(struct OpenAI_Completion *completion, bool e)
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 (*setStop)(struct OpenAI_Completion *completion, const char *s)
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 (*setPresencePenalty)(struct OpenAI_Completion *completion, float pp)
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 (*setFrequencyPenalty)(struct OpenAI_Completion *completion, float fp)
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 (*setBestOf)(struct OpenAI_Completion *completion, uint32_t bo)
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 (*setUser)(struct OpenAI_Completion *completion, const char *u)
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
-
OpenAI_StringResponse_t *(*prompt)(struct OpenAI_Completion *completion, char *p)
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*
-
void (*setModel)(struct OpenAI_Completion *completion, const char *m)
-
struct OpenAI_ChatCompletion
Given a list of messages comprising a conversation, the model will return a response.
Public Members
-
void (*setModel)(struct OpenAI_ChatCompletion *chatCompletion, const char *m)
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 (*setSystem)(struct OpenAI_ChatCompletion *chatCompletion, const char *s)
Set the system to use for completion.
- Param chatCompletion[in]
the point of OpenAI_ChatCompletion
- Param s[in]
description of the required assistant
-
void (*setMaxTokens)(struct OpenAI_ChatCompletion *chatCompletion, uint32_t mt)
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 (*setTemperature)(struct OpenAI_ChatCompletion *chatCompletion, float t)
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 (*setTopP)(struct OpenAI_ChatCompletion *chatCompletion, float tp)
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 (*setStop)(struct OpenAI_ChatCompletion *chatCompletion, const char *s)
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 (*setPresencePenalty)(struct OpenAI_ChatCompletion *chatCompletion, float pp)
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 (*setFrequencyPenalty)(struct OpenAI_ChatCompletion *chatCompletion, float fp)
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 (*setUser)(struct OpenAI_ChatCompletion *chatCompletion, const char *u)
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 (*clearConversation)(struct OpenAI_ChatCompletion *chatCompletion)
Clears the accumulated conversation.
- Param chatCompletion[in]
the point of OpenAI_ChatCompletion
-
OpenAI_StringResponse_t *(*message)(struct OpenAI_ChatCompletion *chatCompletion, const char *p, bool save)
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*
-
void (*setModel)(struct OpenAI_ChatCompletion *chatCompletion, const char *m)
-
struct OpenAI_Edit
Given a prompt and an instruction, the model will return an edited version of the prompt.
Public Members
-
void (*setModel)(struct OpenAI_Edit *edit, const char *m)
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 (*setTemperature)(struct OpenAI_Edit *edit, float t)
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 (*setTopP)(struct OpenAI_Edit *edit, float tp)
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 (*setN)(struct OpenAI_Edit *edit, uint32_t n)
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
-
OpenAI_StringResponse_t *(*process)(struct OpenAI_Edit *edit, char *instruction, char *input)
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
-
void (*setModel)(struct OpenAI_Edit *edit, const char *m)
-
struct OpenAI_ImageGeneration
Creates an image given a prompt.
Public Members
-
void (*setSize)(struct OpenAI_ImageGeneration *imageGeneration, OpenAI_Image_Size s)
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 (*setResponseFormat)(struct OpenAI_ImageGeneration *imageGeneration, OpenAI_Image_Response_Format rf)
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 (*setN)(struct OpenAI_ImageGeneration *imageGeneration, uint32_t n)
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 (*setUser)(struct OpenAI_ImageGeneration *imageGeneration, const char *u)
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
-
OpenAI_ImageResponse_t *(*prompt)(struct OpenAI_ImageGeneration *imageGeneration, char *p)
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
-
void (*setSize)(struct OpenAI_ImageGeneration *imageGeneration, OpenAI_Image_Size s)
-
struct OpenAI_ImageVariation
Creates a variation of a given image.
Public Members
-
void (*setSize)(struct OpenAI_ImageVariation *imageVariation, OpenAI_Image_Size s)
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 (*setResponseFormat)(struct OpenAI_ImageVariation *imageVariation, OpenAI_Image_Response_Format rf)
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 (*setN)(struct OpenAI_ImageVariation *imageVariation, uint32_t n)
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 (*setUser)(struct OpenAI_ImageVariation *imageVariation, const char *u)
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
-
OpenAI_ImageResponse_t *(*image)(struct OpenAI_ImageVariation *imageVariation, uint8_t *data, size_t len)
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
-
void (*setSize)(struct OpenAI_ImageVariation *imageVariation, OpenAI_Image_Size s)
-
struct OpenAI_ImageEdit
Creates an edited or extended image given an original image and a prompt.
Public Members
-
void (*setPrompt)(struct OpenAI_ImageEdit *imageEdit, const char *p)
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 (*setSize)(struct OpenAI_ImageEdit *imageEdit, OpenAI_Image_Size s)
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 (*setResponseFormat)(struct OpenAI_ImageEdit *imageEdit, OpenAI_Image_Response_Format rf)
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 (*setN)(struct OpenAI_ImageEdit *imageEdit, uint32_t n)
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 (*setUser)(struct OpenAI_ImageEdit *imageEdit, const char *u)
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
-
OpenAI_ImageResponse_t *(*image)(struct OpenAI_ImageEdit *imageEdit, uint8_t *data, size_t len, uint8_t *mask_data, size_t mask_len)
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
-
void (*setPrompt)(struct OpenAI_ImageEdit *imageEdit, const char *p)
-
struct OpenAI_AudioTranscription
Transcribes audio into the input language.
Public Members
-
void (*setPrompt)(struct OpenAI_AudioTranscription *audioTranscription, const char *p)
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 (*setResponseFormat)(struct OpenAI_AudioTranscription *audioTranscription, OpenAI_Audio_Response_Format rf)
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 (*setTemperature)(struct OpenAI_AudioTranscription *audioTranscription, float t)
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 (*setLanguage)(struct OpenAI_AudioTranscription *audioTranscription, const char *l)
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.
-
char *(*file)(struct OpenAI_AudioTranscription *audioTranscription, uint8_t *data, size_t len, OpenAI_Audio_Input_Format f)
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.
-
void (*setPrompt)(struct OpenAI_AudioTranscription *audioTranscription, const char *p)
-
struct OpenAI_AudioSpeech
Given a list of messages comprising a conversation, the model will return a response.
Public Members
-
void (*setModel)(struct OpenAI_AudioSpeech *createSpeech, const char *m)
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 (*setVoice)(struct OpenAI_AudioSpeech *createSpeech, const char *m)
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 (*setSpeed)(struct OpenAI_AudioSpeech *createSpeech, float t)
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 (*setResponseFormat)(struct OpenAI_AudioSpeech *createSpeech, OpenAI_Audio_Output_Format rf)
Set the format of the output.
- Param createSpeech[in]
the point of OpenAI_SpeechResponse_t
- Param rf[in]
the format of the output audio
-
OpenAI_SpeechResponse_t *(*speech)(struct OpenAI_AudioSpeech *createSpeech, char *p)
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
*
-
void (*setModel)(struct OpenAI_AudioSpeech *createSpeech, const char *m)
-
struct OpenAI_AudioTranslation
Translates audio into English.
Public Members
-
void (*setPrompt)(struct OpenAI_AudioTranslation *audioTranslation, const char *p)
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 (*setResponseFormat)(struct OpenAI_AudioTranslation *audioTranslation, OpenAI_Audio_Response_Format rf)
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 (*setTemperature)(struct OpenAI_AudioTranslation *audioTranslation, float t)
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.
-
char *(*file)(struct OpenAI_AudioTranslation *audioTranslation, uint8_t *data, size_t len, OpenAI_Audio_Input_Format f)
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.
-
void (*setPrompt)(struct OpenAI_AudioTranslation *audioTranslation, const char *p)
-
struct OpenAI
The entry point for calling the Openai api.
Type Definitions
-
typedef struct OpenAI_EmbeddingResponse OpenAI_EmbeddingResponse_t
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_ModerationResponse OpenAI_ModerationResponse_t
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_ImageResponse OpenAI_ImageResponse_t
Save the image which is generated by OpenAI.
-
typedef struct OpenAI_StringResponse OpenAI_StringResponse_t
Parse the returned json data into OpenAI_StringResponse_t.
-
typedef struct OpenAI_SpeechResponse OpenAI_SpeechResponse_t
Store the returned data into a OpenAI_SpeechResponse_t structure.
-
typedef struct OpenAI_Completion OpenAI_Completion_t
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_ChatCompletion OpenAI_ChatCompletion_t
Given a list of messages comprising a conversation, the model will return a response.
-
typedef struct OpenAI_Edit OpenAI_Edit_t
Given a prompt and an instruction, the model will return an edited version of the prompt.
-
typedef struct OpenAI_ImageGeneration OpenAI_ImageGeneration_t
Creates an image given a prompt.
-
typedef struct OpenAI_ImageVariation OpenAI_ImageVariation_t
Creates a variation of a given image.
-
typedef struct OpenAI_ImageEdit OpenAI_ImageEdit_t
Creates an edited or extended image given an original image and a prompt.
-
typedef struct OpenAI_AudioTranscription OpenAI_AudioTranscription_t
Transcribes audio into the input language.
-
typedef struct OpenAI_AudioSpeech OpenAI_AudioSpeech_t
Given a list of messages comprising a conversation, the model will return a response.
-
typedef struct OpenAI_AudioTranslation OpenAI_AudioTranslation_t
Translates audio into English.
Enumerations
-
enum OpenAI_Image_Size
Values:
-
enumerator OPENAI_IMAGE_SIZE_1024x1024
-
enumerator OPENAI_IMAGE_SIZE_512x512
-
enumerator OPENAI_IMAGE_SIZE_256x256
-
enumerator OPENAI_IMAGE_SIZE_1024x1024
-
enum OpenAI_Image_Response_Format
Values:
-
enumerator OPENAI_IMAGE_RESPONSE_FORMAT_URL
-
enumerator OPENAI_IMAGE_RESPONSE_FORMAT_B64_JSON
-
enumerator OPENAI_IMAGE_RESPONSE_FORMAT_URL
-
enum OpenAI_Audio_Response_Format
Values:
-
enumerator OPENAI_AUDIO_RESPONSE_FORMAT_JSON
-
enumerator OPENAI_AUDIO_RESPONSE_FORMAT_TEXT
-
enumerator OPENAI_AUDIO_RESPONSE_FORMAT_SRT
-
enumerator OPENAI_AUDIO_RESPONSE_FORMAT_VERBOSE_JSON
-
enumerator OPENAI_AUDIO_RESPONSE_FORMAT_VTT
-
enumerator OPENAI_AUDIO_RESPONSE_FORMAT_JSON
-
enum OpenAI_Audio_Input_Format
Values:
-
enumerator OPENAI_AUDIO_INPUT_FORMAT_MP3
-
enumerator OPENAI_AUDIO_INPUT_FORMAT_MP4
-
enumerator OPENAI_AUDIO_INPUT_FORMAT_MPEG
-
enumerator OPENAI_AUDIO_INPUT_FORMAT_MPGA
-
enumerator OPENAI_AUDIO_INPUT_FORMAT_M4A
-
enumerator OPENAI_AUDIO_INPUT_FORMAT_WAV
-
enumerator OPENAI_AUDIO_INPUT_FORMAT_WEBM
-
enumerator OPENAI_AUDIO_INPUT_FORMAT_MP3