ref: 07f47299051fec1a83d14bb024dfab182b4fc18f
dir: /oai.h/
typedef struct OResult OResult;
typedef struct ORequest ORequest;
typedef struct OPrompt OPrompt;
typedef struct OTool OTool;
typedef struct OToolcall OToolcall;
typedef char* (*OToolcallfn)(OToolcall,void*);
typedef enum {
Function,
Custom,
} Tooltype;
extern int oaidebug;
struct OPrompt {
char *role;
char *content;
char *jcname;
JSON *jcontent;
char *callid;
OPrompt *next;
};
struct ORequest {
char *model;
OPrompt *prompts;
OTool *tools;
};
struct OResult {
int success;
char *role;
char *message;
OPrompt *asprompt;
};
struct OTool {
Tooltype type;
char *name;
char *description;
JSON *parameters;
OToolcallfn func;
void *aux;
OTool *next;
};
struct OToolcall {
Tooltype type;
char *name;
char *arguments;
char *id;
OToolcall *next;
};
/*
* initoai returns 1 on success. If baseurl or apikey is nil, it'll try to fetch the data
* from the environment variables $oaiurl and $oaikey. Key is optional.
*/
int initoai(char *baseurl, char *apikey);
/*
* makerequest to make the request.
*/
OResult makerequest(ORequest*);
/*
* create a new prompt object.
*/
OPrompt* makeprompt(char *role);
/*
* append a prompt to the existing request. You can set the role and the content.
* The content is built from the fmt and the variadic arguments.
*/
int addstrprompt(ORequest*, char *role, char *fmt, ...);
int addprompt(ORequest*, OPrompt*);
/*
* append various contents to prompt.
*/
int addtextmessage(OPrompt*, char *text);
int addfilemessage(OPrompt*, uchar *data, long ndata, char *filename, char *fileid);
/*
* append tool
*/
OTool* maketool(OTool*, Tooltype, char *name, char *description, char *parameters, char* (*f)(OToolcall, void*), void*);