2025-01-04 05:00:03 +00:00
|
|
|
#ifndef CALPACA_MESSAGES_H
|
|
|
|
#define CALPACA_MESSAGES_H
|
|
|
|
#include "json-c/json.h"
|
|
|
|
struct json_object *_message_array = NULL;
|
|
|
|
|
|
|
|
struct json_object *message_list(){
|
|
|
|
if(_message_array == NULL){
|
|
|
|
_message_array = json_object_new_array();
|
|
|
|
}
|
|
|
|
return _message_array;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct json_object *message_add(char * role, char * content){
|
|
|
|
struct json_object *messages = message_list();
|
|
|
|
struct json_object *message = json_object_new_object();
|
|
|
|
json_object_object_add(message, "role", json_object_new_string(role));
|
|
|
|
json_object_object_add(message, "content", json_object_new_string(content));
|
|
|
|
json_object_array_add(messages, message);
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
|
|
|
|
char * message_json(){
|
|
|
|
return (char *)json_object_to_json_string_ext(message_list(), JSON_C_TO_STRING_PRETTY);
|
|
|
|
}
|
|
|
|
|
|
|
|
void message_free(){
|
|
|
|
if(_message_array != NULL){
|
|
|
|
json_object_put(_message_array);
|
|
|
|
_message_array = NULL;
|
|
|
|
}
|
|
|
|
}
|
2025-01-04 07:35:39 +00:00
|
|
|
#endif
|