shithub: oai

ref: 1f68d6a68ba2b4512d963ea2815280cabe707f53
dir: /oai.h/

View raw version
typedef struct OResult OResult;
typedef struct ORequest ORequest;
typedef struct OPrompt OPrompt;
typedef struct OTool OTool;
typedef struct OToolcall OToolcall;

typedef char* (*OToolcallfn)(OToolcall);

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;
};

struct OTool {
	Tooltype type;
	char *name;
	char *description;
	char *parameters;
	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, char* (*f)(OToolcall));

/*
 * 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);