Refactor ConversationChainComponent class to handle different types of result objects

This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-02-22 18:41:18 -03:00
commit 176f6b1640

View file

@ -35,13 +35,10 @@ class ConversationChainComponent(CustomComponent):
# result is an AIMessage which is a subclass of BaseMessage
# We need to check if it is a string or a BaseMessage
if hasattr(result, "content") and isinstance(result.content, str):
self.status = "is message"
result = result.content
elif isinstance(result, str):
self.status = "is_string"
result = result
else:
# is dict
result = result.get("response")
self.status = result
return result