Added mkdir using vibe tool.
This commit is contained in:
parent
57384d9ba6
commit
619b231e8d
64
tools.h
64
tools.h
@ -48,6 +48,7 @@ struct json_object *tool_description_db_query();
|
|||||||
struct json_object *tool_description_db_get();
|
struct json_object *tool_description_db_get();
|
||||||
struct json_object *tool_description_web_search_news();
|
struct json_object *tool_description_web_search_news();
|
||||||
struct json_object *tool_description_web_search();
|
struct json_object *tool_description_web_search();
|
||||||
|
struct json_object *tool_description_mkdir();
|
||||||
|
|
||||||
struct json_object *tools_descriptions() {
|
struct json_object *tools_descriptions() {
|
||||||
struct json_object *root = json_object_new_array();
|
struct json_object *root = json_object_new_array();
|
||||||
@ -66,6 +67,7 @@ struct json_object *tools_descriptions() {
|
|||||||
json_object_array_add(root, tool_description_db_get());
|
json_object_array_add(root, tool_description_db_get());
|
||||||
json_object_array_add(root, tool_description_web_search_news());
|
json_object_array_add(root, tool_description_web_search_news());
|
||||||
json_object_array_add(root, tool_description_web_search());
|
json_object_array_add(root, tool_description_web_search());
|
||||||
|
json_object_array_add(root, tool_description_mkdir());
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1042,6 +1044,52 @@ struct json_object *tool_description_linux_terminal() {
|
|||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *tool_function_mkdir(char *path) {
|
||||||
|
if (mkdir(path, 0777) != 0) {
|
||||||
|
perror("mkdir failed");
|
||||||
|
return strdup("Failed to create directory!");
|
||||||
|
}
|
||||||
|
return strdup("Directory successfully created.");
|
||||||
|
}
|
||||||
|
|
||||||
|
struct json_object *tool_description_mkdir() {
|
||||||
|
struct json_object *root = json_object_new_object();
|
||||||
|
json_object_object_add(root, "type", json_object_new_string("function"));
|
||||||
|
|
||||||
|
struct json_object *function = json_object_new_object();
|
||||||
|
json_object_object_add(function, "name", json_object_new_string("mkdir"));
|
||||||
|
json_object_object_add(
|
||||||
|
function, "description",
|
||||||
|
json_object_new_string("Creates a new directory with the specified path."));
|
||||||
|
|
||||||
|
struct json_object *parameters = json_object_new_object();
|
||||||
|
json_object_object_add(parameters, "type", json_object_new_string("object"));
|
||||||
|
|
||||||
|
struct json_object *properties = json_object_new_object();
|
||||||
|
struct json_object *path = json_object_new_object();
|
||||||
|
json_object_object_add(path, "type", json_object_new_string("string"));
|
||||||
|
json_object_object_add(
|
||||||
|
path, "description",
|
||||||
|
json_object_new_string("Path of the directory to create."));
|
||||||
|
json_object_object_add(properties, "path", path);
|
||||||
|
|
||||||
|
json_object_object_add(parameters, "properties", properties);
|
||||||
|
|
||||||
|
struct json_object *required = json_object_new_array();
|
||||||
|
json_object_array_add(required, json_object_new_string("path"));
|
||||||
|
json_object_object_add(parameters, "required", required);
|
||||||
|
|
||||||
|
json_object_object_add(parameters, "additionalProperties",
|
||||||
|
json_object_new_boolean(0));
|
||||||
|
|
||||||
|
json_object_object_add(function, "parameters", parameters);
|
||||||
|
json_object_object_add(function, "strict", json_object_new_boolean(1));
|
||||||
|
|
||||||
|
json_object_object_add(root, "function", function);
|
||||||
|
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
struct json_object *tools_execute(struct json_object *tools_array) {
|
struct json_object *tools_execute(struct json_object *tools_array) {
|
||||||
struct json_object *tools_result_messages = json_object_new_array();
|
struct json_object *tools_result_messages = json_object_new_array();
|
||||||
int array_len = json_object_array_length(tools_array);
|
int array_len = json_object_array_length(tools_array);
|
||||||
@ -1311,6 +1359,21 @@ struct json_object *tools_execute(struct json_object *tools_array) {
|
|||||||
free(listing_result);
|
free(listing_result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (!strcmp(function_name, "mkdir")) {
|
||||||
|
struct json_object *arguments_obj;
|
||||||
|
if (json_object_object_get_ex(function_obj, "arguments",
|
||||||
|
&arguments_obj)) {
|
||||||
|
struct json_object *arguments =
|
||||||
|
json_tokener_parse(json_object_get_string(arguments_obj));
|
||||||
|
struct json_object *path_obj;
|
||||||
|
if (json_object_object_get_ex(arguments, "path", &path_obj)) {
|
||||||
|
char *path = (char *)json_object_get_string(path_obj);
|
||||||
|
char *mkdir_result = tool_function_mkdir(path);
|
||||||
|
json_object_object_add(tool_result, "content",
|
||||||
|
json_object_new_string(mkdir_result));
|
||||||
|
free(mkdir_result);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Unknown function: %s\n", function_name);
|
fprintf(stderr, "Unknown function: %s\n", function_name);
|
||||||
json_object_object_add(
|
json_object_object_add(
|
||||||
@ -1325,4 +1388,3 @@ struct json_object *tools_execute(struct json_object *tools_array) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user