🐛 fix(loading.py): handle case when loading file into dict fails and raise ValueError with "Invalid file" message

 feat(loading.py): improve code readability by using walrus operator to assign loaded file dict to params["dict_"] variable
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-07-08 16:45:59 -03:00
commit 800f4b0a94

View file

@ -254,12 +254,14 @@ def instantiate_prompt(node_type, class_object, params: Dict):
def instantiate_tool(node_type, class_object: Type[BaseTool], params: Dict):
if node_type == "JsonSpec":
params["dict_"] = load_file_into_dict(params.pop("path"))
if file_dict := load_file_into_dict(params.pop("path")):
params["dict_"] = file_dict
else:
raise ValueError("Invalid file")
return class_object(**params)
elif node_type == "PythonFunctionTool":
params["func"] = get_function(params.get("code"))
return class_object(**params)
# For backward compatibility
elif node_type == "PythonFunction":
function_string = params["code"]
if isinstance(function_string, str):