Adjust read_dir description and return value
This commit is contained in:
parent
1fc0af56df
commit
59487d5721
@ -43,16 +43,16 @@ var AvailableTools = map[string]AvailableTool{
|
||||
|
||||
Results are returned as JSON in the following format:
|
||||
{
|
||||
"message": "success", // "success" if successful, or a different message indicating failure
|
||||
"message": "success", // if successful, or a different message indicating failure
|
||||
"result": [
|
||||
{"name": "a_file", "type": "file", "length": 123},
|
||||
{"name": "a_directory", "type": "dir", "length": 5},
|
||||
{"name": "a_file", "type": "file", "size": 123},
|
||||
{"name": "a_directory/", "type": "dir", "size": 11},
|
||||
... // more files or directories
|
||||
]
|
||||
}
|
||||
|
||||
For type: file, length represents the size (in bytes) of the file.
|
||||
For type: dir, length represents the number of entries in that directory.`,
|
||||
For files, size represents the size (in bytes) of the file.
|
||||
For directories, size represents the number of entries in that directory.`,
|
||||
Parameters: FunctionParameters{
|
||||
Type: "object",
|
||||
Properties: map[string]FunctionParameter{
|
||||
@ -205,19 +205,21 @@ func ReadDir(path string) string {
|
||||
for _, f := range files {
|
||||
info, _ := f.Info()
|
||||
|
||||
contentType := "file"
|
||||
length := info.Size()
|
||||
name := f.Name()
|
||||
entryType := "file"
|
||||
size := info.Size()
|
||||
|
||||
if info.IsDir() {
|
||||
contentType = "dir"
|
||||
name += "/"
|
||||
entryType = "dir"
|
||||
subdirfiles, _ := os.ReadDir(filepath.Join(".", path, info.Name()))
|
||||
length = int64(len(subdirfiles))
|
||||
size = int64(len(subdirfiles))
|
||||
}
|
||||
|
||||
dirContents = append(dirContents, map[string]interface{}{
|
||||
"name": f.Name(),
|
||||
"type": contentType,
|
||||
"length": length,
|
||||
"name": name,
|
||||
"type": entryType,
|
||||
"size": size,
|
||||
})
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user