Skip to content

pixano.features.schemas.annotations.text_generation

Message(created_at=None, updated_at=None, **data)

Bases: Annotation

Textual exchange in a question/answer conversation for image or text description and information extraction.

Attributes:

Name Type Description
number int

message number to associate different ANSWER messages to a QUESTION.

user str

identify who is the author of the message (eg a human, a model, the ground truth, etc).

content str

actual text of the message.

timestamp datetime

creation date of the message.

type str

type of the message within "SYSTEM", "QUESTION" or"ANSWER". - SYSTEM: used for prefix messages stating the context. No associated answer expected - QUESTION: used to ask a question about a View. Expecting at least one answer (same message number) - ANSWER: used to reply to a question message by refering its message number

Source code in pixano/features/schemas/base_schema.py
def __init__(self, /, created_at: datetime | None = None, updated_at: datetime | None = None, **data: Any):
    """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.

    Args:
        created_at: The creation date of the object.
        updated_at: The last modification date of the object.
        data: The data of the object validated by Pydantic.
    """
    created_at, updated_at = validate_and_init_create_at_and_update_at(created_at, updated_at)
    data.update({"created_at": created_at, "updated_at": updated_at})
    super().__init__(**data)

none() classmethod

Utility function to get a None equivalent. Should be removed when Lance could manage None value.

Returns:

Type Description
Message

"None" Message.

Source code in pixano/features/schemas/annotations/text_generation.py
@classmethod
def none(cls) -> "Message":
    """Utility function to get a None equivalent.
    Should be removed when Lance could manage None value.

    Returns:
        "None" Message.
    """
    return cls(
        id="",
        item=ItemRef.none(),
        view=ViewRef.none(),
        entity=EntityRef.none(),
        source_ref=SourceRef.none(),
        number=0,
        user="",
        type="QUESTION",
        content="",
        timestamp=datetime(1, 1, 1, 0, 0, 0, 0),
    )

create_message(number, user, type, content, timestamp=datetime(1, 1, 1, 0, 0, 0, 0), id='', item_ref=ItemRef.none(), view_ref=ViewRef.none(), entity_ref=EntityRef.none(), source_ref=SourceRef.none())

Create a Message instance.

Parameters:

Name Type Description Default
number int

message number to associate diffrent ANSWER messages to a QUESTION

required
user str

identify who is the author of the message (eg a human, a model, the ground truth, etc)

required
type Literal['SYSTEM', 'QUESTION', 'ANSWER']

type of the message within "SYSTEM", "QUESTION" or"ANSWER"

required
content str

actual text of the message

required
timestamp datetime

creation date of the message

datetime(1, 1, 1, 0, 0, 0, 0)
id str

object id

''
item_ref ItemRef

Item reference.

none()
view_ref ViewRef

View reference.

none()
entity_ref EntityRef

Entity reference.

none()
source_ref SourceRef

Source reference.

none()

Returns:

Type Description
Message

The created Message instance.

Source code in pixano/features/schemas/annotations/text_generation.py
def create_message(
    number: int,
    user: str,
    type: Literal["SYSTEM", "QUESTION", "ANSWER"],
    content: str,
    timestamp: datetime = datetime(1, 1, 1, 0, 0, 0, 0),
    id: str = "",
    item_ref: ItemRef = ItemRef.none(),
    view_ref: ViewRef = ViewRef.none(),
    entity_ref: EntityRef = EntityRef.none(),
    source_ref: SourceRef = SourceRef.none(),
) -> Message:
    """Create a Message instance.

    Args:
        number: message number to associate diffrent ANSWER messages to a QUESTION
        user: identify who is the author of the message (eg a human, a model, the ground truth, etc)
        type: type of the message within "SYSTEM", "QUESTION" or"ANSWER"
        content: actual text of the message
        timestamp: creation date of the message
        id: object id
        item_ref: Item reference.
        view_ref: View reference.
        entity_ref: Entity reference.
        source_ref: Source reference.

    Returns:
        The created `Message` instance.
    """
    return Message(
        number=number,
        user=user,
        type=type,
        content=content,
        timestamp=timestamp,
        id=id,
        item_ref=item_ref,
        view_ref=view_ref,
        entity_ref=entity_ref,
        source_ref=source_ref,
    )

is_message(cls, strict=False)

Check if a class is a Message or subclass of Message.

Source code in pixano/features/schemas/annotations/text_generation.py
def is_message(cls: type, strict: bool = False) -> bool:
    """Check if a class is a Message or subclass of Message."""
    return issubclass_strict(cls, Message, strict)