Update.
This commit is contained in:
parent
71606a6c22
commit
276a6d0dbf
1
main.c
1
main.c
@ -200,6 +200,7 @@ void repl() {
|
|||||||
// previous_line = line;
|
// previous_line = line;
|
||||||
if(!strncmp(line,"dump",4)){
|
if(!strncmp(line,"dump",4)){
|
||||||
printf("%s\n",message_json());
|
printf("%s\n",message_json());
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
if (!strncmp(line, "exit", 4)) {
|
if (!strncmp(line, "exit", 4)) {
|
||||||
exit(0);
|
exit(0);
|
||||||
|
@ -57,6 +57,11 @@ struct json_object *message_add_tool_result(const char *tool_call_id, const char
|
|||||||
return message;
|
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 *message_add(const char *role, const char *content) {
|
||||||
struct json_object *messages = message_list();
|
struct json_object *messages = message_list();
|
||||||
struct json_object *message = json_object_new_object();
|
struct json_object *message = json_object_new_object();
|
||||||
|
3
openai.h
3
openai.h
@ -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";
|
const char* api_url = "https://api.openai.com/v1/chat/completions";
|
||||||
char* json_data = chat_json(user_role, message_content);
|
char* json_data = chat_json(user_role, message_content);
|
||||||
struct json_object* message_object = openai_process_chat_message(api_url, json_data);
|
struct json_object* message_object = openai_process_chat_message(api_url, json_data);
|
||||||
|
message_add_object(message_object);
|
||||||
if (message_object == NULL) {
|
if (message_object == NULL) {
|
||||||
printf("ERROR + NULL IS SUCCESS\n");
|
printf("ERROR + NULL IS SUCCESS\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -102,7 +103,7 @@ char* openai_chat(const char* user_role, const char* message_content) {
|
|||||||
struct json_object* tool_calls;
|
struct json_object* tool_calls;
|
||||||
json_object_object_get_ex(message_object, "tool_calls", &tool_calls);
|
json_object_object_get_ex(message_object, "tool_calls", &tool_calls);
|
||||||
if (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);
|
struct json_object* tool_call_results = tools_execute(tool_calls);
|
||||||
int results_count = json_object_array_length(tool_call_results);
|
int results_count = json_object_array_length(tool_call_results);
|
||||||
for (int i = 0; i < results_count; i++) {
|
for (int i = 0; i < results_count; i++) {
|
||||||
|
Loading…
Reference in New Issue
Block a user