refactor(loading.py): remove unused imports and add validation for class_object parameters that are not in __fields__ attribute.
This commit is contained in:
parent
7ba827e9fc
commit
96ef8fd657
1 changed files with 11 additions and 1 deletions
|
|
@ -25,6 +25,7 @@ from langflow.interface.toolkits.base import toolkits_creator
|
||||||
from langflow.interface.types import get_type_list
|
from langflow.interface.types import get_type_list
|
||||||
from langflow.interface.utils import load_file_into_dict
|
from langflow.interface.utils import load_file_into_dict
|
||||||
from langflow.utils import util, validate
|
from langflow.utils import util, validate
|
||||||
|
from pydantic import ValidationError
|
||||||
|
|
||||||
|
|
||||||
def instantiate_class(node_type: str, base_type: str, params: Dict) -> Any:
|
def instantiate_class(node_type: str, base_type: str, params: Dict) -> Any:
|
||||||
|
|
@ -74,7 +75,16 @@ def instantiate_class(node_type: str, base_type: str, params: Dict) -> Any:
|
||||||
elif base_type == "embeddings":
|
elif base_type == "embeddings":
|
||||||
# ? Why remove model from params?
|
# ? Why remove model from params?
|
||||||
params.pop("model")
|
params.pop("model")
|
||||||
return class_object(**params)
|
# remove all params that are not in class_object.__fields__
|
||||||
|
try:
|
||||||
|
return class_object(**params)
|
||||||
|
except ValidationError:
|
||||||
|
params = {
|
||||||
|
key: value
|
||||||
|
for key, value in params.items()
|
||||||
|
if key in class_object.__fields__
|
||||||
|
}
|
||||||
|
return class_object(**params)
|
||||||
elif base_type == "vectorstores":
|
elif base_type == "vectorstores":
|
||||||
if len(params.get("documents", [])) == 0:
|
if len(params.get("documents", [])) == 0:
|
||||||
# Error when the pdf or other source was not correctly
|
# Error when the pdf or other source was not correctly
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue