Skip to content

object_models

FormatImplementationStandard

Bases: StrEnum

The standards for format implementations.

Source code in horde_sdk/generation_parameters/text/object_models.py
class FormatImplementationStandard(StrEnum):
    """The standards for format implementations."""

    KOBOLD_AI = auto()
    """The KoboldAI standard for a format implementation."""

KOBOLD_AI class-attribute instance-attribute

KOBOLD_AI = auto()

The KoboldAI standard for a format implementation.

FormatFeatureFlags

Bases: GenerationFeatureFlags

Represents the feature flags for text generation formatting.

Source code in horde_sdk/generation_parameters/text/object_models.py
class FormatFeatureFlags(GenerationFeatureFlags):
    """Represents the feature flags for text generation formatting."""

    format_implementation_standard: FormatImplementationStandard | None = Field(
        default=None,
        examples=[
            FormatImplementationStandard.KOBOLD_AI,
        ],
    )
    """The standard for format implementations."""

    leading_space_to_input_when_missing: bool = Field(
        default=False,
        examples=[
            False,
        ],
    )
    """Input formatting option. When enabled, adds a leading space to your input if there is no trailing whitespace at
    the end of the previous action."""

    remove_consecutive_newlines: bool = Field(
        default=False,
        examples=[
            False,
        ],
    )
    """Output formatting option. When enabled, replaces all occurrences of two or more consecutive newlines in the
    output with one newline."""

    remove_special_characters: bool = Field(
        default=False,
        examples=[
            False,
        ],
    )
    """Output formatting option. When enabled, removes #/@%}{+=~|\\^<> from the output."""

    remove_end_of_sentence: bool = Field(
        default=False,
        examples=[
            False,
        ],
    )
    """Output formatting option. When enabled, removes some characters from the end of the output such that the output
    doesn't end in the middle of a sentence. If the output is less than one sentence long, does nothing."""

    remove_after_first_line: bool = Field(
        default=False,
        examples=[
            False,
        ],
    )
    """Output formatting option. When enabled, removes everything after the first line of the output, including the
    newline."""

format_implementation_standard class-attribute instance-attribute

format_implementation_standard: (
    FormatImplementationStandard | None
) = Field(default=None, examples=[KOBOLD_AI])

The standard for format implementations.

leading_space_to_input_when_missing class-attribute instance-attribute

leading_space_to_input_when_missing: bool = Field(
    default=False, examples=[False]
)

Input formatting option. When enabled, adds a leading space to your input if there is no trailing whitespace at the end of the previous action.

remove_consecutive_newlines class-attribute instance-attribute

remove_consecutive_newlines: bool = Field(
    default=False, examples=[False]
)

Output formatting option. When enabled, replaces all occurrences of two or more consecutive newlines in the output with one newline.

remove_special_characters class-attribute instance-attribute

remove_special_characters: bool = Field(
    default=False, examples=[False]
)

Output formatting option. When enabled, removes #/@%}{+=~|\^<> from the output.

remove_end_of_sentence class-attribute instance-attribute

remove_end_of_sentence: bool = Field(
    default=False, examples=[False]
)

Output formatting option. When enabled, removes some characters from the end of the output such that the output doesn't end in the middle of a sentence. If the output is less than one sentence long, does nothing.

remove_after_first_line class-attribute instance-attribute

remove_after_first_line: bool = Field(
    default=False, examples=[False]
)

Output formatting option. When enabled, removes everything after the first line of the output, including the newline.

model_config class-attribute instance-attribute

model_config = ConfigDict(use_attribute_docstrings=True)

extra_texts class-attribute instance-attribute

extra_texts: bool = Field(default=False)

Whether there is support for extra texts.

extra_source_images class-attribute instance-attribute

extra_source_images: bool = Field(default=False)

Whether there is support for extra source images.

BasicTextGenerationFormatParameters

Bases: GenerationParameterBaseModel

Represent common text generation formatting parameters.

Source code in horde_sdk/generation_parameters/text/object_models.py
class BasicTextGenerationFormatParameters(GenerationParameterBaseModel):  # TODO: Better field names
    """Represent common text generation formatting parameters."""

    frmtadsnsp: bool | None = Field(
        default=None,
        examples=[
            False,
        ],
    )
    """Input formatting option. When enabled, adds a leading space to your input if there is no trailing whitespace at
    the end of the previous action."""
    frmtrmblln: bool | None = Field(
        default=None,
        examples=[
            False,
        ],
    )
    """Output formatting option. When enabled, replaces all occurrences of two or more consecutive newlines in the
    output with one newline."""
    frmtrmspch: bool | None = Field(
        default=None,
        examples=[
            False,
        ],
    )
    """Output formatting option. When enabled, removes #/@%}{+=~|\\^<> from the output."""
    frmttriminc: bool | None = Field(
        default=None,
        examples=[
            False,
        ],
    )
    """Output formatting option. When enabled, removes some characters from the end of the output such that the output
    doesn't end in the middle of a sentence. If the output is less than one sentence long, does nothing."""
    singleline: bool | None = Field(
        default=None,
        examples=[
            False,
        ],
    )
    """Output formatting option. When enabled, removes everything after the first line of the output, including the
    newline."""

