Skip to content

Chat

Waldiez chat model.

WaldiezChat

Bases: WaldiezBase

Chat class.

Attributes:

NameTypeDescription
idstr

The chat ID.

dataWaldiezChatData

The chat data. See waldiez.models.chat.WaldiezChatData for more information.

namestr

The chat name.

sourcestr

The chat source.

targetstr

The chat target.

nested_chatWaldiezChatNested

The nested chat message/reply if any.

messageWaldiezChatMessage

The chat message.

message_contentOptional[str]

The chat message content if any. If method, the method's body.

Methods:

NameDescription
get_chat_args

Get the chat arguments to use in autogen.

after_work: Optional[WaldiezSwarmAfterWork] property

Get the after work.

chat_id: int property

Get the chat ID.

context_variables: Dict[str, Any] property

Get the context variables.

description: str property

Get the description.

get_chat_args(for_queue: bool, sender: Optional[WaldiezAgent] = None) -> Dict[str, Any]

Get the chat arguments to use in autogen.

Parameters:

NameTypeDescriptionDefault
for_queuebool

Whether to get the chat arguments for a chat queue.

required
senderWaldiezAgent

The sender agent, to check if it's a RAG user.

None

Returns:

TypeDescription
dict

The chat arguments.

Source code in waldiez/models/chat/chat.py
def get_chat_args(
    self,
    for_queue: bool,
    sender: Optional[WaldiezAgent] = None,
) -> Dict[str, Any]:
    """Get the chat arguments to use in autogen.

    Parameters
    ----------
    for_queue : bool
        Whether to get the chat arguments for a chat queue.
    sender : WaldiezAgent, optional
        The sender agent, to check if it's a RAG user.
    Returns
    -------
    dict
        The chat arguments.
    """
    args_dict = self.data.get_chat_args(for_queue)
    if (
        isinstance(sender, WaldiezRagUser)
        and sender.agent_type == "rag_user"
        and self.message.type == "rag_message_generator"
    ):
        # check for n_results in agent data, to add in context
        n_results = sender.data.retrieve_config.n_results
        if isinstance(n_results, int) and n_results > 0:
            args_dict["n_results"] = n_results
    return args_dict

get_message_function(name_prefix: Optional[str] = None, name_suffix: Optional[str] = None, is_rag: bool = False) -> Tuple[str, str]

Get the message function.

Parameters:

NameTypeDescriptionDefault
name_prefixstr

The function name prefix.

None
name_suffixstr

The function name suffix.

None
is_ragbool

If the message is from a RAG user.

False

Returns:

TypeDescription
Tuple[str, str]

The message function and the function name.

Source code in waldiez/models/chat/chat.py
def get_message_function(
    self,
    name_prefix: Optional[str] = None,
    name_suffix: Optional[str] = None,
    is_rag: bool = False,
) -> Tuple[str, str]:
    """Get the message function.

    Parameters
    ----------
    name_prefix : str
        The function name prefix.
    name_suffix : str
        The function name suffix.
    is_rag : bool
        If the message is from a RAG user.

    Returns
    -------
    Tuple[str, str]
        The message function and the function name.
    """
    if self.message.type in ("string", "none") or (
        not self.message_content and is_rag is False
    ):
        return "", ""
    function_types = CALLABLE_MESSAGE_TYPES
    function_name = CALLABLE_MESSAGE
    if name_prefix:
        function_name = f"{name_prefix}_{function_name}"
    if name_suffix:
        function_name = f"{function_name}_{name_suffix}"
    if is_rag and self.message.type == "rag_message_generator":
        function_types = CALLABLE_MESSAGE_RAG_WITH_CARRYOVER_TYPES
        return (
            generate_function(
                function_name=function_name,
                function_args=CALLABLE_MESSAGE_ARGS,
                function_types=function_types,
                function_body=self.message.content_body
                or RAG_METHOD_WITH_CARRYOVER_BODY,
            ),
            function_name,
        )
    return (
        generate_function(
            function_name=function_name,
            function_args=CALLABLE_MESSAGE_ARGS,
            function_types=function_types,
            function_body=self.message_content or "",
        ),
        function_name,
    )

