🐛 fix(loading.py): convert retriever to retriever object if it has "as_retriever" method

The code now checks if the "retriever" key exists in the params dictionary and if the value has an "as_retriever" method. If it does, the value is replaced with the result of calling the "as_retriever" method. This change ensures that the "retriever" parameter is always an instance of the retriever object, preventing potential attribute errors later in the code.
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-07-01 09:42:44 -03:00
commit d39bea6e85

View file

@ -100,6 +100,8 @@ def instantiate_llm(node_type, class_object, params: Dict):
def instantiate_memory(node_type, class_object, params):
try:
if "retriever" in params and hasattr(params["retriever"], "as_retriever"):
params["retriever"] = params["retriever"].as_retriever()
return class_object(**params)
# I want to catch a specific attribute error that happens
# when the object does not have a cursor attribute