frmtadsnsp class-attribute instance-attribute

frmtadsnsp: bool | None = Field(
    default=None, examples=[False]
)

Input formatting option. When enabled, adds a leading space to your input if there is no trailing whitespace at the end of the previous action.

frmtrmblln class-attribute instance-attribute

frmtrmblln: bool | None = Field(
    default=None, examples=[False]
)

Output formatting option. When enabled, replaces all occurrences of two or more consecutive newlines in the output with one newline.

frmtrmspch class-attribute instance-attribute

frmtrmspch: bool | None = Field(
    default=None, examples=[False]
)

Output formatting option. When enabled, removes #/@%}{+=~|\^<> from the output.

frmttriminc class-attribute instance-attribute

frmttriminc: bool | None = Field(
    default=None, examples=[False]
)

Output formatting option. When enabled, removes some characters from the end of the output such that the output doesn't end in the middle of a sentence. If the output is less than one sentence long, does nothing.

singleline class-attribute instance-attribute

singleline: bool | None = Field(
    default=None, examples=[False]
)

Output formatting option. When enabled, removes everything after the first line of the output, including the newline.

SCHEMA_VERSION class-attribute

SCHEMA_VERSION: str = '1.0'

Most recent schema version for this payload.

LEGACY_SCHEMA_VERSION class-attribute

LEGACY_SCHEMA_VERSION: str = '1.0'

Oldest schema version supported for deserialization when unspecified.

schema_version class-attribute instance-attribute

schema_version: str = Field(
    default="",
    description="Schema version recorded when the payload was serialized.",
)

model_config class-attribute instance-attribute

model_config = ConfigDict(
    use_attribute_docstrings=True, from_attributes=True
)

underlying_generation_scheme class-attribute instance-attribute

underlying_generation_scheme: (
    UNDERLYING_GENERATION_SCHEME | None
) = None

The underlying method the generation uses to produce results.

  • If associated with a auxiliary process that is model based, such as a LoRa, this should be set to MODEL.
  • If instead a service is used to produce results, this should be set to MODEL_FROM_SERVICE.
  • If there is no generative model involved, and instead a "traditional" algorithm is used, this should be set to NON_MODEL_ALGORITHM.

Otherwise, if this component is simply a set of parameters that, in itself, does not produce results, this should be set to None.

current_schema_version classmethod

current_schema_version() -> str

Return the canonical schema version for newly created instances.

Source code in horde_sdk/generation_parameters/generic/__init__.py
@classmethod
def current_schema_version(cls) -> str:
    """Return the canonical schema version for newly created instances."""
    return cls.SCHEMA_VERSION

legacy_schema_version classmethod

legacy_schema_version() -> str

Return the version assumed for pre-metadata payloads.

Source code in horde_sdk/generation_parameters/generic/__init__.py
@classmethod
def legacy_schema_version(cls) -> str:
    """Return the version assumed for pre-metadata payloads."""
    return getattr(cls, "LEGACY_SCHEMA_VERSION", cls.SCHEMA_VERSION)

BasicTextGenerationParametersTemplate

Bases: GenerationWithModelParameters

Represents the common parameters for a text generation.

Source code in horde_sdk/generation_parameters/text/object_models.py
class BasicTextGenerationParametersTemplate(GenerationWithModelParameters):  # TODO: Non-AI-Horde specific constraints
    """Represents the common parameters for a text generation."""

    prompt: str | None = None
    """The prompt to use for the generation."""

    soft_prompt: str | None = None
    """The soft prompt to use for the generation."""

    max_context_length: int | None = Field(
        default=None,
        ge=80,
        le=32000,
    )
    """Maximum number of tokens to send to the model."""

    max_length: int | None = Field(default=None, ge=16, le=1024)
    """Number of tokens to generate."""

    stop_sequence: list[str] | None = None
    """The stop sequences to use for the generation."""

    temperature: float | None = Field(default=None, ge=0.0, le=5.0)
    """Temperature value."""

    dynamic_temp_exponent: float | None = Field(default=None, ge=0.0, le=5.0)
    """Dynamic temperature exponent value."""
    dynamic_temp_range: float | None = Field(default=None, ge=0.0, le=5.0)
    """Dynamic temperature range value."""

    tfs: float | None = Field(default=None, ge=0.0, le=1.0)
    """Tail free sampling value."""
    typical: float | None = Field(default=None, ge=0.0, le=1.0)
    """Typical sampling value."""
    sampler_order: list[int] | None = None
    """The sampler order to use for the generation."""
    smoothing_factor: float | None = Field(default=None, ge=0.0, le=10.0)
    """Quadratic sampling value."""

    top_a: float | None = Field(default=None, ge=0.0, le=1.0)
    """Top-a sampling value."""
    top_k: int | None = Field(default=None, ge=0, le=100)
    """Top-k sampling value."""
    top_p: float | None = Field(default=None, ge=0.001, le=1.0)
    """Top-p sampling value."""

    min_p: float | None = Field(default=None, ge=0.0, le=1.0)
    """Min-p sampling value."""
    rep_pen: float | None = Field(default=None, ge=1.0, le=3.0)
    """Base repetition penalty value."""
    rep_pen_range: int | None = Field(default=None, ge=0, le=4096)
    """Repetition penalty range."""
    rep_pen_slope: float | None = Field(default=None, ge=0.0, le=10.0)
    """Repetition penalty slope."""