get_nested_chat_message_function(name_prefix: Optional[str] = None, name_suffix: Optional[str] = None) -> Tuple[str, str]

Get the nested chat message function.

Parameters:

NameTypeDescriptionDefault
name_prefixstr

The function name prefix.

None
name_suffixstr

The function name suffix.

None

Returns:

TypeDescription
Tuple[str, str]

The nested chat message function and the function name.

Source code in waldiez/models/chat/chat.py
def get_nested_chat_message_function(
    self,
    name_prefix: Optional[str] = None,
    name_suffix: Optional[str] = None,
) -> Tuple[str, str]:
    """Get the nested chat message function.

    Parameters
    ----------
    name_prefix : str
        The function name prefix.
    name_suffix : str
        The function name suffix.

    Returns
    -------
    Tuple[str, str]
        The nested chat message function and the function name.
    """
    if (
        not self.nested_chat.message
        or self.nested_chat.message.type in ("string", "none")
        or not self.nested_chat.message_content
    ):
        return "", ""
    function_name = NESTED_CHAT_MESSAGE
    if name_prefix:
        function_name = f"{name_prefix}_{function_name}"
    if name_suffix:
        function_name = f"{function_name}_{name_suffix}"
    return (
        generate_function(
            function_name=function_name,
            function_args=NESTED_CHAT_ARGS,
            function_types=NESTED_CHAT_TYPES,
            function_body=self.nested_chat.message_content,
        ),
        function_name,
    )

get_nested_chat_reply_function(name_prefix: Optional[str] = None, name_suffix: Optional[str] = None) -> Tuple[str, str]

Get the nested chat reply function.

Parameters:

NameTypeDescriptionDefault
name_prefixstr

The function name prefix.

None
name_suffixstr

The function name suffix.

None

Returns:

TypeDescription
Tuple[str, str]

The nested chat reply function and the function name.

Source code in waldiez/models/chat/chat.py
def get_nested_chat_reply_function(
    self,
    name_prefix: Optional[str] = None,
    name_suffix: Optional[str] = None,
) -> Tuple[str, str]:
    """Get the nested chat reply function.

    Parameters
    ----------
    name_prefix : str
        The function name prefix.
    name_suffix : str
        The function name suffix.

    Returns
    -------
    Tuple[str, str]
        The nested chat reply function and the function name.
    """
    if (
        not self.nested_chat.reply
        or self.nested_chat.reply.type in ("string", "none")
        or not self.nested_chat.reply_content
    ):
        return "", ""
    function_name = NESTED_CHAT_REPLY
    if name_prefix:
        function_name = f"{name_prefix}_{function_name}"
    if name_suffix:
        function_name = f"{function_name}_{name_suffix}"
    return (
        generate_function(
            function_name=function_name,
            function_args=NESTED_CHAT_ARGS,
            function_types=NESTED_CHAT_TYPES,
            function_body=self.nested_chat.reply_content,
        ),
        function_name,
    )

max_rounds: int property

Get the max rounds for swarm chat.

message: WaldiezChatMessage property

Get the message.

message_content: Optional[str] property

Get the message content.

model_dump(**kwargs: Any) -> Dict[str, Any]

Dump the model to a dict including the chat attributes.

Parameters:

NameTypeDescriptionDefault
kwargsAny

The keyword arguments.

{}

Returns:

TypeDescription
Dict[str, Any]

The model dump with the chat attributes.

