🐛 fix(loading.py): convert "max_tokens" parameter from string to int if it is a string and can be converted to int

🐛 fix(loading.py): remove "max_tokens" parameter if it is not an integer
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-07-08 13:59:46 -03:00
commit 7e712b1be8

View file

@ -120,6 +120,15 @@ def instantiate_llm(node_type, class_object, params: Dict):
# False if condition is True
if node_type == "VertexAI":
return initialize_vertexai(class_object=class_object, params=params)
# max_tokens sometimes is a string and should be an int
if (
"max_tokens" in params
and isinstance(params["max_tokens"], str)
and params["max_tokens"].isdigit()
):
params["max_tokens"] = int(params["max_tokens"])
elif not isinstance(params["max_tokens"], int):
params.pop("max_tokens", None)
return class_object(**params)