prompt class-attribute instance-attribute

prompt: str | None = None

The prompt to use for the generation.

soft_prompt class-attribute instance-attribute

soft_prompt: str | None = None

The soft prompt to use for the generation.

max_context_length class-attribute instance-attribute

max_context_length: int | None = Field(
    default=None, ge=80, le=32000
)

Maximum number of tokens to send to the model.

max_length class-attribute instance-attribute

max_length: int | None = Field(default=None, ge=16, le=1024)

Number of tokens to generate.

stop_sequence class-attribute instance-attribute

stop_sequence: list[str] | None = None

The stop sequences to use for the generation.

temperature class-attribute instance-attribute

temperature: float | None = Field(
    default=None, ge=0.0, le=5.0
)

Temperature value.

dynamic_temp_exponent class-attribute instance-attribute

dynamic_temp_exponent: float | None = Field(
    default=None, ge=0.0, le=5.0
)

Dynamic temperature exponent value.

dynamic_temp_range class-attribute instance-attribute

dynamic_temp_range: float | None = Field(
    default=None, ge=0.0, le=5.0
)

Dynamic temperature range value.

tfs class-attribute instance-attribute

tfs: float | None = Field(default=None, ge=0.0, le=1.0)

Tail free sampling value.

typical class-attribute instance-attribute

typical: float | None = Field(default=None, ge=0.0, le=1.0)

Typical sampling value.

sampler_order class-attribute instance-attribute

sampler_order: list[int] | None = None

The sampler order to use for the generation.

smoothing_factor class-attribute instance-attribute

smoothing_factor: float | None = Field(
    default=None, ge=0.0, le=10.0
)

Quadratic sampling value.

top_a class-attribute instance-attribute

top_a: float | None = Field(default=None, ge=0.0, le=1.0)

Top-a sampling value.

top_k class-attribute instance-attribute

top_k: int | None = Field(default=None, ge=0, le=100)

Top-k sampling value.

top_p class-attribute instance-attribute

top_p: float | None = Field(default=None, ge=0.001, le=1.0)

Top-p sampling value.

min_p class-attribute instance-attribute

min_p: float | None = Field(default=None, ge=0.0, le=1.0)

Min-p sampling value.

rep_pen class-attribute instance-attribute

rep_pen: float | None = Field(default=None, ge=1.0, le=3.0)

Base repetition penalty value.

rep_pen_range class-attribute instance-attribute

rep_pen_range: int | None = Field(
    default=None, ge=0, le=4096
)

Repetition penalty range.

rep_pen_slope class-attribute instance-attribute

rep_pen_slope: float | None = Field(
    default=None, ge=0.0, le=10.0
)

Repetition penalty slope.

SCHEMA_VERSION class-attribute

SCHEMA_VERSION: str = '1.0'

Most recent schema version for this payload.

LEGACY_SCHEMA_VERSION class-attribute

LEGACY_SCHEMA_VERSION: str = '1.0'

Oldest schema version supported for deserialization when unspecified.

schema_version class-attribute instance-attribute

schema_version: str = Field(
    default="",
    description="Schema version recorded when the payload was serialized.",
)

model_config class-attribute instance-attribute

model_config = ConfigDict(
    use_attribute_docstrings=True, from_attributes=True
)

underlying_generation_scheme class-attribute instance-attribute

underlying_generation_scheme: (
    UNDERLYING_GENERATION_SCHEME
) = MODEL

See :attr:ComposedParameterSetBase.underlying_generation_scheme for more information.

model class-attribute instance-attribute

model: str | None = None

model_baseline class-attribute instance-attribute

model_baseline: str | None = None

current_schema_version classmethod

current_schema_version() -> str

Return the canonical schema version for newly created instances.

Source code in horde_sdk/generation_parameters/generic/__init__.py
@classmethod
def current_schema_version(cls) -> str:
    """Return the canonical schema version for newly created instances."""
    return cls.SCHEMA_VERSION

legacy_schema_version classmethod

legacy_schema_version() -> str

Return the version assumed for pre-metadata payloads.

Source code in horde_sdk/generation_parameters/generic/__init__.py
@classmethod
def legacy_schema_version(cls) -> str:
    """Return the version assumed for pre-metadata payloads."""
    return getattr(cls, "LEGACY_SCHEMA_VERSION", cls.SCHEMA_VERSION)

