shithub: oai

ref: 1c65e9795d3a51c26a87296d53b0ebe9efdc7719
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,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 {
	OPrompt *prompts;
	OTool *tools;
};

struct OResult {
	int success;
	char *role;
	char *message;
	int tokscompletion;
	int toksprompt;
	int tokstotal;
	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, $oaikey and $oaimodel.
 */
int initoai(char *baseurl, char *apikey, char *model);

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