OpenAI API
The OpenAI library supports access to the OpenAI cloud-based LLM.
It provides the ability to create on-device LLM prompts and send to powerful cloud-based LLMs.
Function Index
Json * | openaiChatCompletion(Json *props) |
Submit a request to OpenAI Chat Completion API. | |
int | openaiInit(cchar *endpoint, cchar *key, Json *config, int flags) |
Initialize the OpenAI API. | |
Url * | openaiRealTimeConnect(Json *props) |
Submit a request to OpenAI Real Time API. | |
Json * | openaiResponses(Json *props, OpenAIAgent agent, void *arg) |
Submit a request to OpenAI Responses API. | |
Url * | openaiStream(Json *props, UrlSseProc callback, void *arg) |
Submit a request to OpenAI Response API and stream the response. | |
void | openaiTerm(void) |
Terminate the OpenAI API. |
Typedef Index
OpenAIAgent | OpenAI Agent callback function. |
Defines
#define | AI_SHOW_NONE 0x1 |
Trace nothing. | |
#define | AI_SHOW_REQ 0x2 |
Trace request. | |
#define | AI_SHOW_RESP 0x8 |
Trace response. |
Typedefs
typedef char *(* OpenAIAgent) (cchar *name, Json *request, Json *response, void *arg)
OpenAI Agent callback function.
- Parameters:
name is the name of the agent. request is the request JSON object. response is the response JSON object. arg is a user argument.
- Returns:
- Allocated text to be added to the response from the agent/tool.
Functions
Submit a request to OpenAI Chat Completion API.
- Description:
- The following defaults are set: model: gpt-4o-mini.
- Parameters:
props is a JSON object of Response API parameters.
- Returns:
- Returns a JSON object with the response from the OpenAI Response API. Caller must free the returned JSON object with jsonFree.
- API Stability:
- Evolving.
Initialize the OpenAI API.
- Parameters:
endpoint is the OpenAI endpoint. key is the OpenAI key. config is a JSON object of configuration parameters. flags is a bitmask of flags.
- API Stability:
- Internal.
Submit a request to OpenAI Real Time API.
- Parameters:
props is a JSON object of Real Time API parameters.
- Returns:
- Returns an OpenAIRealTime object on success, or 0 on failure.
- API Stability:
- Evolving.
Submit a request to OpenAI Responses API.
- Description:
- The following defaults are set: {model: 'gpt-4o-mini', truncation: 'auto'}. The API will aggregate the output text into "output_text" for convenience.
- Parameters:
props is a JSON object of Response API parameters. agent is a callback function that will be called for each chunk of the response. arg is a user argument that will be passed to the callback function.
- Returns:
- Returns a JSON object with the response from the OpenAI Response API. Caller must free the returned JSON object with jsonFree.
- API Stability:
- Evolving.
Submit a request to OpenAI Response API and stream the response.
- Description:
- The following defaults are set: {model: 'gpt-4o-mini', truncation: 'auto'}. The API will aggregate the output text into "output_text" for convenience.
- Parameters:
props is a JSON object of Response API parameters. callback is a callback function that will be called for each chunk of the response. arg is a user argument that will be passed to the callback function.
- Returns:
- Returns an Url object on success, or 0 on failure.
- API Stability:
- Evolving.
void openaiTerm (void )
Terminate the OpenAI API.
- API Stability:
- Internal.