BasicTextGenerationParameters

Bases: BasicTextGenerationParametersTemplate

Represents the common bare-minimum parameters for a text generation.

Source code in horde_sdk/generation_parameters/text/object_models.py
class BasicTextGenerationParameters(BasicTextGenerationParametersTemplate):  # TODO: Non-AI-Horde specific constraints
    """Represents the common bare-minimum parameters for a text generation."""

    model_config = get_default_frozen_model_config_dict()

    model: str
    """The model to use for the generation."""

    prompt: str  # pyright: ignore[reportGeneralTypeIssues, reportIncompatibleVariableOverride]
    """The prompt to use for the generation."""

model_config class-attribute instance-attribute

model_config = get_default_frozen_model_config_dict()

model instance-attribute

model: str

The model to use for the generation.

prompt instance-attribute

prompt: str

The prompt to use for the generation.

SCHEMA_VERSION class-attribute

SCHEMA_VERSION: str = '1.0'

Most recent schema version for this payload.

LEGACY_SCHEMA_VERSION class-attribute

LEGACY_SCHEMA_VERSION: str = '1.0'

Oldest schema version supported for deserialization when unspecified.

schema_version class-attribute instance-attribute

schema_version: str = Field(
    default="",
    description="Schema version recorded when the payload was serialized.",
)

underlying_generation_scheme class-attribute instance-attribute

underlying_generation_scheme: (
    UNDERLYING_GENERATION_SCHEME
) = MODEL

See :attr:ComposedParameterSetBase.underlying_generation_scheme for more information.

model_baseline class-attribute instance-attribute

model_baseline: str | None = None

soft_prompt class-attribute instance-attribute

soft_prompt: str | None = None

The soft prompt to use for the generation.

max_context_length class-attribute instance-attribute

max_context_length: int | None = Field(
    default=None, ge=80, le=32000
)

Maximum number of tokens to send to the model.

max_length class-attribute instance-attribute

max_length: int | None = Field(default=None, ge=16, le=1024)

Number of tokens to generate.

stop_sequence class-attribute instance-attribute

stop_sequence: list[str] | None = None

The stop sequences to use for the generation.

temperature class-attribute instance-attribute

temperature: float | None = Field(
    default=None, ge=0.0, le=5.0
)

Temperature value.

dynamic_temp_exponent class-attribute instance-attribute

dynamic_temp_exponent: float | None = Field(
    default=None, ge=0.0, le=5.0
)

Dynamic temperature exponent value.

dynamic_temp_range class-attribute instance-attribute

dynamic_temp_range: float | None = Field(
    default=None, ge=0.0, le=5.0
)

Dynamic temperature range value.

tfs class-attribute instance-attribute

tfs: float | None = Field(default=None, ge=0.0, le=1.0)

Tail free sampling value.

typical class-attribute instance-attribute

typical: float | None = Field(default=None, ge=0.0, le=1.0)

Typical sampling value.

sampler_order class-attribute instance-attribute

sampler_order: list[int] | None = None

The sampler order to use for the generation.

smoothing_factor class-attribute instance-attribute

smoothing_factor: float | None = Field(
    default=None, ge=0.0, le=10.0
)

Quadratic sampling value.

top_a class-attribute instance-attribute

top_a: float | None = Field(default=None, ge=0.0, le=1.0)

Top-a sampling value.

top_k class-attribute instance-attribute

top_k: int | None = Field(default=None, ge=0, le=100)

Top-k sampling value.

top_p class-attribute instance-attribute

top_p: float | None = Field(default=None, ge=0.001, le=1.0)

Top-p sampling value.

min_p class-attribute instance-attribute

min_p: float | None = Field(default=None, ge=0.0, le=1.0)

Min-p sampling value.

rep_pen class-attribute instance-attribute

rep_pen: float | None = Field(default=None, ge=1.0, le=3.0)

Base repetition penalty value.

rep_pen_range class-attribute instance-attribute

rep_pen_range: int | None = Field(
    default=None, ge=0, le=4096
)

Repetition penalty range.

rep_pen_slope class-attribute instance-attribute

rep_pen_slope: float | None = Field(
    default=None, ge=0.0, le=10.0
)

Repetition penalty slope.

current_schema_version classmethod

current_schema_version() -> str

Return the canonical schema version for newly created instances.

Source code in horde_sdk/generation_parameters/generic/__init__.py
@classmethod
def current_schema_version(cls) -> str:
    """Return the canonical schema version for newly created instances."""
    return cls.SCHEMA_VERSION

legacy_schema_version classmethod

legacy_schema_version() -> str

Return the version assumed for pre-metadata payloads.

Source code in horde_sdk/generation_parameters/generic/__init__.py
@classmethod
def legacy_schema_version(cls) -> str:
    """Return the version assumed for pre-metadata payloads."""
    return getattr(cls, "LEGACY_SCHEMA_VERSION", cls.SCHEMA_VERSION)

TextGenerationParametersTemplate

