|
|
|
@@ -88,6 +88,14 @@ class PromptMessage(ABC, BaseModel): |
|
|
|
content: Optional[str | list[PromptMessageContent]] = None |
|
|
|
name: Optional[str] = None |
|
|
|
|
|
|
|
def is_empty(self) -> bool: |
|
|
|
""" |
|
|
|
Check if prompt message is empty. |
|
|
|
|
|
|
|
:return: True if prompt message is empty, False otherwise |
|
|
|
""" |
|
|
|
return not self.content |
|
|
|
|
|
|
|
|
|
|
|
class UserPromptMessage(PromptMessage): |
|
|
|
""" |
|
|
|
@@ -118,6 +126,16 @@ class AssistantPromptMessage(PromptMessage): |
|
|
|
role: PromptMessageRole = PromptMessageRole.ASSISTANT |
|
|
|
tool_calls: list[ToolCall] = [] |
|
|
|
|
|
|
|
def is_empty(self) -> bool: |
|
|
|
""" |
|
|
|
Check if prompt message is empty. |
|
|
|
|
|
|
|
:return: True if prompt message is empty, False otherwise |
|
|
|
""" |
|
|
|
if not super().is_empty() and not self.tool_calls: |
|
|
|
return False |
|
|
|
|
|
|
|
return True |
|
|
|
|
|
|
|
class SystemPromptMessage(PromptMessage): |
|
|
|
""" |
|
|
|
@@ -132,3 +150,14 @@ class ToolPromptMessage(PromptMessage): |
|
|
|
""" |
|
|
|
role: PromptMessageRole = PromptMessageRole.TOOL |
|
|
|
tool_call_id: str |
|
|
|
|
|
|
|
def is_empty(self) -> bool: |
|
|
|
""" |
|
|
|
Check if prompt message is empty. |
|
|
|
|
|
|
|
:return: True if prompt message is empty, False otherwise |
|
|
|
""" |
|
|
|
if not super().is_empty() and not self.tool_call_id: |
|
|
|
return False |
|
|
|
|
|
|
|
return True |