# coding: utf-8

"""
    FastAPI

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

    The version of the OpenAPI document: 0.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 Dict, List, Optional, Union
from pydantic.v1 import BaseModel, Field, StrictBool, StrictFloat, StrictInt, StrictStr, conlist
from clients.ollm.models.chat_completion_request_ext import ChatCompletionRequestExt
from clients.ollm.models.chat_message import ChatMessage
from clients.ollm.models.function import Function
from clients.ollm.models.function_call import FunctionCall
from clients.ollm.models.stop import Stop

class CreateChatCompletionRequest(BaseModel):
    """
    An OpenAI API compatible schema for a chat completion request.  See: https://platform.openai.com/docs/api-reference/chat/create for more information.  # noqa: E501
    """
    model: StrictStr = Field(...)
    messages: conlist(ChatMessage) = Field(...)
    functions: Optional[conlist(Function)] = None
    function_call: Optional[FunctionCall] = None
    temperature: Optional[Union[StrictFloat, StrictInt]] = 1.0
    top_p: Optional[Union[StrictFloat, StrictInt]] = 1.0
    n: Optional[StrictInt] = 1
    stream: Optional[StrictBool] = False
    stop: Optional[Stop] = None
    max_tokens: Optional[Union[StrictFloat, StrictInt]] = 262144
    presence_penalty: Optional[Union[StrictFloat, StrictInt]] = 0.0
    frequency_penalty: Optional[Union[StrictFloat, StrictInt]] = 0.0
    logit_bias: Optional[Dict[str, StrictStr]] = None
    user: Optional[StrictStr] = None
    octoai: Optional[ChatCompletionRequestExt] = None
    __properties = ["model", "messages", "functions", "function_call", "temperature", "top_p", "n", "stream", "stop", "max_tokens", "presence_penalty", "frequency_penalty", "logit_bias", "user", "octoai"]

    class Config:
        """Pydantic configuration"""
        allow_population_by_field_name = True
        validate_assignment = True

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

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        return json.dumps(self.to_dict())

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

    def to_dict(self):
        """Returns the dictionary representation of the model using alias"""
        _dict = self.dict(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 functions (list)
        _items = []
        if self.functions:
            for _item in self.functions:
                if _item:
                    _items.append(_item.to_dict())
            _dict['functions'] = _items
        # override the default output from pydantic by calling `to_dict()` of function_call
        if self.function_call:
            _dict['function_call'] = self.function_call.to_dict()
        # override the default output from pydantic by calling `to_dict()` of stop
        if self.stop:
            _dict['stop'] = self.stop.to_dict()
        # override the default output from pydantic by calling `to_dict()` of octoai
        if self.octoai:
            _dict['octoai'] = self.octoai.to_dict()
        return _dict

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

        if not isinstance(obj, dict):
            return CreateChatCompletionRequest.parse_obj(obj)

        _obj = CreateChatCompletionRequest.parse_obj({
            "model": obj.get("model"),
            "messages": [ChatMessage.from_dict(_item) for _item in obj.get("messages")] if obj.get("messages") is not None else None,
            "functions": [Function.from_dict(_item) for _item in obj.get("functions")] if obj.get("functions") is not None else None,
            "function_call": FunctionCall.from_dict(obj.get("function_call")) if obj.get("function_call") is not None else None,
            "temperature": obj.get("temperature") if obj.get("temperature") is not None else 1.0,
            "top_p": obj.get("top_p") if obj.get("top_p") is not None else 1.0,
            "n": obj.get("n") if obj.get("n") is not None else 1,
            "stream": obj.get("stream") if obj.get("stream") is not None else False,
            "stop": Stop.from_dict(obj.get("stop")) if obj.get("stop") is not None else None,
            "max_tokens": obj.get("max_tokens") if obj.get("max_tokens") is not None else 262144,
            "presence_penalty": obj.get("presence_penalty") if obj.get("presence_penalty") is not None else 0.0,
            "frequency_penalty": obj.get("frequency_penalty") if obj.get("frequency_penalty") is not None else 0.0,
            "logit_bias": obj.get("logit_bias"),
            "user": obj.get("user"),
            "octoai": ChatCompletionRequestExt.from_dict(obj.get("octoai")) if obj.get("octoai") is not None else None
        })
        return _obj