Bases: CompositeParametersBase

Represents the parameters for a text generation.

Source code in horde_sdk/generation_parameters/text/object_models.py
class TextGenerationParametersTemplate(CompositeParametersBase):
    """Represents the parameters for a text generation."""

    base_params: BasicTextGenerationParametersTemplate | None = None
    """The basic text generation parameters for the generation."""

    format_params: BasicTextGenerationFormatParameters | None = None
    """The text generation formatting parameters."""

    @override
    def get_number_expected_results(self) -> int:
        """Return the number of expected results for this parameter set.

        Returns:
            int: The number of expected results.
        """
        return 1

    def to_parameters(
        self,
        *,
        base_param_updates: BasicTextGenerationParametersTemplate | None = None,
        result_ids: Sequence[ID_TYPES] | None = None,
        allocator: ResultIdAllocator | None = None,
        seed: str = "text",
    ) -> TextGenerationParameters:
        """Convert this template into concrete text generation parameters."""
        base_params = self.base_params
        if base_params is None:
            raise ValueError("Text generation templates must define base_params before conversion.")

        overrides: dict[str, object] | None = None
        if base_param_updates:
            overrides = {
                "base_params": base_params.model_copy(update=base_param_updates.model_dump(exclude_none=True)),
            }

        def _inject_base_params_into_fingerprint(
            finalization: TemplateFinalization[Self],
            fingerprint_payload: dict[str, object],
        ) -> None:
            fingerprint_base_params = finalization.template.base_params
            if fingerprint_base_params is None:
                raise ValueError("Text generation templates must define base_params before conversion.")
            fingerprint_payload["base_params"] = fingerprint_base_params.model_dump(exclude_none=False)

        finalization = finalize_template_for_parameters(
            self,
            overrides=overrides,
            exclude_none=False,
            fingerprint_exclude_fields=("result_ids",),
            fingerprint_transform=_inject_base_params_into_fingerprint,
        )

        finalized_template = finalization.template
        resolved_base_params = finalized_template.base_params
        if resolved_base_params is None:
            raise ValueError("Text generation templates must define base_params before conversion.")

        resolved_result_ids = resolve_result_ids_from_payload(
            explicit_ids=result_ids,
            payload_value=finalization.payload.get("result_ids"),
            count=1,
            allocator=allocator,
            seed=seed,
            fingerprint=finalization.fingerprint,
        )

        concrete_base_params = BasicTextGenerationParameters.model_validate(
            resolved_base_params,
            from_attributes=True,
        )

        parameter_payload = finalized_template.model_copy(
            update={
                "base_params": concrete_base_params,
                "result_ids": resolved_result_ids,
            },
        )

        return TextGenerationParameters.model_validate(
            parameter_payload,
            from_attributes=True,
        )

base_params class-attribute instance-attribute

base_params: (
    BasicTextGenerationParametersTemplate | None
) = None

The basic text generation parameters for the generation.

format_params class-attribute instance-attribute

format_params: (
    BasicTextGenerationFormatParameters | None
) = None

The text generation formatting parameters.

SCHEMA_VERSION class-attribute

SCHEMA_VERSION: str = '1.0'

Most recent schema version for this payload.

LEGACY_SCHEMA_VERSION class-attribute

LEGACY_SCHEMA_VERSION: str = '1.0'

Oldest schema version supported for deserialization when unspecified.

schema_version class-attribute instance-attribute

schema_version: str = Field(
    default="",
    description="Schema version recorded when the payload was serialized.",
)

model_config class-attribute instance-attribute

model_config = ConfigDict(
    use_attribute_docstrings=True,
    from_attributes=True,
    arbitrary_types_allowed=True,
)

underlying_generation_scheme class-attribute instance-attribute

underlying_generation_scheme: (
    UNDERLYING_GENERATION_SCHEME | None
) = None

The underlying method the generation uses to produce results.

Note that this refers only to the top-level generation itself. Component parameters may contain their own underlying generation schemes. For example, for stable diffusion image generation, this would always be MODEL even if some of the contained components use another scheme such as MODEL_FROM_SERVICE or NON_MODEL_ALGORITHM.

  • If the top-level generation is model-based, this should be set to MODEL.
  • If the top-level generation uses an outside service to produce results, this should be set to MODEL_FROM_SERVICE.
  • If the top-level generation does not use a generative model and instead uses a "traditional" algorithm, this should be set to NON_MODEL_ALGORITHM.

get_number_expected_results

get_number_expected_results() -> int

Return the number of expected results for this parameter set.

Returns:

  • int ( int ) –

    The number of expected results.

Source code in horde_sdk/generation_parameters/text/object_models.py
@override
def get_number_expected_results(self) -> int:
    """Return the number of expected results for this parameter set.

    Returns:
        int: The number of expected results.
    """
    return 1

to_parameters

to_parameters(
    *,
    base_param_updates: (
        BasicTextGenerationParametersTemplate | None
    ) = None,
    result_ids: Sequence[ID_TYPES] | None = None,
    allocator: ResultIdAllocator | None = None,
    seed: str = "text"
) -> TextGenerationParameters

