mindroot.coreplugins.chat.models - MindRoot 9.10.0 documentation

Hide navigation sidebar
Hide table of contents sidebar
Skip to content
Back to top
Toggle table of contents sidebar

# Source code for mindroot.coreplugins.chat.models

    from typing import Union, List, Literal
    from pydantic import BaseModel

    class TextMessagePart(BaseModel):
        type: Literal["text"]
        text: str

    class ImageMessagePart(BaseModel):
        type: Literal["image"]
        data: str  # Use 'data' here to store your data URL string

    # we need to be able to serialize this data to JSON
    # so we can send
    # it over the network
    # implementaion for ImageMessagePart json serialization:
    # https://pydantic-docs.helpmanual.io/usage/exporting_models/#json-serialisation
    # https://pydantic-docs.helpmanual.io/usage/exporting_models/#json-serialisation

    # Use Union to create a discriminated union type
    MessageParts = Union[TextMessagePart, ImageMessagePart]