# coding: utf-8

"""
    HCX API

    The HCX REST API. Please see https://api.ncloud-docs.com/docs/ai-naver-clovastudio-summary for more details.

    The version of the OpenAPI document: 24.1.5
    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 pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing_extensions import Annotated
from typing import Optional, Set
from typing_extensions import Self

class CreateCompletionRequest(BaseModel):
    """
    CreateCompletionRequest
    """ # noqa: E501
    text: StrictStr
    temperature: Optional[Union[Annotated[float, Field(le=1, strict=True, ge=0)], Annotated[int, Field(le=1, strict=True, ge=0)]]] = 0.5
    top_k: Optional[Annotated[int, Field(le=128, strict=True, ge=0)]] = Field(default=0, alias="topK")
    top_p: Optional[Union[Annotated[float, Field(le=1, strict=True, ge=0)], Annotated[int, Field(le=1, strict=True, ge=0)]]] = Field(default=0.8, alias="topP")
    repeat_penalty: Optional[Union[Annotated[float, Field(le=10, strict=True, ge=0)], Annotated[int, Field(le=10, strict=True, ge=0)]]] = Field(default=5, alias="repeatPenalty")
    stop_before: Optional[List[StrictStr]] = Field(default=None, alias="stopBefore")
    max_tokens: Optional[Annotated[int, Field(le=2048, strict=True, ge=0)]] = Field(default=32, alias="maxTokens")
    include_tokens: Optional[StrictBool] = Field(default=False, alias="includeTokens")
    start: Optional[StrictStr] = None
    restart: Optional[StrictStr] = None
    include_ai_filters: Optional[StrictBool] = Field(default=True, alias="includeAiFilters")
    stream: Optional[StrictBool] = False
    __properties: ClassVar[List[str]] = ["text", "temperature", "topK", "topP", "repeatPenalty", "stopBefore", "maxTokens", "includeTokens", "start", "restart", "includeAiFilters", "stream"]

    model_config = ConfigDict(
        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) -> Optional[Self]:
        """Create an instance of CreateCompletionRequest 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.
        """
        excluded_fields: Set[str] = set([
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # set to None if temperature (nullable) is None
        # and model_fields_set contains the field
        if self.temperature is None and "temperature" in self.model_fields_set:
            _dict['temperature'] = None

        # set to None if top_k (nullable) is None
        # and model_fields_set contains the field
        if self.top_k is None and "top_k" in self.model_fields_set:
            _dict['topK'] = None

        # set to None if top_p (nullable) is None
        # and model_fields_set contains the field
        if self.top_p is None and "top_p" in self.model_fields_set:
            _dict['topP'] = None

        # set to None if repeat_penalty (nullable) is None
        # and model_fields_set contains the field
        if self.repeat_penalty is None and "repeat_penalty" in self.model_fields_set:
            _dict['repeatPenalty'] = None

        # set to None if stop_before (nullable) is None
        # and model_fields_set contains the field
        if self.stop_before is None and "stop_before" in self.model_fields_set:
            _dict['stopBefore'] = None

        # set to None if max_tokens (nullable) is None
        # and model_fields_set contains the field
        if self.max_tokens is None and "max_tokens" in self.model_fields_set:
            _dict['maxTokens'] = None

        # set to None if include_tokens (nullable) is None
        # and model_fields_set contains the field
        if self.include_tokens is None and "include_tokens" in self.model_fields_set:
            _dict['includeTokens'] = None

        # set to None if start (nullable) is None
        # and model_fields_set contains the field
        if self.start is None and "start" in self.model_fields_set:
            _dict['start'] = None

        # set to None if restart (nullable) is None
        # and model_fields_set contains the field
        if self.restart is None and "restart" in self.model_fields_set:
            _dict['restart'] = None

        # set to None if include_ai_filters (nullable) is None
        # and model_fields_set contains the field
        if self.include_ai_filters is None and "include_ai_filters" in self.model_fields_set:
            _dict['includeAiFilters'] = None

        # set to None if stream (nullable) is None
        # and model_fields_set contains the field
        if self.stream is None and "stream" in self.model_fields_set:
            _dict['stream'] = None

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of CreateCompletionRequest from a dict"""
        if obj is None:
            return None

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

        _obj = cls.model_validate({
            "text": obj.get("text"),
            "temperature": obj.get("temperature") if obj.get("temperature") is not None else 0.5,
            "topK": obj.get("topK") if obj.get("topK") is not None else 0,
            "topP": obj.get("topP") if obj.get("topP") is not None else 0.8,
            "repeatPenalty": obj.get("repeatPenalty") if obj.get("repeatPenalty") is not None else 5,
            "stopBefore": obj.get("stopBefore"),
            "maxTokens": obj.get("maxTokens") if obj.get("maxTokens") is not None else 32,
            "includeTokens": obj.get("includeTokens") if obj.get("includeTokens") is not None else False,
            "start": obj.get("start"),
            "restart": obj.get("restart"),
            "includeAiFilters": obj.get("includeAiFilters") if obj.get("includeAiFilters") is not None else True,
            "stream": obj.get("stream") if obj.get("stream") is not None else False
        })
        return _obj