Source code in waldiez/models/chat/chat.py
def model_dump(self, **kwargs: Any) -> Dict[str, Any]:
    """Dump the model to a dict including the chat attributes.

    Parameters
    ----------
    kwargs : Any
        The keyword arguments.
    Returns
    -------
    Dict[str, Any]
        The model dump with the chat attributes.
    """
    dump = super().model_dump(**kwargs)
    dump["name"] = self.name
    dump["description"] = self.description
    dump["source"] = self.source
    dump["target"] = self.target
    dump["nested_chat"] = self.nested_chat.model_dump()
    dump["message"] = self.message.model_dump()
    dump["message_content"] = self.message_content
    dump["context_variables"] = self.context_variables
    dump["max_rounds"] = self.max_rounds
    dump["after_work"] = (
        self.after_work.model_dump() if self.after_work else None
    )
    return dump

name: str property

Get the name.

nested_chat: WaldiezChatNested property

Get the nested chat.

order: int property

Get the order.

prerequisites: List[int] property

Get the chat prerequisites.

set_chat_id(value: int) -> None

Set the chat ID.

Parameters:

NameTypeDescriptionDefault
valueint

The chat ID.

required
Source code in waldiez/models/chat/chat.py
def set_chat_id(self, value: int) -> None:
    """Set the chat ID.

    Parameters
    ----------
    value : int
        The chat ID.
    """
    self.data.set_chat_id(value)

set_prerequisites(value: List[int]) -> None

Set the chat prerequisites.

Parameters:

NameTypeDescriptionDefault
valueList[int]

The chat prerequisites.

required
Source code in waldiez/models/chat/chat.py
def set_prerequisites(self, value: List[int]) -> None:
    """Set the chat prerequisites.

    Parameters
    ----------
    value : List[int]
        The chat prerequisites.
    """
    self.data.set_prerequisites(value)

source: str property

Get the source.

target: str property

Get the target.

Chat data model.

WaldiezChatData

Bases: WaldiezBase

Chat data class.

Attributes:

NameTypeDescription
namestr

The name of the chat.

sourcestr

The source of the chat (sender).

targetstr

The target of the chat (recipient).

descriptionstr

The description of the chat.

positionint

The position of the chat. Ignored (UI related).

orderint

The of the chat. If negative, ignored.

clear_history(Optional[bool], optional)

Whether to clear the chat history, by default None.

messageUnion[str, WaldiezChatMessage]

The message of the chat.

nested_chatWaldiezChatNested

The nested chat config.

summaryWaldiezChatSummary

The summary method and options for the chat.

max_turnsOptional[int]

The maximum number of turns for the chat, by default None (no limit).

silent(Optional[bool], optional)

Whether to run the chat silently, by default None (ignored).

summary_argsOptional[Dict[str, Any]]

The summary args to use in autogen.

real_sourceOptional[str]

The real source of the chat (overrides the source).

real_targetOptional[str]

The real target of the chat (overrides the target).

max_roundsint

Maximum number of conversation rounds (swarm).

after_workOptional[WaldiezSwarmAfterWork]

The work to do after the chat (swarm).

Methods:

NameDescription
validate_message

Validate the message.

validate_summary_method

Validate the summary method.

serialize_summary_method

Serialize summary method.

get_chat_args

Get the chat arguments to use in autogen.

get_chat_args(for_queue: bool) -> Dict[str, Any]

Get the chat arguments to use in autogen.

Without the 'message' key.

Parameters:

NameTypeDescriptionDefault
for_queuebool

Whether to get the arguments for a chat queue.

required

Returns:

TypeDescription
Dict[str, Any]

The dictionary to pass as kwargs.

Source code in waldiez/models/chat/chat_data.py
def get_chat_args(self, for_queue: bool) -> Dict[str, Any]:
    """Get the chat arguments to use in autogen.

    Without the 'message' key.

    Parameters
    ----------
    for_queue : bool
        Whether to get the arguments for a chat queue.

    Returns
    -------
    Dict[str, Any]
        The dictionary to pass as kwargs.
    """
    args: Dict[str, Any] = {}
    if self.summary.method:
        args["summary_method"] = self.summary.method
    if self.summary_args:
        args["summary_args"] = self.summary_args
    if isinstance(self.max_turns, int) and self.max_turns > 0:
        args["max_turns"] = self.max_turns
    if isinstance(self.clear_history, bool):
        args["clear_history"] = self.clear_history
    if isinstance(self.silent, bool):
        args["silent"] = self.silent
    args.update(self._get_context_args())
    if for_queue:
        args["chat_id"] = self._chat_id
    if self._prerequisites:
        args["prerequisites"] = self._prerequisites
    return args