Convert this template into concrete text generation parameters.

Source code in horde_sdk/generation_parameters/text/object_models.py
def to_parameters(
    self,
    *,
    base_param_updates: BasicTextGenerationParametersTemplate | None = None,
    result_ids: Sequence[ID_TYPES] | None = None,
    allocator: ResultIdAllocator | None = None,
    seed: str = "text",
) -> TextGenerationParameters:
    """Convert this template into concrete text generation parameters."""
    base_params = self.base_params
    if base_params is None:
        raise ValueError("Text generation templates must define base_params before conversion.")

    overrides: dict[str, object] | None = None
    if base_param_updates:
        overrides = {
            "base_params": base_params.model_copy(update=base_param_updates.model_dump(exclude_none=True)),
        }

    def _inject_base_params_into_fingerprint(
        finalization: TemplateFinalization[Self],
        fingerprint_payload: dict[str, object],
    ) -> None:
        fingerprint_base_params = finalization.template.base_params
        if fingerprint_base_params is None:
            raise ValueError("Text generation templates must define base_params before conversion.")
        fingerprint_payload["base_params"] = fingerprint_base_params.model_dump(exclude_none=False)

    finalization = finalize_template_for_parameters(
        self,
        overrides=overrides,
        exclude_none=False,
        fingerprint_exclude_fields=("result_ids",),
        fingerprint_transform=_inject_base_params_into_fingerprint,
    )

    finalized_template = finalization.template
    resolved_base_params = finalized_template.base_params
    if resolved_base_params is None:
        raise ValueError("Text generation templates must define base_params before conversion.")

    resolved_result_ids = resolve_result_ids_from_payload(
        explicit_ids=result_ids,
        payload_value=finalization.payload.get("result_ids"),
        count=1,
        allocator=allocator,
        seed=seed,
        fingerprint=finalization.fingerprint,
    )

    concrete_base_params = BasicTextGenerationParameters.model_validate(
        resolved_base_params,
        from_attributes=True,
    )

    parameter_payload = finalized_template.model_copy(
        update={
            "base_params": concrete_base_params,
            "result_ids": resolved_result_ids,
        },
    )

    return TextGenerationParameters.model_validate(
        parameter_payload,
        from_attributes=True,
    )

current_schema_version classmethod

current_schema_version() -> str

Return the canonical schema version for newly created instances.

Source code in horde_sdk/generation_parameters/generic/__init__.py
@classmethod
def current_schema_version(cls) -> str:
    """Return the canonical schema version for newly created instances."""
    return cls.SCHEMA_VERSION

legacy_schema_version classmethod

legacy_schema_version() -> str

Return the version assumed for pre-metadata payloads.

Source code in horde_sdk/generation_parameters/generic/__init__.py
@classmethod
def legacy_schema_version(cls) -> str:
    """Return the version assumed for pre-metadata payloads."""
    return getattr(cls, "LEGACY_SCHEMA_VERSION", cls.SCHEMA_VERSION)

TextGenerationParameters

Bases: TextGenerationParametersTemplate

Represents the common bare-minium parameters for a text generation.

Source code in horde_sdk/generation_parameters/text/object_models.py
class TextGenerationParameters(TextGenerationParametersTemplate):
    """Represents the common bare-minium parameters for a text generation."""

    result_ids: list[ID_TYPES]
    """The generation IDs to assign to the resulting discrete generations."""

    base_params: BasicTextGenerationParameters
    """The basic text generation parameters for the generation."""

result_ids instance-attribute

result_ids: list[ID_TYPES]

The generation IDs to assign to the resulting discrete generations.

base_params instance-attribute

base_params: BasicTextGenerationParameters

The basic text generation parameters for the generation.

SCHEMA_VERSION class-attribute

SCHEMA_VERSION: str = '1.0'

Most recent schema version for this payload.

LEGACY_SCHEMA_VERSION class-attribute

LEGACY_SCHEMA_VERSION: str = '1.0'

Oldest schema version supported for deserialization when unspecified.

schema_version class-attribute instance-attribute

schema_version: str = Field(
    default="",
    description="Schema version recorded when the payload was serialized.",
)

model_config class-attribute instance-attribute

model_config = ConfigDict(
    use_attribute_docstrings=True,
    from_attributes=True,
    arbitrary_types_allowed=True,
)

underlying_generation_scheme class-attribute instance-attribute

underlying_generation_scheme: (
    UNDERLYING_GENERATION_SCHEME | None
) = None

The underlying method the generation uses to produce results.

Note that this refers only to the top-level generation itself. Component parameters may contain their own underlying generation schemes. For example, for stable diffusion image generation, this would always be MODEL even if some of the contained components use another scheme such as MODEL_FROM_SERVICE or NON_MODEL_ALGORITHM.

  • If the top-level generation is model-based, this should be set to MODEL.
  • If the top-level generation uses an outside service to produce results, this should be set to MODEL_FROM_SERVICE.
  • If the top-level generation does not use a generative model and instead uses a "traditional" algorithm, this should be set to NON_MODEL_ALGORITHM.

format_params class-attribute instance-attribute

format_params: (
    BasicTextGenerationFormatParameters | None
) = None

The text generation formatting parameters.

current_schema_version classmethod

current_schema_version() -> str

Return the canonical schema version for newly created instances.

Source code in horde_sdk/generation_parameters/generic/__init__.py
@classmethod
def current_schema_version(cls) -> str:
    """Return the canonical schema version for newly created instances."""
    return cls.SCHEMA_VERSION

legacy_schema_version classmethod

legacy_schema_version() -> str

Return the version assumed for pre-metadata payloads.

Source code in horde_sdk/generation_parameters/generic/__init__.py
@classmethod
def legacy_schema_version(cls) -> str:
    """Return the version assumed for pre-metadata payloads."""
    return getattr(cls, "LEGACY_SCHEMA_VERSION", cls.SCHEMA_VERSION)

get_number_expected_results

get_number_expected_results() -> int

Return the number of expected results for this parameter set.

Returns:

  • int ( int ) –

    The number of expected results.

Source code in horde_sdk/generation_parameters/text/object_models.py
@override
def get_number_expected_results(self) -> int:
    """Return the number of expected results for this parameter set.

    Returns:
        int: The number of expected results.
    """
    return 1

to_parameters

to_parameters(
    *,
    base_param_updates: (
        BasicTextGenerationParametersTemplate | None
    ) = None,
    result_ids: Sequence[ID_TYPES] | None = None,
    allocator: ResultIdAllocator | None = None,
    seed: str = "text"
) -> TextGenerationParameters

Convert this template into concrete text generation parameters.

Source code in horde_sdk/generation_parameters/text/object_models.py
def to_parameters(
    self,
    *,
    base_param_updates: BasicTextGenerationParametersTemplate | None = None,
    result_ids: Sequence[ID_TYPES] | None = None,
    allocator: ResultIdAllocator | None = None,
    seed: str = "text",
) -> TextGenerationParameters:
    """Convert this template into concrete text generation parameters."""
    base_params = self.base_params
    if base_params is None:
        raise ValueError("Text generation templates must define base_params before conversion.")

    overrides: dict[str, object] | None = None
    if base_param_updates:
        overrides = {
            "base_params": base_params.model_copy(update=base_param_updates.model_dump(exclude_none=True)),
        }

    def _inject_base_params_into_fingerprint(
        finalization: TemplateFinalization[Self],
        fingerprint_payload: dict[str, object],
    ) -> None:
        fingerprint_base_params = finalization.template.base_params
        if fingerprint_base_params is None:
            raise ValueError("Text generation templates must define base_params before conversion.")
        fingerprint_payload["base_params"] = fingerprint_base_params.model_dump(exclude_none=False)

    finalization = finalize_template_for_parameters(
        self,
        overrides=overrides,
        exclude_none=False,
        fingerprint_exclude_fields=("result_ids",),
        fingerprint_transform=_inject_base_params_into_fingerprint,
    )

    finalized_template = finalization.template
    resolved_base_params = finalized_template.base_params
    if resolved_base_params is None:
        raise ValueError("Text generation templates must define base_params before conversion.")

    resolved_result_ids = resolve_result_ids_from_payload(
        explicit_ids=result_ids,
        payload_value=finalization.payload.get("result_ids"),
        count=1,
        allocator=allocator,
        seed=seed,
        fingerprint=finalization.fingerprint,
    )

    concrete_base_params = BasicTextGenerationParameters.model_validate(
        resolved_base_params,
        from_attributes=True,
    )

    parameter_payload = finalized_template.model_copy(
        update={
            "base_params": concrete_base_params,
            "result_ids": resolved_result_ids,
        },
    )

    return TextGenerationParameters.model_validate(
        parameter_payload,
        from_attributes=True,
    )

KoboldAITextGenerationParameters

Bases: TextGenerationParameters

Represents koboldAI text generation parameters.

Source code in horde_sdk/generation_parameters/text/object_models.py
class KoboldAITextGenerationParameters(TextGenerationParameters):
    """Represents koboldAI text generation parameters."""

    use_default_bad_words_ids: bool | None = None
    """When True, uses the default KoboldAI bad word IDs."""

use_default_bad_words_ids class-attribute instance-attribute

use_default_bad_words_ids: bool | None = None

When True, uses the default KoboldAI bad word IDs.

SCHEMA_VERSION class-attribute

SCHEMA_VERSION: str = '1.0'

Most recent schema version for this payload.

LEGACY_SCHEMA_VERSION class-attribute

LEGACY_SCHEMA_VERSION: str = '1.0'

Oldest schema version supported for deserialization when unspecified.

schema_version class-attribute instance-attribute

schema_version: str = Field(
    default="",
    description="Schema version recorded when the payload was serialized.",
)

