This commit is contained in:
retoor 2025-03-20 16:38:10 +01:00
parent 71606a6c22
commit 276a6d0dbf
3 changed files with 8 additions and 1 deletions

1
main.c
View File

@ -200,6 +200,7 @@ void repl() {
// previous_line = line;
if(!strncmp(line,"dump",4)){
printf("%s\n",message_json());
continue;
}
if (!strncmp(line, "exit", 4)) {
exit(0);

View File

@ -57,6 +57,11 @@ struct json_object *message_add_tool_result(const char *tool_call_id, const char
return message;
}
void message_add_object(json_object *message) {
struct json_object *messages = message_list();
json_object_array_add(messages, message);
}
struct json_object *message_add(const char *role, const char *content) {
struct json_object *messages = message_list();
struct json_object *message = json_object_new_object();

View File

@ -95,6 +95,7 @@ char* openai_chat(const char* user_role, const char* message_content) {
const char* api_url = "https://api.openai.com/v1/chat/completions";
char* json_data = chat_json(user_role, message_content);
struct json_object* message_object = openai_process_chat_message(api_url, json_data);
message_add_object(message_object);
if (message_object == NULL) {
printf("ERROR + NULL IS SUCCESS\n");
return NULL;
@ -102,7 +103,7 @@ char* openai_chat(const char* user_role, const char* message_content) {
struct json_object* tool_calls;
json_object_object_get_ex(message_object, "tool_calls", &tool_calls);
if (tool_calls) {
message_add_tool_call(message_object);
// message_add_tool_call(message_object);
struct json_object* tool_call_results = tools_execute(tool_calls);
int results_count = json_object_array_length(tool_call_results);
for (int i = 0; i < results_count; i++) {