1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# tools.py
import json
from vfs import VFS
def list_files(path="."):
"""
List all files in a given path.
:param path: The path to list files from.
:return: A list of files in the path.
"""
return VFS.get_instance().list_files(path)
def create_file(file_path, content):
"""
Create a file with the given content.
:param file_path: The path to the file to create.
:param content: The content to write to the file.
"""
return VFS.get_instance().create_file(file_path, content)
def read_file(file_path):
"""
Read the content of a file.
:param file_path: The path to the file to read.
:return: The content of the file.
"""
return VFS.get_instance().read_file(file_path)
def delete_file(file_path):
"""
Delete a file.
:param file_path: The path to the file to delete.
"""
return VFS.get_instance().delete_file(file_path)
def make_tools_for_vfs(vfs_instance):
"""Create tool functions bound to a specific VFS instance.
Used for parallel execution where each worker has its own VFS.
Returns a dict of {name: function} matching available_functions format.
"""
def _list_files(path="."):
return vfs_instance.list_files(path)
def _create_file(file_path, content):
return vfs_instance.create_file(file_path, content)
def _read_file(file_path):
return vfs_instance.read_file(file_path)
def _delete_file(file_path):
return vfs_instance.delete_file(file_path)
return {
"list_files": _list_files,
"create_file": _create_file,
"read_file": _read_file,
"delete_file": _delete_file,
}
tools = [
{
"type": "function",
"function": {
"name": "list_files",
"description": "List all files in a given path.",
"parameters": {
"type": "object",
"properties": {
"path": {"type": "string", "description": "The path to list files from."},
},
"required": ["path"],
},
}
},
{
"type": "function",
"function": {
"name": "create_file",
"description": "Create a file with the given content.",
"parameters": {
"type": "object",
"properties": {
"file_path": {"type": "string", "description": "The path to the file to create."},
"content": {"type": "string", "description": "The content to write to the file."},
},
"required": ["file_path", "content"],
},
}
},
{
"type": "function",
"function": {
"name": "read_file",
"description": "Read the content of a file.",
"parameters": {
"type": "object",
"properties": {
"file_path": {"type": "string", "description": "The path to the file to read."},
},
"required": ["file_path"],
},
}
},
{
"type": "function",
"function": {
"name": "delete_file",
"description": "Delete a file.",
"parameters": {
"type": "object",
"properties": {
"file_path": {"type": "string", "description": "The path to the file to delete."},
},
"required": ["file_path"],
},
}
}
]
available_functions = {
"list_files": list_files,
"create_file": create_file,
"read_file": read_file,
"delete_file": delete_file,
}
|