get_chat_id() -> int

Get the chat id.

Returns:

TypeDescription
int

The chat id.

Source code in waldiez/models/chat/chat_data.py
def get_chat_id(self) -> int:
    """Get the chat id.

    Returns
    -------
    int
        The chat id.
    """
    return self._chat_id

get_prerequisites() -> List[int]

Get the chat prerequisites.

Returns:

TypeDescription
List[int]

The chat prerequisites (if async).

Source code in waldiez/models/chat/chat_data.py
def get_prerequisites(self) -> List[int]:
    """Get the chat prerequisites.

    Returns
    -------
    List[int]
        The chat prerequisites (if async).
    """
    return self._prerequisites

message_content: Optional[str] property

Get the message content.

set_chat_id(value: int) -> None

Set the chat id.

Parameters:

NameTypeDescriptionDefault
valueint

The chat id.

required
Source code in waldiez/models/chat/chat_data.py
def set_chat_id(self, value: int) -> None:
    """Set the chat id.

    Parameters
    ----------
    value : int
        The chat id.
    """
    self._chat_id = value

set_prerequisites(value: List[int]) -> None

Set the chat prerequisites.

Parameters:

NameTypeDescriptionDefault
valueList[int]

The chat prerequisites to set.

required
Source code in waldiez/models/chat/chat_data.py
def set_prerequisites(self, value: List[int]) -> None:
    """Set the chat prerequisites.

    Parameters
    ----------
    value : List[int]
        The chat prerequisites to set.
    """
    self._prerequisites = value

summary_args: Optional[Dict[str, Any]] property

Get the summary args.

validate_chat_data() -> Self

Validate the chat data.

Returns:

TypeDescription
WaldiezChatData

The validated chat data.

Raises:

TypeDescription
ValueError

If the validation fails.

Source code in waldiez/models/chat/chat_data.py
@model_validator(mode="after")
def validate_chat_data(self) -> Self:
    """Validate the chat data.

    Returns
    -------
    WaldiezChatData
        The validated chat data.

    Raises
    ------
    ValueError
        If the validation fails.
    """
    if not isinstance(self.message, WaldiezChatMessage):  # pragma: no cover
        return self
    self._message_content = self.message.content
    if self.message.type == "none":
        self._message_content = None
    if self.message.type == "string":
        self._message_content = self.message.content
    if self.message.type == "method":
        valid, error_or_body = check_function(
            self.message.content or "",
            CALLABLE_MESSAGE,
            CALLABLE_MESSAGE_ARGS,
        )
        if not valid:
            raise ValueError(error_or_body)
        self._message_content = error_or_body
    return self

validate_context_variables(value: Optional[Dict[str, Any]]) -> Optional[Dict[str, Any]] classmethod

Validate the context variables.

Parameters:

NameTypeDescriptionDefault
valueOptional[Dict[str, Any]]

The context variables value.

required

Returns:

TypeDescription
Optional[Dict[str, Any]]

The validated context variables value.

Raises:

TypeDescription
ValueError

If the validation fails.

Source code in waldiez/models/chat/chat_data.py
@field_validator("context_variables", mode="after")
@classmethod
def validate_context_variables(
    cls, value: Optional[Dict[str, Any]]
) -> Optional[Dict[str, Any]]:
    """Validate the context variables.

    Parameters
    ----------
    value : Optional[Dict[str, Any]]
        The context variables value.

    Returns
    -------
    Optional[Dict[str, Any]]
        The validated context variables value.

    Raises
    ------
    ValueError
        If the validation fails.
    """
    if value is None:
        return None
    return update_dict(value)

validate_message(value: Any) -> WaldiezChatMessage classmethod

Validate the message.

Parameters:

NameTypeDescriptionDefault
valueAny

The message value.

required

Returns:

TypeDescription
WaldiezChatMessage

The validated message value.

Raises:

TypeDescription
ValueError

If the validation fails.

Source code in waldiez/models/chat/chat_data.py
@field_validator("message", mode="before")
@classmethod
def validate_message(cls, value: Any) -> WaldiezChatMessage:
    """Validate the message.

    Parameters
    ----------
    value : Any
        The message value.

    Returns
    -------
    WaldiezChatMessage
        The validated message value.

    Raises
    ------
    ValueError
        If the validation fails.
    """
    if value is None:
        return WaldiezChatMessage(
            type="none", use_carryover=False, content=None, context={}
        )
    if isinstance(value, (str, int, float, bool)):
        return WaldiezChatMessage(
            type="string",
            use_carryover=False,
            content=str(value),
            context={},
        )
    if isinstance(value, dict):
        return WaldiezChatMessage.model_validate(value)
    if not isinstance(value, WaldiezChatMessage):
        return WaldiezChatMessage(
            type="none", use_carryover=False, content=None, context={}
        )
    return value

Waldiez Message Model.

WaldiezChatMessage

Bases: WaldiezBase

Waldiez Message.

A generic message with a type and content.

If the type is not none, the content is a string. If the type is 'method', the content is the source code of a method. If the type is 'last_carryover', the content is a method to return the last carryover from the context. If the type is 'rag_message_generator', and the sender is a RAG user agent, the content will be generated by the sender.message_generator method.

Attributes:

NameTypeDescription
typeWaldiezChatMessageType

The type of the message: - string - method - rag_message_generator - none If the sender is a RAG user agent, and the type is rag_message_generator, the {sender}.message_generator method will be used.

contentOptional[str]

The content of the message (string or method).

contextDict[str, Any]

Extra context of the message.

content_body: Optional[str] property

Get the content body.

validate_content() -> Self

Validate the content (if not a method).

Returns:

TypeDescription
WaldiezChatMessage

The validated instance.

Raises:

TypeDescription
ValueError

If the content is invalid.

Source code in waldiez/models/chat/chat_message.py
@model_validator(mode="after")
def validate_content(self) -> Self:
    """Validate the content (if not a method).

    Returns
    -------
    WaldiezChatMessage
        The validated instance.

    Raises
    ------
    ValueError
        If the content is invalid.
    """
    content: Optional[str] = None
    if self.type == "none":
        content = "None"
    if self.type == "method":
        if not self.content:
            raise ValueError(
                "The message content is required for the method type"
            )
        content = self.content
    if self.type == "string":
        if not self.content:
            self.content = ""
        if self.use_carryover:
            content = get_last_carryover_method_content(
                text_content=self.content,
            )
        content = self.content
    if self.type == "rag_message_generator":
        if self.use_carryover:
            content = get_last_carryover_method_content(
                text_content=self.content or "",
            )
        else:
            content = RAG_METHOD_WITH_CARRYOVER_BODY
            self.content = RAG_METHOD_WITH_CARRYOVER
    self._content_body = content
    return self

validate_context_vars() -> Self

Try to detect bools nulls and numbers from the context values.

Returns:

TypeDescription
WaldiezChatMessage

The validated instance.

Source code in waldiez/models/chat/chat_message.py
@model_validator(mode="after")
def validate_context_vars(self) -> Self:
    """Try to detect bools nulls and numbers from the context values.

    Returns
    -------
    WaldiezChatMessage
        The validated instance.
    """
    self.context = update_dict(self.context)
    return self

validate_method(function_name: str, function_args: List[str]) -> str

Validate a method.

Parameters:

