# Copyright (c) Microsoft. All rights reserved.
# WARNING: This is an auto-generated file. DO NOT EDIT THIS FILE DIRECTLY.


from dataclasses import dataclass, field
from typing import Any, ClassVar, Optional

from ._context import LoadContext, SaveContext


@dataclass
class ModelOptions:
    """Options for configuring the behavior of the AI model.
    `kind` is a required property here, but this section can accept additional via options.

    Attributes
    ----------
    frequencyPenalty : Optional[float]
        The frequency penalty to apply to the model's output
    maxOutputTokens : Optional[int]
        The maximum number of tokens to generate in the output
    presencePenalty : Optional[float]
        The presence penalty to apply to the model's output
    seed : Optional[int]
        A random seed for deterministic output
    temperature : Optional[float]
        The temperature to use for sampling
    topK : Optional[int]
        The top-K sampling value
    topP : Optional[float]
        The top-P sampling value
    stopSequences : list[str]
        Stop sequences to end generation
    allowMultipleToolCalls : Optional[bool]
        Whether to allow multiple tool calls in a single response
    additionalProperties : Optional[dict[str, Any]]
        Additional custom properties for model options
    """

    _shorthand_property: ClassVar[Optional[str]] = None

    frequencyPenalty: Optional[float] = None
    maxOutputTokens: Optional[int] = None
    presencePenalty: Optional[float] = None
    seed: Optional[int] = None
    temperature: Optional[float] = None
    topK: Optional[int] = None
    topP: Optional[float] = None
    stopSequences: list[str] = field(default_factory=list)
    allowMultipleToolCalls: Optional[bool] = None
    additionalProperties: Optional[dict[str, Any]] = None

    @staticmethod
    def load(data: Any, context: Optional[LoadContext] = None) -> "ModelOptions":
        """Load a ModelOptions instance.
        Args:
            data (Any): The data to load the instance from.
            context (Optional[LoadContext]): Optional context with pre/post processing callbacks.
        Returns:
            ModelOptions: The loaded ModelOptions instance.

        """

        if context is not None:
            data = context.process_input(data)

        if not isinstance(data, dict):
            raise ValueError(f"Invalid data for ModelOptions: {data}")

        # create new instance
        instance = ModelOptions()

        if data is not None and "frequencyPenalty" in data:
            instance.frequencyPenalty = data["frequencyPenalty"]
        if data is not None and "maxOutputTokens" in data:
            instance.maxOutputTokens = data["maxOutputTokens"]
        if data is not None and "presencePenalty" in data:
            instance.presencePenalty = data["presencePenalty"]
        if data is not None and "seed" in data:
            instance.seed = data["seed"]
        if data is not None and "temperature" in data:
            instance.temperature = data["temperature"]
        if data is not None and "topK" in data:
            instance.topK = data["topK"]
        if data is not None and "topP" in data:
            instance.topP = data["topP"]
        if data is not None and "stopSequences" in data:
            instance.stopSequences = data["stopSequences"]
        if data is not None and "allowMultipleToolCalls" in data:
            instance.allowMultipleToolCalls = data["allowMultipleToolCalls"]
        if data is not None and "additionalProperties" in data:
            instance.additionalProperties = data["additionalProperties"]
        if context is not None:
            instance = context.process_output(instance)
        return instance

    def save(self, context: Optional[SaveContext] = None) -> dict[str, Any]:
        """Save the ModelOptions instance to a dictionary.
        Args:
            context (Optional[SaveContext]): Optional context with pre/post processing callbacks.
        Returns:
            dict[str, Any]: The dictionary representation of this instance.

        """
        obj = self
        if context is not None:
            obj = context.process_object(obj)

        result: dict[str, Any] = {}

        if obj.frequencyPenalty is not None:
            result["frequencyPenalty"] = obj.frequencyPenalty
        if obj.maxOutputTokens is not None:
            result["maxOutputTokens"] = obj.maxOutputTokens
        if obj.presencePenalty is not None:
            result["presencePenalty"] = obj.presencePenalty
        if obj.seed is not None:
            result["seed"] = obj.seed
        if obj.temperature is not None:
            result["temperature"] = obj.temperature
        if obj.topK is not None:
            result["topK"] = obj.topK
        if obj.topP is not None:
            result["topP"] = obj.topP
        if obj.stopSequences is not None:
            result["stopSequences"] = obj.stopSequences
        if obj.allowMultipleToolCalls is not None:
            result["allowMultipleToolCalls"] = obj.allowMultipleToolCalls
        if obj.additionalProperties is not None:
            result["additionalProperties"] = obj.additionalProperties

        if context is not None:
            result = context.process_dict(result)
        return result

    def to_yaml(self, context: Optional[SaveContext] = None) -> str:
        """Convert the ModelOptions instance to a YAML string.
        Args:
            context (Optional[SaveContext]): Optional context with pre/post processing callbacks.
        Returns:
            str: The YAML string representation of this instance.

        """
        if context is None:
            context = SaveContext()
        return context.to_yaml(self.save(context))

    def to_json(self, context: Optional[SaveContext] = None, indent: int = 2) -> str:
        """Convert the ModelOptions instance to a JSON string.
        Args:
            context (Optional[SaveContext]): Optional context with pre/post processing callbacks.
            indent (int): Number of spaces for indentation. Defaults to 2.
        Returns:
            str: The JSON string representation of this instance.

        """
        if context is None:
            context = SaveContext()
        return context.to_json(self.save(context), indent)
