Refactor code to extract class name from custom code
- Updatethe `get_function_custom` function to use the `validate.extract_class_name` function to extract class name from the `code` parameter. - Modify `instantiate_tool` function to update the `class_object` with the return value of `get_function_custom` and call the `build` method on the instantiated object with the remaining params. - Add a new function `extract_class_name` in the `validate` module to extract class name from the `code` parameter.
This commit is contained in:
parent
ac569f3405
commit
839e9737cc
5 changed files with 16 additions and 24 deletions
|
|
@ -178,8 +178,8 @@ def instantiate_tool(node_type, class_object, params):
|
|||
params["func"] = get_function(params.get("code"))
|
||||
return class_object(**params)
|
||||
elif node_type == "CustomComponent":
|
||||
params["func"] = get_function_custom(params.get("code"))
|
||||
return class_object(**params)
|
||||
class_object = get_function_custom(params.pop("code"))
|
||||
return class_object().build(**params)
|
||||
# For backward compatibility
|
||||
elif node_type == "PythonFunction":
|
||||
function_string = params["code"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue