Module zep_python.message

Expand source code
from zep_python.message.models import (
    Message,
)

__all__ = [
    "Message",
]

Sub-modules

zep_python.message.client
zep_python.message.models

Classes

class Message (**data: Any)

Represents a message in a conversation.

Attributes

uuid : str, optional
The unique identifier of the message.
created_at : str, optional
The timestamp of when the message was created.
role : str
The role of the sender of the message (e.g., "user", "assistant").
role_type : RoleType
The type of the role (e.g., "user", "system").
content : str
The content of the message.
token_count : int, optional
The number of tokens in the message.

Methods

to_dict() -> Dict[str, Any]: Returns a dictionary representation of the message.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Expand source code
class Message(BaseModel):
    """
    Represents a message in a conversation.

    Attributes
    ----------
    uuid : str, optional
        The unique identifier of the message.
    created_at : str, optional
        The timestamp of when the message was created.
    role : str
        The role of the sender of the message (e.g., "user", "assistant").
    role_type: RoleType
        The type of the role (e.g., "user", "system").
    content : str
        The content of the message.
    token_count : int, optional
        The number of tokens in the message.

    Methods
    -------
    to_dict() -> Dict[str, Any]:
        Returns a dictionary representation of the message.
    """

    role: str = Field("A role is required")
    role_type: RoleType = Field("A role type is required")
    content: str = Field("Content is required")
    uuid: Optional[str] = Field(default=None)
    created_at: Optional[str] = Field(default=None)
    token_count: Optional[int] = Field(default=None)
    metadata: Optional[Dict[str, Any]] = Field(default=None)

    @validator("role_type")
    def validate_role_type(cls, v):
        if isinstance(v, RoleType):
            return v
        if v not in RoleType._value2member_map_:
            raise ValueError(f"Invalid role type: {v}")
        return v

    def to_dict(self) -> Dict[str, Any]:
        """
        Returns a dictionary representation of the message.

        Returns
        -------
        Dict[str, Any]
            A dictionary containing the attributes of the message.
        """
        return self.model_dump(exclude_unset=True, exclude_none=True)

Ancestors

  • pydantic.main.BaseModel

Class variables

var content : str
var created_at : Optional[str]
var metadata : Optional[Dict[str, Any]]
var model_computed_fields
var model_config
var model_fields
var role : str
var role_typeRoleType
var token_count : Optional[int]
var uuid : Optional[str]

Static methods

def validate_role_type(v)
Expand source code
@validator("role_type")
def validate_role_type(cls, v):
    if isinstance(v, RoleType):
        return v
    if v not in RoleType._value2member_map_:
        raise ValueError(f"Invalid role type: {v}")
    return v

Methods

def to_dict(self) ‑> Dict[str, Any]

Returns a dictionary representation of the message.

Returns

Dict[str, Any]
A dictionary containing the attributes of the message.
Expand source code
def to_dict(self) -> Dict[str, Any]:
    """
    Returns a dictionary representation of the message.

    Returns
    -------
    Dict[str, Any]
        A dictionary containing the attributes of the message.
    """
    return self.model_dump(exclude_unset=True, exclude_none=True)