-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathsave_file.py
More file actions
50 lines (43 loc) · 1.8 KB
/
save_file.py
File metadata and controls
50 lines (43 loc) · 1.8 KB
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
"""
This module contains a class for saving a file to the output directory. The file's name and contents are provided as parameters.
"""
from agentflow.function import BaseFunction
class SaveFile(BaseFunction):
"""
This class inherits from the BaseFunction class. It defines a function for saving a file to the output directory.
"""
def get_definition(self) -> dict:
"""
Returns a dictionary that defines the function. It includes the function's name, description, and parameters.
:return: A dictionary that defines the function.
:rtype: dict
"""
return {
"name": "save_file",
"description": "Saves a file. Returns the path to the file.",
"parameters": {
"type": "object",
"properties": {
"file_name": {
"type": "string",
"description": "The name of the file, including its extension. For example, test.txt.",
},
"file_contents": {
"type": "string",
"description": "The contents of the file.",
},
},
"required": ["file_name", "file_contents"],
},
}
def execute(self, file_name: str, file_contents: str) -> str:
"""
Saves a file to the output directory. The file's name and contents are provided as parameters.
:param file_name: The name of the file, including its extension. For example, test.txt.
:type file_name: str
:param file_contents: The contents of the file.
:type file_contents: str
:return: The name of the saved file.
:rtype: str
"""
return self.output.save(file_name, file_contents)