model_config class-attribute instance-attribute

model_config = ConfigDict(
    use_attribute_docstrings=True,
    from_attributes=True,
    arbitrary_types_allowed=True,
)

underlying_generation_scheme class-attribute instance-attribute

underlying_generation_scheme: (
    UNDERLYING_GENERATION_SCHEME | None
) = None

The underlying method the generation uses to produce results.

Note that this refers only to the top-level generation itself. Component parameters may contain their own underlying generation schemes. For example, for stable diffusion image generation, this would always be MODEL even if some of the contained components use another scheme such as MODEL_FROM_SERVICE or NON_MODEL_ALGORITHM.

  • If the top-level generation is model-based, this should be set to MODEL.
  • If the top-level generation uses an outside service to produce results, this should be set to MODEL_FROM_SERVICE.
  • If the top-level generation does not use a generative model and instead uses a "traditional" algorithm, this should be set to NON_MODEL_ALGORITHM.

base_params instance-attribute

base_params: BasicTextGenerationParameters

The basic text generation parameters for the generation.

format_params class-attribute instance-attribute

format_params: (
    BasicTextGenerationFormatParameters | None
) = None

The text generation formatting parameters.

result_ids instance-attribute

result_ids: list[ID_TYPES]

The generation IDs to assign to the resulting discrete generations.

current_schema_version classmethod

current_schema_version() -> str

Return the canonical schema version for newly created instances.

Source code in horde_sdk/generation_parameters/generic/__init__.py
@classmethod
def current_schema_version(cls) -> str:
    """Return the canonical schema version for newly created instances."""
    return cls.SCHEMA_VERSION

legacy_schema_version classmethod

legacy_schema_version() -> str

Return the version assumed for pre-metadata payloads.

Source code in horde_sdk/generation_parameters/generic/__init__.py
@classmethod
def legacy_schema_version(cls) -> str:
    """Return the version assumed for pre-metadata payloads."""
    return getattr(cls, "LEGACY_SCHEMA_VERSION", cls.SCHEMA_VERSION)

get_number_expected_results

get_number_expected_results() -> int

Return the number of expected results for this parameter set.

Returns:

  • int ( int ) –

    The number of expected results.

Source code in horde_sdk/generation_parameters/text/object_models.py
@override
def get_number_expected_results(self) -> int:
    """Return the number of expected results for this parameter set.

    Returns:
        int: The number of expected results.
    """
    return 1

to_parameters

to_parameters(
    *,
    base_param_updates: (
        BasicTextGenerationParametersTemplate | None
    ) = None,
    result_ids: Sequence[ID_TYPES] | None = None,
    allocator: ResultIdAllocator | None = None,
    seed: str = "text"
) -> TextGenerationParameters

Convert this template into concrete text generation parameters.

Source code in horde_sdk/generation_parameters/text/object_models.py
def to_parameters(
    self,
    *,
    base_param_updates: BasicTextGenerationParametersTemplate | None = None,
    result_ids: Sequence[ID_TYPES] | None = None,
    allocator: ResultIdAllocator | None = None,
    seed: str = "text",
) -> TextGenerationParameters:
    """Convert this template into concrete text generation parameters."""
    base_params = self.base_params
    if base_params is None:
        raise ValueError("Text generation templates must define base_params before conversion.")

    overrides: dict[str, object] | None = None
    if base_param_updates:
        overrides = {
            "base_params": base_params.model_copy(update=base_param_updates.model_dump(exclude_none=True)),
        }

    def _inject_base_params_into_fingerprint(
        finalization: TemplateFinalization[Self],
        fingerprint_payload: dict[str, object],
    ) -> None:
        fingerprint_base_params = finalization.template.base_params
        if fingerprint_base_params is None:
            raise ValueError("Text generation templates must define base_params before conversion.")
        fingerprint_payload["base_params"] = fingerprint_base_params.model_dump(exclude_none=False)

    finalization = finalize_template_for_parameters(
        self,
        overrides=overrides,
        exclude_none=False,
        fingerprint_exclude_fields=("result_ids",),
        fingerprint_transform=_inject_base_params_into_fingerprint,
    )

    finalized_template = finalization.template
    resolved_base_params = finalized_template.base_params
    if resolved_base_params is None:
        raise ValueError("Text generation templates must define base_params before conversion.")

    resolved_result_ids = resolve_result_ids_from_payload(
        explicit_ids=result_ids,
        payload_value=finalization.payload.get("result_ids"),
        count=1,
        allocator=allocator,
        seed=seed,
        fingerprint=finalization.fingerprint,
    )

    concrete_base_params = BasicTextGenerationParameters.model_validate(
        resolved_base_params,
        from_attributes=True,
    )

    parameter_payload = finalized_template.model_copy(
        update={
            "base_params": concrete_base_params,
            "result_ids": resolved_result_ids,
        },
    )

    return TextGenerationParameters.model_validate(
        parameter_payload,
        from_attributes=True,
    )