Module zep_python.message.models
Expand source code
from enum import Enum
from typing import Any, Dict, Optional
from uuid import UUID
from pydantic import BaseModel, Field, validator
class RoleType(str, Enum):
USER_ROLE = "user"
ASSISTANT_ROLE = "assistant"
SYSTEM_ROLE = "system"
FUNCTION_ROLE = "function"
TOOL_ROLE = "tool"
NO_ROLE = "norole"
def get_zep_message_role_type(role):
if role == "human":
return RoleType.USER_ROLE
elif role == "ai":
return RoleType.ASSISTANT_ROLE
elif role == "system":
return RoleType.SYSTEM_ROLE
elif role == "function":
return RoleType.FUNCTION_ROLE
elif role == "tool":
return RoleType.TOOL_ROLE
elif role == "norole":
return RoleType.NO_ROLE
else:
return RoleType.NO_ROLE
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)
class UpdateMessageMetadataRequest(BaseModel):
"""
Represents a request to update a user.
Attributes
----------
uuid : UUID
A unique identifier for the message.
session_id : str
A unique identifier for the session.
metadata : Dict[str, Any]
The metadata associated with the message.
"""
uuid: UUID
session_id: str
metadata: Dict[str, Any]
Functions
def get_zep_message_role_type(role)
-
Expand source code
def get_zep_message_role_type(role): if role == "human": return RoleType.USER_ROLE elif role == "ai": return RoleType.ASSISTANT_ROLE elif role == "system": return RoleType.SYSTEM_ROLE elif role == "function": return RoleType.FUNCTION_ROLE elif role == "tool": return RoleType.TOOL_ROLE elif role == "norole": return RoleType.NO_ROLE else: return RoleType.NO_ROLE
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 allowself
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_type : RoleType
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)
class RoleType (*args, **kwds)
-
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.
Expand source code
class RoleType(str, Enum): USER_ROLE = "user" ASSISTANT_ROLE = "assistant" SYSTEM_ROLE = "system" FUNCTION_ROLE = "function" TOOL_ROLE = "tool" NO_ROLE = "norole"
Ancestors
- builtins.str
- enum.Enum
Class variables
var ASSISTANT_ROLE
var FUNCTION_ROLE
var NO_ROLE
var SYSTEM_ROLE
var TOOL_ROLE
var USER_ROLE
class UpdateMessageMetadataRequest (**data: Any)
-
Represents a request to update a user.
Attributes
uuid
:UUID
- A unique identifier for the message.
session_id
:str
- A unique identifier for the session.
metadata
:Dict[str, Any]
- The metadata associated with 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 allowself
as a field name.Expand source code
class UpdateMessageMetadataRequest(BaseModel): """ Represents a request to update a user. Attributes ---------- uuid : UUID A unique identifier for the message. session_id : str A unique identifier for the session. metadata : Dict[str, Any] The metadata associated with the message. """ uuid: UUID session_id: str metadata: Dict[str, Any]
Ancestors
- pydantic.main.BaseModel
Class variables
var metadata : Dict[str, Any]
var model_computed_fields
var model_config
var model_fields
var session_id : str
var uuid : uuid.UUID