🐛 fix(process.py): refactor fix_memory_inputs function to improve readability and reduce nesting

The fix_memory_inputs function was refactored to reduce nesting and improve readability. The function now checks if the langchain_object has a memory attribute and if it is not None before proceeding. The try-except block was also refactored to reduce nesting.
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-06-19 12:02:15 -03:00
commit 11185affdd

View file

@ -20,7 +20,8 @@ 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 hasattr(langchain_object, "memory") and langchain_object.memory is not None: if not hasattr(langchain_object, "memory") or langchain_object.memory is None:
return
try: try:
if langchain_object.memory.memory_key in langchain_object.input_variables: if langchain_object.memory.memory_key in langchain_object.input_variables:
return return