NameTypeDescriptionDefault
function_namestr

The method name.

required
function_argsList[str]

The expected method arguments.

required

Returns:

TypeDescription
str

The validated method body.

Raises:

TypeDescription
ValueError

If the validation fails.

Source code in waldiez/models/chat/chat_message.py
def validate_method(
    self,
    function_name: str,
    function_args: List[str],
) -> str:
    """Validate a method.

    Parameters
    ----------
    function_name : str
        The method name.
    function_args : List[str]
        The expected method arguments.

    Returns
    -------
    str
        The validated method body.

    Raises
    ------
    ValueError
        If the validation fails.
    """
    if not self.content:
        raise ValueError(
            "The message content is required for the method type"
        )
    is_valid, error_or_body = check_function(
        code_string=self.content,
        function_name=function_name,
        function_args=function_args,
    )
    if not is_valid:
        raise ValueError(error_or_body)
    return error_or_body

WaldiezChatMessageType = Literal['string', 'method', 'rag_message_generator', 'none'] module-attribute

Possible types for the message.

get_last_carryover_method_content(text_content: str) -> str

Get the last carryover method content.

Parameters:

NameTypeDescriptionDefault
text_contentstr

Text content before the carryover.

required

Returns:

TypeDescription
str

The last carryover method content.

Source code in waldiez/models/chat/chat_message.py
def get_last_carryover_method_content(text_content: str) -> str:
    """Get the last carryover method content.

    Parameters
    ----------
    text_content : str
        Text content before the carryover.
    Returns
    -------
    str
        The last carryover method content.
    """
    method_content = '''
    """Get the message to send using the last carryover.

    Parameters
    ----------
    sender : ConversableAgent
        The source agent.
    recipient : ConversableAgent
        The target agent.
    context : Dict[str, Any]
        The context.

    Returns
    -------
    Union[Dict[str, Any], str]
        The message to send using the last carryover.
    """
    carryover = context.get("carryover", "")
    if isinstance(carryover, list):
        carryover = carryover[-1]
    if not isinstance(carryover, str):
        if isinstance(carryover, list):
            carryover = carryover[-1]
        elif isinstance(carryover, dict):
            carryover = carryover.get("content", "")
    if not isinstance(carryover, str):
        carryover = ""'''
    if text_content:
        method_content += f"""
    final_message = "{text_content}" + carryover
    return final_message
"""
    else:
        method_content += """
    return carryover
"""
    return method_content

Nested chat model.

WaldiezChatNested

Bases: WaldiezBase

Nested chat class.

Attributes:

NameTypeDescription
messageWaldiezChatMessage

The message in a nested chat (sender -> recipient).

replyWaldiezChatMessage

The reply in a nested chat (recipient -> sender).

message_content: Optional[str] property

Get the message content.

reply_content: Optional[str] property

Get the reply content.

validate_message(value: Any) -> WaldiezChatMessage classmethod

Validate the message.

Parameters:

NameTypeDescriptionDefault
valueAny

The value.

required

Returns:

TypeDescription
WaldiezChatMessage

The validated message.

Raises:

TypeDescription
ValueError

If the validation fails.

Source code in waldiez/models/chat/chat_nested.py
@field_validator("message", "reply", mode="before")
@classmethod
def validate_message(cls, value: Any) -> WaldiezChatMessage:
    """Validate the message.

    Parameters
    ----------
    value : Any
        The value.

    Returns
    -------
    WaldiezChatMessage
        The validated message.

    Raises
    ------
    ValueError
        If the validation fails.
    """
    if not value:
        return WaldiezChatMessage(
            type="none", use_carryover=False, content=None, context={}
        )
    if isinstance(value, str):
        return WaldiezChatMessage(
            type="string", use_carryover=False, content=value, context={}
        )
    if isinstance(value, dict):
        return WaldiezChatMessage.model_validate(value)
    if isinstance(value, WaldiezChatMessage):
        return value
    raise ValueError(f"Invalid message type: {type(value)}")

