# coding: utf-8

"""
    Montelo

    Documentation for the Montelo API.

    The version of the OpenAPI document: 1.0
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations
import pprint
import re  # noqa: F401
import json


from typing import Any, ClassVar, Dict, List, Optional, Union
from pydantic import BaseModel, StrictFloat, StrictInt
from montelo.client.openapi_client.models.message_dto import MessageDto
from montelo.client.openapi_client.models.response_format_dto import ResponseFormatDto
from montelo.client.openapi_client.models.tool_dto import ToolDto
try:
    from typing import Self
except ImportError:
    from typing_extensions import Self

class InferenceInput(BaseModel):
    """
    InferenceInput
    """ # noqa: E501
    messages: List[MessageDto]
    tools: Optional[List[ToolDto]] = None
    max_tokens: Optional[Union[StrictFloat, StrictInt]] = None
    prompt_truncate_len: Optional[Union[StrictFloat, StrictInt]] = None
    temperature: Optional[Union[StrictFloat, StrictInt]] = None
    top_p: Optional[Union[StrictFloat, StrictInt]] = None
    top_k: Optional[Union[StrictFloat, StrictInt]] = None
    frequency_penalty: Optional[Union[StrictFloat, StrictInt]] = None
    presence_penalty: Optional[Union[StrictFloat, StrictInt]] = None
    n: Optional[Union[StrictFloat, StrictInt]] = None
    response_format: Optional[ResponseFormatDto] = None
    __properties: ClassVar[List[str]] = ["messages", "tools", "max_tokens", "prompt_truncate_len", "temperature", "top_p", "top_k", "frequency_penalty", "presence_penalty", "n", "response_format"]

    model_config = {
        "populate_by_name": True,
        "validate_assignment": True,
        "protected_namespaces": (),
    }


    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.model_dump(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> Self:
        """Create an instance of InferenceInput from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self) -> Dict[str, Any]:
        """Return the dictionary representation of the model using alias.

        This has the following differences from calling pydantic's
        `self.model_dump(by_alias=True)`:

        * `None` is only added to the output dict for nullable fields that
          were set at model initialization. Other fields with value `None`
          are ignored.
        """
        _dict = self.model_dump(
            by_alias=True,
            exclude={
            },
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of each item in messages (list)
        _items = []
        if self.messages:
            for _item in self.messages:
                if _item:
                    _items.append(_item.to_dict())
            _dict['messages'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in tools (list)
        _items = []
        if self.tools:
            for _item in self.tools:
                if _item:
                    _items.append(_item.to_dict())
            _dict['tools'] = _items
        # override the default output from pydantic by calling `to_dict()` of response_format
        if self.response_format:
            _dict['response_format'] = self.response_format.to_dict()
        return _dict

    @classmethod
    def from_dict(cls, obj: Dict) -> Self:
        """Create an instance of InferenceInput from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate({
            "messages": [MessageDto.from_dict(_item) for _item in obj.get("messages")] if obj.get("messages") is not None else None,
            "tools": [ToolDto.from_dict(_item) for _item in obj.get("tools")] if obj.get("tools") is not None else None,
            "max_tokens": obj.get("max_tokens"),
            "prompt_truncate_len": obj.get("prompt_truncate_len"),
            "temperature": obj.get("temperature"),
            "top_p": obj.get("top_p"),
            "top_k": obj.get("top_k"),
            "frequency_penalty": obj.get("frequency_penalty"),
            "presence_penalty": obj.get("presence_penalty"),
            "n": obj.get("n"),
            "response_format": ResponseFormatDto.from_dict(obj.get("response_format")) if obj.get("response_format") is not None else None
        })
        return _obj


