- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcall_function.py
More file actions
Latest commit
54 lines (45 loc) · 1.73 KB
/
Copy pathcall_function.py
File metadata and controls
54 lines (45 loc) · 1.73 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
51
52
53
54
#list of functions ai agent can call
fromfunctions.get_files_infoimportschema_get_files_info, get_files_info
fromfunctions.get_file_contentimportschema_get_file_content, get_file_content
fromfunctions.write_fileimportschema_write_file, write_file
fromfunctions.run_python_fileimportschema_run_python_file, run_python_file
fromgoogleimportgenai
fromgoogle.genaiimporttypes
fromconfigimportworking_directory
available_functions=types.Tool(
function_declarations=[schema_get_files_info, schema_get_file_content, schema_write_file, schema_run_python_file],
)
defcall_function(function_call, verbose=False):
ifverbose:
print(f"Calling function: {function_call.name}({function_call.args})")
else:
print(f" - Calling function: {function_call.name}")
function_map= {
"get_files_info": get_files_info,
"get_file_content": get_file_content,
"write_file": write_file,
"run_python_file": run_python_file
}
function_name=function_call.nameor""
iffunction_namenotinfunction_map:
returntypes.Content(
role="tool",
parts=[
types.Part.from_function_response(
name=function_name,
response={"error": f"Unknown function: {function_name}"}
)
],
)
args=dict(function_call.args) iffunction_call.argselse {}
args["working_directory"] =working_directory
function_result=function_map[function_name](**args)
returntypes.Content(
role="tool",
parts=[
types.Part.from_function_response(
name=function_name,
response={"result": function_result}
)
]
)