validate_nested_chat() -> Self

Validate the nested chat.

Returns:

TypeDescription
WaldiezChatNested

The validated nested chat.

Raises:

TypeDescription
ValueError

If the validation fails.

Source code in waldiez/models/chat/chat_nested.py
@model_validator(mode="after")
def validate_nested_chat(self) -> Self:
    """Validate the nested chat.

    Returns
    -------
    WaldiezChatNested
        The validated nested chat.

    Raises
    ------
    ValueError
        If the validation fails.
    """
    if self.message is not None:
        self._message_content = self.message.content_body
        if self.message.type == "none":
            self._message_content = ""
        if self.message.type == "string":
            self._message_content = self.message.content
        if self.message.type == "method":
            self._message_content = self.message.validate_method(
                function_name=NESTED_CHAT_MESSAGE,
                function_args=NESTED_CHAT_ARGS,
            )

    if self.reply is not None:
        self._reply_content = self.reply.content_body
        if self.reply.type == "none":
            self._reply_content = ""
        if self.reply.type == "string":
            self._reply_content = self.reply.content
        if self.reply.type == "method":
            self._reply_content = self.reply.validate_method(
                function_name=NESTED_CHAT_REPLY,
                function_args=NESTED_CHAT_ARGS,
            )
    return self

Waldiez chat summary options.

WaldiezChatSummary

Bases: WaldiezBase

Llm summary method options.

Attributes:

NameTypeDescription
methodOptional[WaldiezChatSummaryMethod]

The method to use for the LLM summary. Defaults to "last_msg".

promptstr

The prompt for the LLM summary method.

argsOptional[Dict[str, Any]]

The additional arguments for the LLM summary method, by default None.

serialize_summary_method(value: Any, info: FieldSerializationInfo) -> Any classmethod

Serialize summary method.

Parameters:

NameTypeDescriptionDefault
valueAny

The value to serialize.

required
infoFieldSerializationInfo

The serialization info.

required

Returns:

TypeDescription
Any

The serialized value.

Source code in waldiez/models/chat/chat_summary.py
@field_serializer("method")
@classmethod
def serialize_summary_method(
    cls, value: Any, info: FieldSerializationInfo
) -> Any:
    """Serialize summary method.

    Parameters
    ----------
    value : Any
        The value to serialize.
    info : FieldSerializationInfo
        The serialization info.

    Returns
    -------
    Any
        The serialized value.
    """
    if info.by_alias is True:
        if value == "reflection_with_llm":
            return "reflectionWithLlm"
        if value == "last_msg":
            return "lastMsg"
    return value

validate_summary_method(value: Optional[WaldiezChatSummaryMethod]) -> Optional[WaldiezChatSummaryMethod] classmethod

Validate the summary method.

Parameters:

NameTypeDescriptionDefault
valueOptional[WaldiezChatSummaryMethod]

The passed WaldiezChatSummaryMethod

required

Returns:

TypeDescription
Optional[WaldiezChatSummaryMethod]

The validated message summary method

Source code in waldiez/models/chat/chat_summary.py
@field_validator("method", mode="before")
@classmethod
def validate_summary_method(
    cls, value: Optional[WaldiezChatSummaryMethod]
) -> Optional[WaldiezChatSummaryMethod]:
    """Validate the summary method.

    Parameters
    ----------
    value : Optional[WaldiezChatSummaryMethod]
        The passed WaldiezChatSummaryMethod

    Returns
    -------
    Optional[WaldiezChatSummaryMethod]
        The validated message summary method
    """
    if str(value).lower() == "none":
        return None
    if value == "lastMsg":
        return "last_msg"
    if value == "reflectionWithLlm":
        return "reflection_with_llm"
    return value

WaldiezChatSummaryMethod = Literal['reflectionWithLlm', 'lastMsg', 'reflection_with_llm', 'last_msg'] module-attribute

Possible methods for the LLM summary.