Skip to content

notion

Notion

Notion(content: str, role: Union[ChatRole, ReactRole, str], persistent: bool = False)

Bases: Memory

A memory that stores the role associated with its content. The role is usually a [ChatRole][silverlingua.core.atoms.role.chat.ChatRole] or a [ReactRole][silverlingua.core.atoms.role.react.ReactRole]. (See [atoms/roles][silverlingua.core.atoms.role])

Attributes:

Name Type Description
role str

The role of the notion.

content str

The content of the memory.

persistent bool

Whether the notion should be stored in long-term memory.

Source code in src/SilverLingua/core/molecules/notion.py
def __init__(
    self,
    content: str,
    role: Union[ChatRole, ReactRole, str],
    persistent: bool = False,
):
    super().__init__(content=content, role=role, persistent=persistent)

content instance-attribute

content: str

model_config class-attribute instance-attribute

model_config = ConfigDict(from_attributes=True)

role instance-attribute

role: str

persistent class-attribute instance-attribute

persistent: bool = False

chat_role property

chat_role: ChatRole

Gets the chat based role Enum (e.g. Role.SYSTEM, Role.HUMAN, etc.)

(See config)

react_role property

react_role: ReactRole

Gets the react based role Enum (e.g. Role.THOUGHT, Role.OBSERVATION, etc.)

(See config)

validate_role classmethod

validate_role(v: Union[ChatRole, ReactRole, str])
Source code in src/SilverLingua/core/molecules/notion.py
@field_validator("role", mode="before")
@classmethod
def validate_role(cls, v: Union[ChatRole, ReactRole, str]):
    if isinstance(v, (ChatRole, ReactRole)):
        return v.value.value
    elif isinstance(v, str):
        return v
    raise ValueError(f"Expected a ChatRole, ReactRole, or a string, got {type(v)}")