fix: added conditions to check for attributes

This commit is contained in:
Gabriel Almeida 2023-04-05 11:38:03 -03:00
commit 808e702b30

View file

@ -115,12 +115,10 @@ def fix_memory_inputs(langchain_object):
object's input variables. If so, it does nothing. Otherwise, it gets a possible new memory key using the object's input variables. If so, it does nothing. Otherwise, it gets a possible new memory key using the
get_memory_key function and updates the memory keys using the update_memory_keys function. get_memory_key function and updates the memory keys using the update_memory_keys function.
""" """
if ( if hasattr(langchain_object, "memory") and langchain_object.memory is not None:
hasattr(langchain_object, "memory") if langchain_object.memory.memory_key in langchain_object.input_variables:
and langchain_object.memory is not None
and langchain_object.memory.memory_key in langchain_object.input_variables
):
return return
possible_new_mem_key = get_memory_key(langchain_object) possible_new_mem_key = get_memory_key(langchain_object)
if possible_new_mem_key is not None: if possible_new_mem_key is not None:
update_memory_keys(langchain_object, possible_new_mem_key) update_memory_keys(langchain_object, possible_new_mem_key)