# coding: utf-8

"""
    ollm-api

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    The version of the OpenAPI document: 0.1
    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, StrictBool, StrictInt, StrictStr
from pydantic import Field
from typing_extensions import Annotated
try:
    from typing import Self
except ImportError:
    from typing_extensions import Self

class CreateCompletionRequest(BaseModel):
    """
    CreateCompletionRequest
    """ # noqa: E501
    best_of: Optional[StrictInt] = None
    echo: Optional[StrictBool] = None
    frequency_penalty: Optional[Union[Annotated[float, Field(le=2.0, strict=True, ge=-2.0)], Annotated[int, Field(le=2, strict=True, ge=-2)]]] = None
    logit_bias: Optional[Any] = Field(default=None, description="Modify the likelihood of specified tokens appearing in the completion.")
    logprobs: Optional[StrictInt] = None
    max_tokens: Optional[StrictInt] = None
    model: StrictStr = Field(description="Model name to use for completion.")
    n: Optional[Annotated[int, Field(strict=True, ge=1)]] = None
    presence_penalty: Optional[Union[Annotated[float, Field(le=2.0, strict=True, ge=-2.0)], Annotated[int, Field(le=2, strict=True, ge=-2)]]] = None
    prompt: Optional[StrictStr]
    repetition_penalty: Optional[Union[Annotated[float, Field(strict=True, ge=0.0)], Annotated[int, Field(strict=True, ge=0)]]] = None
    seed: Optional[StrictInt] = None
    stop: Optional[StrictStr] = None
    stream: Optional[StrictBool] = None
    suffix: Optional[StrictStr] = None
    temperature: Optional[Union[Annotated[float, Field(le=2.0, strict=True, ge=0.0)], Annotated[int, Field(le=2, strict=True, ge=0)]]] = None
    top_p: Optional[Union[Annotated[float, Field(le=1.0, strict=True)], Annotated[int, Field(le=1, strict=True)]]] = None
    user: Optional[StrictStr] = None
    __properties: ClassVar[List[str]] = ["best_of", "echo", "frequency_penalty", "logit_bias", "logprobs", "max_tokens", "model", "n", "presence_penalty", "prompt", "repetition_penalty", "seed", "stop", "stream", "suffix", "temperature", "top_p", "user"]

    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 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.
        """
        _dict = self.model_dump(
            by_alias=True,
            exclude={
            },
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of logit_bias
        if self.logit_bias:
            _dict['logit_bias'] = self.logit_bias.to_dict()
        # set to None if best_of (nullable) is None
        # and model_fields_set contains the field
        if self.best_of is None and "best_of" in self.model_fields_set:
            _dict['best_of'] = None

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

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

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

        # set to None if logprobs (nullable) is None
        # and model_fields_set contains the field
        if self.logprobs is None and "logprobs" in self.model_fields_set:
            _dict['logprobs'] = 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['max_tokens'] = None

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

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

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

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

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

        # set to None if stop (nullable) is None
        # and model_fields_set contains the field
        if self.stop is None and "stop" in self.model_fields_set:
            _dict['stop'] = 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

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

        # 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_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['top_p'] = None

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Dict) -> 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({
            "best_of": obj.get("best_of"),
            "echo": obj.get("echo"),
            "frequency_penalty": obj.get("frequency_penalty"),
            "logit_bias": AnyOf.from_dict(obj.get("logit_bias")) if obj.get("logit_bias") is not None else None,
            "logprobs": obj.get("logprobs"),
            "max_tokens": obj.get("max_tokens"),
            "model": obj.get("model"),
            "n": obj.get("n"),
            "presence_penalty": obj.get("presence_penalty"),
            "prompt": obj.get("prompt"),
            "repetition_penalty": obj.get("repetition_penalty"),
            "seed": obj.get("seed"),
            "stop": obj.get("stop"),
            "stream": obj.get("stream"),
            "suffix": obj.get("suffix"),
            "temperature": obj.get("temperature"),
            "top_p": obj.get("top_p"),
            "user": obj.get("user")
        })
        return _obj


