-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
31 lines (26 loc) · 873 Bytes
/
utils.py
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
import json
import inspect
def save_as_json(raw_data, file_name):
with open(file_name, "w") as f:
json.dump(raw_data, f, indent=4, ensure_ascii=False)
def load_json(file_name) -> dict:
with open(file_name, "r") as f:
return json.load(f)
def generate_schema(function):
signature = inspect.signature(function)
params = signature.parameters
properties = {}
required = []
for name, param in params.items():
param_info = {"type": "string"} # Assuming all parameters are strings, adjust as needed
if param.default != inspect.Parameter.empty:
param_info["enum"] = [param.default]
else:
required.append(name)
properties[name] = param_info
schema = {
"type": "object",
"properties": properties,
"required": required,
}
return schema