From d646732b8316a97923bec748900e0a9ba877a1e1 Mon Sep 17 00:00:00 2001 From: mmikita95 Date: Fri, 8 Nov 2024 17:34:02 +0400 Subject: [PATCH 1/4] chore: serialize tool calls messages with non-empty content --- src/writer/ai.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/writer/ai.py b/src/writer/ai.py index bb260a9ad..bfae63964 100644 --- a/src/writer/ai.py +++ b/src/writer/ai.py @@ -1824,7 +1824,18 @@ def _is_serialized(self, message: 'Conversation.Message') -> bool: elif message.get("tool_call_id") is not None: return False tool_calls = message.get("tool_calls") - if tool_calls is not None and tool_calls != []: + if ( + ( + tool_calls is not None + and + tool_calls != [] + ) + and + not message.get("content") + ): + # If tool call request message + # doesn't have meaningful content, + # we don't serialize it return False return True From 2f96977eb1270ae4a9d1bf6c33abbcefb2bb71db Mon Sep 17 00:00:00 2001 From: mmikita95 Date: Mon, 18 Nov 2024 10:51:13 +0300 Subject: [PATCH 2/4] chore: update `_is_serialized` --- src/writer/ai.py | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/writer/ai.py b/src/writer/ai.py index bfae63964..20a82d0a4 100644 --- a/src/writer/ai.py +++ b/src/writer/ai.py @@ -1820,22 +1820,12 @@ def _is_serialized(self, message: 'Conversation.Message') -> bool: :return: Boolean that indicates """ if message["role"] in ["system", "tool"]: + # Prevent serialization of messages + # not intended for user display return False - elif message.get("tool_call_id") is not None: - return False - tool_calls = message.get("tool_calls") - if ( - ( - tool_calls is not None - and - tool_calls != [] - ) - and - not message.get("content") - ): - # If tool call request message - # doesn't have meaningful content, - # we don't serialize it + elif message.get("content") is None: + # Prevent serialization for messages + # without meaningful content return False return True From bb3683a25c1063482990705a6a6c536bc0a897d3 Mon Sep 17 00:00:00 2001 From: Mikita Makiej <157150795+mmikita95@users.noreply.github.com> Date: Mon, 18 Nov 2024 11:46:52 +0300 Subject: [PATCH 3/4] fix: unfinished docstring --- src/writer/ai.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/writer/ai.py b/src/writer/ai.py index 20a82d0a4..23192adb6 100644 --- a/src/writer/ai.py +++ b/src/writer/ai.py @@ -1817,7 +1817,8 @@ def _is_serialized(self, message: 'Conversation.Message') -> bool: """ Function to verify whether the message should be serializable. - :return: Boolean that indicates + :return: Boolean indicating if the message meets + the criteria for serialization. """ if message["role"] in ["system", "tool"]: # Prevent serialization of messages From 93a4f6ed024fae073f043e3be7f82cf10956352d Mon Sep 17 00:00:00 2001 From: Mikita Makiej <157150795+mmikita95@users.noreply.github.com> Date: Mon, 18 Nov 2024 12:47:27 +0300 Subject: [PATCH 4/4] fix: also include empty non-`None` content as failing condition --- src/writer/ai.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/writer/ai.py b/src/writer/ai.py index 23192adb6..0e3c6a44c 100644 --- a/src/writer/ai.py +++ b/src/writer/ai.py @@ -1824,7 +1824,7 @@ def _is_serialized(self, message: 'Conversation.Message') -> bool: # Prevent serialization of messages # not intended for user display return False - elif message.get("content") is None: + elif not message.get("content"): # Prevent serialization for messages # without meaningful content return False