Skip to content

message_intel

django_spire.ai.chat.message_intel

BaseMessageIntel

Bases: BaseIntel, ABC

template property

__init_subclass__

Source code in django_spire/ai/chat/message_intel.py
def __init_subclass__(cls, **kwargs):
    super().__init_subclass__(**kwargs)

    template = cls.__dict__.get('_template')

    if template is None and hasattr(cls, '__private_attributes__'):
        private_attr = cls.__private_attributes__.get('_template')

        if private_attr and hasattr(private_attr, 'default'):
            template = private_attr.default

    if not template:
        message = f'{cls.__module__}.{cls.__qualname__}._template must be set'
        raise ValueError(message)

render_to_str abstractmethod

Source code in django_spire/ai/chat/message_intel.py
@abstractmethod
def render_to_str(self) -> str:
    raise NotImplementedError

render_template_to_str

Source code in django_spire/ai/chat/message_intel.py
def render_template_to_str(self, context_data: dict | None = None):
    return render_to_string(
        template_name=self._template,
        context={**self.model_dump(), **(context_data or {})},
    )

DefaultMessageIntel

Bases: BaseMessageIntel

text instance-attribute

render_to_str

Source code in django_spire/ai/chat/message_intel.py
def render_to_str(self) -> str:
    return self.text