|
| 1 | +# coding: utf-8 |
| 2 | + |
| 3 | +""" |
| 4 | + otari |
| 5 | +
|
| 6 | + Otari, an OpenAI-compatible LLM gateway with API key management |
| 7 | +
|
| 8 | + The version of the OpenAPI document: 0.0.0-dev |
| 9 | + Generated by OpenAPI Generator (https://openapi-generator.tech) |
| 10 | +
|
| 11 | + Do not edit the class manually. |
| 12 | +""" # noqa: E501 |
| 13 | + |
| 14 | + |
| 15 | +from __future__ import annotations |
| 16 | +from inspect import getfullargspec |
| 17 | +import json |
| 18 | +import pprint |
| 19 | +import re # noqa: F401 |
| 20 | +from pydantic import BaseModel, ConfigDict, Field, StrictStr, ValidationError, field_validator |
| 21 | +from typing import Any, Dict, Optional |
| 22 | +from typing import Union, Any, List, Set, TYPE_CHECKING, Optional, Dict |
| 23 | +from typing_extensions import Literal, Self |
| 24 | +from pydantic import Field |
| 25 | + |
| 26 | +CHATCOMPLETIONREQUESTTOOLSINNER_ANY_OF_SCHEMAS = ["Dict[str, object]"] |
| 27 | + |
| 28 | +class ChatCompletionRequestToolsInner(BaseModel): |
| 29 | + """ |
| 30 | + ChatCompletionRequestToolsInner |
| 31 | + """ |
| 32 | + |
| 33 | + # data type: Dict[str, object] |
| 34 | + anyof_schema_1_validator: Optional[Dict[str, Any]] = None |
| 35 | + # data type: Dict[str, object] |
| 36 | + anyof_schema_2_validator: Optional[Dict[str, Any]] = None |
| 37 | + if TYPE_CHECKING: |
| 38 | + actual_instance: Optional[Union[Dict[str, object]]] = None |
| 39 | + else: |
| 40 | + actual_instance: Any = None |
| 41 | + any_of_schemas: Set[str] = { "Dict[str, object]" } |
| 42 | + |
| 43 | + model_config = { |
| 44 | + "validate_assignment": True, |
| 45 | + "protected_namespaces": (), |
| 46 | + } |
| 47 | + |
| 48 | + def __init__(self, *args, **kwargs) -> None: |
| 49 | + if args: |
| 50 | + if len(args) > 1: |
| 51 | + raise ValueError("If a position argument is used, only 1 is allowed to set `actual_instance`") |
| 52 | + if kwargs: |
| 53 | + raise ValueError("If a position argument is used, keyword arguments cannot be used.") |
| 54 | + super().__init__(actual_instance=args[0]) |
| 55 | + else: |
| 56 | + super().__init__(**kwargs) |
| 57 | + |
| 58 | + @field_validator('actual_instance') |
| 59 | + def actual_instance_must_validate_anyof(cls, v): |
| 60 | + instance = ChatCompletionRequestToolsInner.model_construct() |
| 61 | + error_messages = [] |
| 62 | + # validate data type: Dict[str, object] |
| 63 | + try: |
| 64 | + instance.anyof_schema_1_validator = v |
| 65 | + return v |
| 66 | + except (ValidationError, ValueError) as e: |
| 67 | + error_messages.append(str(e)) |
| 68 | + # validate data type: Dict[str, object] |
| 69 | + try: |
| 70 | + instance.anyof_schema_2_validator = v |
| 71 | + return v |
| 72 | + except (ValidationError, ValueError) as e: |
| 73 | + error_messages.append(str(e)) |
| 74 | + if error_messages: |
| 75 | + # no match |
| 76 | + raise ValueError("No match found when setting the actual_instance in ChatCompletionRequestToolsInner with anyOf schemas: Dict[str, object]. Details: " + ", ".join(error_messages)) |
| 77 | + else: |
| 78 | + return v |
| 79 | + |
| 80 | + @classmethod |
| 81 | + def from_dict(cls, obj: Dict[str, Any]) -> Self: |
| 82 | + return cls.from_json(json.dumps(obj)) |
| 83 | + |
| 84 | + @classmethod |
| 85 | + def from_json(cls, json_str: str) -> Self: |
| 86 | + """Returns the object represented by the json string""" |
| 87 | + instance = cls.model_construct() |
| 88 | + error_messages = [] |
| 89 | + # deserialize data into Dict[str, object] |
| 90 | + try: |
| 91 | + # validation |
| 92 | + instance.anyof_schema_1_validator = json.loads(json_str) |
| 93 | + # assign value to actual_instance |
| 94 | + instance.actual_instance = instance.anyof_schema_1_validator |
| 95 | + return instance |
| 96 | + except (ValidationError, ValueError) as e: |
| 97 | + error_messages.append(str(e)) |
| 98 | + # deserialize data into Dict[str, object] |
| 99 | + try: |
| 100 | + # validation |
| 101 | + instance.anyof_schema_2_validator = json.loads(json_str) |
| 102 | + # assign value to actual_instance |
| 103 | + instance.actual_instance = instance.anyof_schema_2_validator |
| 104 | + return instance |
| 105 | + except (ValidationError, ValueError) as e: |
| 106 | + error_messages.append(str(e)) |
| 107 | + |
| 108 | + if error_messages: |
| 109 | + # no match |
| 110 | + raise ValueError("No match found when deserializing the JSON string into ChatCompletionRequestToolsInner with anyOf schemas: Dict[str, object]. Details: " + ", ".join(error_messages)) |
| 111 | + else: |
| 112 | + return instance |
| 113 | + |
| 114 | + def to_json(self) -> str: |
| 115 | + """Returns the JSON representation of the actual instance""" |
| 116 | + if self.actual_instance is None: |
| 117 | + return "null" |
| 118 | + |
| 119 | + if hasattr(self.actual_instance, "to_json") and callable(self.actual_instance.to_json): |
| 120 | + return self.actual_instance.to_json() |
| 121 | + else: |
| 122 | + return json.dumps(self.actual_instance) |
| 123 | + |
| 124 | + def to_dict(self) -> Optional[Union[Dict[str, Any], Dict[str, object]]]: |
| 125 | + """Returns the dict representation of the actual instance""" |
| 126 | + if self.actual_instance is None: |
| 127 | + return None |
| 128 | + |
| 129 | + if hasattr(self.actual_instance, "to_dict") and callable(self.actual_instance.to_dict): |
| 130 | + return self.actual_instance.to_dict() |
| 131 | + else: |
| 132 | + return self.actual_instance |
| 133 | + |
| 134 | + def to_str(self) -> str: |
| 135 | + """Returns the string representation of the actual instance""" |
| 136 | + return pprint.pformat(self.model_dump()) |
| 137 | + |
| 138 | + |
0 commit comments