Skip to content

WeightedPrompt

Bases: BaseModel

Represents a prompt with an associated weight.

This class is used to define a text prompt with a corresponding numerical weight, indicating the significance or influence of the prompt in a given context, such as in image generation or text processing tasks.

Attributes:

Name Type Description
text str

The textual content of the prompt.

weight float

A numerical weight associated with the prompt. Defaults to 1. The weight must be greater than or equal to 0.

Methods:

Name Description
__repr__

Returns a string representation of the WeightedPrompt instance, formatted as 'weight*(text)'.

Source code in imaginairy/schema.py
class WeightedPrompt(BaseModel):
    """
    Represents a prompt with an associated weight.

    This class is used to define a text prompt with a corresponding numerical weight,
    indicating the significance or influence of the prompt in a given context, such as
    in image generation or text processing tasks.

    Attributes:
        text (str): The textual content of the prompt.
        weight (float): A numerical weight associated with the prompt. Defaults to 1.
                        The weight must be greater than or equal to 0.

    Methods:
        __repr__: Returns a string representation of the WeightedPrompt instance,
                  formatted as 'weight*(text)'.
    """

    text: str
    weight: float = Field(1, ge=0)

    def __repr__(self):
        return f"{self.weight}*({self.text})"