a
    fkn                     @  s^  d dl mZ d dlZd dlZd dlmZmZmZmZm	Z	m
Z
mZmZ d dlmZmZ d dlmZmZmZmZmZmZmZmZmZmZmZ d dlZd dlZd dlmZ ddlm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z( dd	l)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5 dd
l6m7Z7m8Z8m9Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZB ddlCmDZD erbd dlEmFZFmGZGmHZH ddgZIe
dZJe
dddZKedZLeG dd deZMG dd dejNZNdddddddZOddddd ZPdd!dd"d#ZQd$d%d&dd'd(d)ZRdd*dd+d,d-ZSdddd+d.d/ZTeG d0d1 d1eZUG d2d3 d3ZVdd4d5d6d7d8ZWd9dd:d;d<d=ZXd*ddd>d?d@ZYdAdBdCdDdEdFZZereNZ9nG dGd de:eNZ9e7rd dHlm[Z\ edIe-ddJe\Z]erd dHlm[Z[ ne]Z[d*ddd>dKdLZ^n>es0G dMdN dNe9e	eJ Z_d*ddd>dOdLZ^ddPddQdRZ`G dSdT dTedUdVZaeG dWdX dXejNZbdS )Y    )annotationsN)TYPE_CHECKINGAnyTypeUnionGenericTypeVarCallablecast)datedatetime)UnpackLiteralClassVarProtocolRequired	ParamSpec	TypedDict	TypeGuardfinaloverrideruntime_checkable)	FieldInfo   )	BodyIncExQueryModelTHeadersTimeoutNotGiven
AnyMappingHttpxRequestFiles)PropertyInfois_listis_given	lru_cache
is_mapping
parse_datecoerce_booleanparse_datetimestrip_not_givenextract_type_argis_annotated_typestrip_annotated_type)PYDANTIC_V2
ConfigDictGenericModelget_argsis_union	parse_obj
get_originis_literal_typeget_model_configget_model_fieldsfield_get_default)RAW_RESPONSE_HEADER)
ModelFieldLiteralSchemaModelFieldsSchema	BaseModelr1   _T_BaseModelT)boundPc                   @  s   e Zd ZU ded< dS )_ConfigProtocolboolallow_population_by_field_nameN__name__
__module____qualname____annotations__ rK   rK   G/var/www/ai-form-bot/venv/lib/python3.9/site-packages/openai/_models.pyrC   L   s   
rC   c                      s  e Zd ZU er2edeejdddZ	de
d< n(eeddd	d
ZG dd dejZdddddddddddddddddZdddddddddddddddddZeddddZeed5d!d"d#d$d%d&d'ZeseZesxedd d ddddddd dd(d)d*d*dddddd+d,dd-d. fd/d0Zed d d ddddddd dd1dd*d*dddddd+d,ddd2 fd3d4Z  ZS )6r>   allowZDEFER_PYDANTIC_BUILDtrue)extraZdefer_buildClassVar[ConfigDict]model_configzset[str]returnc                 C  s   | j S N)__fields_set__selfrK   rK   rL   model_fields_setX   s    zBaseModel.model_fields_setc                   @  s   e Zd ZU ejjZded< dS )zBaseModel.Configr   rO   N)rG   rH   rI   pydanticZExtrarM   rO   rJ   rK   rK   rK   rL   Config^   s   
rZ   pythonTF)modeuse_api_namesexclude_unsetexclude_defaultsexclude_nonewarningszLiteral['json', 'python']rD   zdict[str, object])r\   r]   r^   r_   r`   ra   rS   c                C  s   | j ||||||dS )aD  Recursively generate a dictionary representation of the model, optionally specifying which fields to include or exclude.

        By default, fields that were not set by the API will not be included,
        and keys will match the API response, *not* the property names from the model.

        For example, if the API responds with `"fooBar": true` but we've defined a `foo_bar: bool` property,
        the output will use the `"fooBar"` key (unless `use_api_names=False` is passed).

        Args:
            mode:
                If mode is 'json', the dictionary will only contain JSON serializable types. e.g. `datetime` will be turned into a string, `"2024-3-22T18:11:19.117000Z"`.
                If mode is 'python', the dictionary may contain any Python objects. e.g. `datetime(2024, 3, 22)`

            use_api_names: Whether to use the key that the API responded with or the property name. Defaults to `True`.
            exclude_unset: Whether to exclude fields that have not been explicitly set.
            exclude_defaults: Whether to exclude fields that are set to their default value from the output.
            exclude_none: Whether to exclude fields that have a value of `None` from the output.
            warnings: Whether to log warnings when invalid fields are encountered. This is only supported in Pydantic v2.
        )r\   by_aliasr^   r_   r`   ra   )
model_dump)rW   r\   r]   r^   r_   r`   ra   rK   rK   rL   to_dicta   s    zBaseModel.to_dict   )indentr]   r^   r_   r`   ra   z
int | Nonestr)rf   r]   r^   r_   r`   ra   rS   c                C  s   | j ||||||dS )al  Generates a JSON string representing this model as it would be received from or sent to the API (but with indentation).

        By default, fields that were not set by the API will not be included,
        and keys will match the API response, *not* the property names from the model.

        For example, if the API responds with `"fooBar": true` but we've defined a `foo_bar: bool` property,
        the output will use the `"fooBar"` key (unless `use_api_names=False` is passed).

        Args:
            indent: Indentation to use in the JSON output. If `None` is passed, the output will be compact. Defaults to `2`
            use_api_names: Whether to use the key that the API responded with or the property name. Defaults to `True`.
            exclude_unset: Whether to exclude fields that have not been explicitly set.
            exclude_defaults: Whether to exclude fields that have the default value.
            exclude_none: Whether to exclude fields that have a value of `None`.
            warnings: Whether to show any warnings that occurred during serialization. This is only supported in Pydantic v2.
        )rf   rb   r^   r_   r`   ra   )model_dump_json)rW   rf   r]   r^   r_   r`   ra   rK   rK   rL   to_json   s    zBaseModel.to_jsonc                 C  s   |    d| d dS )N(z, ))Z__repr_name__Z__repr_str__rV   rK   rK   rL   __str__   s    zBaseModel.__str__NzType[ModelT]set[str] | Noneobjectr   )cls_fields_setvaluesrS   c                 K  sD  |  | }i }t| }t|tr&|jn|d}|d u r>t }t| }| D ]\\}}	|	j	}
|
d u sp|
|vrt|rt|}
|
|v rt
||
 |	|
d||< || qNt|	||< qNi }| D ]0\}
}|
|vrtr|||
< q||
 |||
< qt|d| tr*t|dd  t|d| t|d| n|  t|d| |S )Npopulate_by_name)valuefieldkey__dict__Z__pydantic_private__Z__pydantic_extra__Z__pydantic_fields_set__rU   )__new__r7   
isinstancerC   rE   getsetr8   itemsalias_construct_fieldaddr9   r/   rn   __setattr__Z_init_private_attributes)ro   rp   rq   mZfields_valuesconfigrr   Zmodel_fieldsnamert   ru   Z_extrars   rK   rK   rL   	construct   sB    



zBaseModel.construct)r\   includeexcluderb   r^   r_   r`   
round_tripra   contextserialize_as_anyzLiteral['json', 'python'] | strr   z'bool | Literal['none', 'warn', 'error']zdict[str, Any] | Nonezdict[str, Any])r\   r   r   rb   r^   r_   r`   r   ra   r   r   rS   c                  sh   |dkrt d|dkr t d|	dkr0t d|
dur@t d|dkrPt d	t j||||||d
S )a  Usage docs: https://docs.pydantic.dev/2.4/concepts/serialization/#modelmodel_dump

            Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.

            Args:
                mode: The mode in which `to_python` should run.
                    If mode is 'json', the dictionary will only contain JSON serializable types.
                    If mode is 'python', the dictionary may contain any Python objects.
                include: A list of fields to include in the output.
                exclude: A list of fields to exclude from the output.
                by_alias: Whether to use the field's alias in the dictionary key if defined.
                exclude_unset: Whether to exclude fields that are unset or None from the output.
                exclude_defaults: Whether to exclude fields that are set to their default value from the output.
                exclude_none: Whether to exclude fields that have a value of `None` from the output.
                round_trip: Whether to enable serialization and deserialization round-trip support.
                warnings: Whether to log warnings when invalid fields are encountered.

            Returns:
                A dictionary representation of the model.
            r[   z%mode is only supported in Pydantic v2F+round_trip is only supported in Pydantic v2T)warnings is only supported in Pydantic v2N(context is only supported in Pydantic v21serialize_as_any is only supported in Pydantic v2)r   r   rb   r^   r_   r`   )
ValueErrorsuperdict)rW   r\   r   r   rb   r^   r_   r`   r   ra   r   r   	__class__rK   rL   rc      s$    $zBaseModel.model_dump)rf   r   r   rb   r^   r_   r`   r   ra   r   r   )rf   r   r   rb   r^   r_   r`   r   ra   r   r   rS   c             	     sZ   |dkrt d|	dkr t d|
dur0t d|dkr@t dt j|||||||dS )	a  Usage docs: https://docs.pydantic.dev/2.4/concepts/serialization/#modelmodel_dump_json

            Generates a JSON representation of the model using Pydantic's `to_json` method.

            Args:
                indent: Indentation to use in the JSON output. If None is passed, the output will be compact.
                include: Field(s) to include in the JSON output. Can take either a string or set of strings.
                exclude: Field(s) to exclude from the JSON output. Can take either a string or set of strings.
                by_alias: Whether to serialize using field aliases.
                exclude_unset: Whether to exclude fields that have not been explicitly set.
                exclude_defaults: Whether to exclude fields that have the default value.
                exclude_none: Whether to exclude fields that have a value of `None`.
                round_trip: Whether to use serialization/deserialization between JSON and class instance.
                warnings: Whether to show any warnings that occurred during serialization.

            Returns:
                A JSON string representation of the model.
            Fr   Tr   Nr   r   )rf   r   r   rb   r^   r_   r`   )r   r   json)rW   rf   r   r   rb   r^   r_   r`   r   ra   r   r   r   rK   rL   rh   -  s"    "zBaseModel.model_dump_json)N)rG   rH   rI   r/   r0   r)   osenvironry   rQ   rJ   propertyr   rX   rY   
BaseConfigrZ   rd   ri   rl   classmethodr   r   model_constructrc   rh   __classcell__rK   rK   r   rL   r>   Q   sr   
)# 7.6rn   r   rg   )rs   rt   ru   rS   c                 C  sJ   | d u rt |S tr|j}ntt|j}|d u r>td| t| |dS )Nz"Unexpected field type is None for rs   type_)r9   r/   
annotationr
   typeZouter_type_RuntimeErrorconstruct_type)rs   rt   ru   r   rK   rK   rL   r}   b  s    r}   r   rD   )r   rS   c                 C  s0   t | r(t| D ]}t|r dS qdS t| S )zWReturns whether or not the given type is either a `BaseModel` or a union of `BaseModel`TF)r3   r2   is_basemodelis_basemodel_type)r   variantrK   rK   rL   r   q  s    r   z/TypeGuard[type[BaseModel] | type[GenericModel]]c                 C  s.   t | p
| }t|sdS t|tp,t|tS )NF)r5   inspectisclass
issubclassr>   r1   )r   originrK   rK   rL   r   }  s    
r   zCallable[P, _BaseModelT]zP.argszP.kwargs)base_model_clsargskwargsrS   c                 O  s   |rt dttt| |dS )a?  Construct a BaseModel class without validation.

    This is useful for cases where you need to instantiate a `BaseModel`
    from an API response as this provides type-safe params which isn't supported
    by helpers like `construct_type()`.

    ```py
    build(MyModel, my_field_a="foo", my_field_b=123)
    ```
    z]Received positional arguments which are not supported; Keyword arguments must be used insteadr   rs   )	TypeErrorr
   r@   r   )r   r   r   rK   rK   rL   build  s
    r   ztype[_T])rs   r   rS   c                 C  s   t tt| |dS )zLoose coercion to the expected type with construction of nested values.

    Note: the returned value from this function is not guaranteed to match the
    given type.
    r   )r
   r?   r   r   rK   rK   rL   construct_type_unchecked  s    r   c              	     s  t dtr.tdd }tdnt }tp>}t}t|rztt d| dW S  tyx   Y n0 t	|d}|rt
| r| |jp|j}|rt|tr|j|}|rt|| dS |D ]0}zt| |dW   S  ty    Y qY q0 qtd |tkrLt
| s*| S t\}	fd	d
|  D S tst|tsnt|trt| rfdd| D S t
| rttrjf i | S t tjf i | S |tkrt| s| S |d   fdd| D S |tkr,t| tr(t| }
|
| kr$| S |
S | S tkrZz
t | W S  tyX   |  Y S 0 t!krz
t"| W S  ty   |  Y S 0 | S )zLoose coercion to the expected type with construction of nested values.

    If the given value does not match the expected type then it is returned as-is.
    ztype[object]r   Nr   r   )unionmeta_annotationsr   z0Could not convert data into a valid instance of c                   s   i | ]\}}|t | d qS r   r   ).0ru   item)
items_typerK   rL   
<dictcomp>      z"construct_type.<locals>.<dictcomp>c                   s.   g | ]&}t |r&tt jf i |n|qS rK   )r'   r
   r   r   r   entryr   rK   rL   
<listcomp>  r   z"construct_type.<locals>.<listcomp>c                   s   g | ]}t | d qS r   r   r   )
inner_typerK   rL   r     r   )#r
   r-   r2   r,   tupler5   r3   validate_type	Exception_build_discriminated_union_metar'   ry   field_alias_from
field_namerx   rg   mappingr   r   r   r{   r6   r   r>   r1   r$   r   r   listfloatintr   r*   r   r(   )rs   r   metar   r   discriminatorZvariant_valueZvariant_typer   _ZcoercedrK   )r   r   r   rL   r     sx    



"











r   c                   @  s   e Zd ZU ded< dS )CachedDiscriminatorTypeDiscriminatorDetails__discriminator__NrF   rK   rK   rK   rL   r     s   
r   c                   @  s:   e Zd ZU ded< ded< ded< dddddd	d
ZdS )r   rg   r   z
str | Noner   zdict[str, type]r   None)r   discriminator_fielddiscriminator_aliasrS   c                C  s   || _ || _|| _d S rT   )r   r   r   )rW   r   r   r   rK   rK   rL   __init__0  s    zDiscriminatorDetails.__init__N)rG   rH   rI   rJ   r   rK   rK   rK   rL   r     s   
r   ztuple[Any, ...]zDiscriminatorDetails | None)r   r   rS   c                 C  s@  t | tr| jS d }|D ]"}t |tr|jd ur|j} q<q|sDd S i }d }t| D ]}t|}t|rTtrt	||}|s|qT|
d}|d }|d dkrtd|d D ]}	t |	tr|||	< qqTtd|j
|}
|
sqT|
j}|
jrTt|
jrTt|
jD ]}	t |	t r|||	<  qqT|s"d S t|||d}|tt| _|S )	NZserialization_aliasschemar   literalr<   expectedzdict[str, FieldInfo])r   r   r   )rx   r   r   r#   r   r2   r.   r   r/   _extract_field_schema_pv2ry   r
   rg   Z
__fields__r|   r   r6   r   )r   r   Zdiscriminator_field_namer   r   r   r   rt   Zfield_schemar   Z
field_infodetailsrK   rK   rL   r   <  sR    



r   ztype[BaseModel]zModelField | None)modelr   rS   c                 C  sX   | j }|d dkrd S |d }|d dkr.d S td|}|d |}|sNd S td|S )Nr   r   r   zmodel-fieldsr=   fieldsr;   )Z__pydantic_core_schema__r
   ry   )r   r   r   Zfields_schemart   rK   rK   rL   r   w  s    
r   )r   rs   rS   c                 C  s8   t | r&t| tjr&ttt| |S ttt| |dS )z@Strict validation that the given value matches the expected typer   )	r   r   r   rY   r>   r
   r?   r4   _validate_non_model_typer   rK   rK   rL   r     s    r   r   zpydantic.ConfigDictr   )typr   rS   c                 C  s   t | d| dS )zYAdd a pydantic config for the given type.

    Note: this is a no-op on Pydantic v1.
    Z__pydantic_config__N)setattr)r   r   rK   rK   rL   set_pydantic_config  s    r   c                   @  s   e Zd ZdS )r1   N)rG   rH   rI   rK   rK   rK   rL   r1     s   )TypeAdapterzTypeAdapter[object])maxsizec                 C  s   t | |S rT   )r   Zvalidate_pythonr   rK   rK   rL   r     s    r   c                   @  s   e Zd ZU dZded< dS )	RootModelzUsed as a placeholder to easily convert runtime types to a Pydantic format
        to provide validation.

        For example:
        ```py
        validated = RootModel[int](__root__="5").__root__
        # validated: 5
        ```
        r?   __root__N)rG   rH   rI   __doc__rJ   rK   rK   rK   rL   r     s   

r   c                 C  s   t | |}tt|jS rT   )_create_pydantic_modelvalidater
   r?   r   )r   rs   r   rK   rK   rL   r     s    zType[RootModel[_T]]c                 C  s   t |  S rT   )r   r   rK   rK   rL   r     s    r   c                   @  s^   e Zd ZU ded< ded< ded< ded< ded	< d
ed< ded< ded< ded< ded< dS )FinalRequestOptionsInputzRequired[str]methodurlr   paramsr   headersr   max_retrieszfloat | Timeout | NonetimeoutzHttpxRequestFiles | Nonefilesrg   idempotency_keyr   	json_datar!   
extra_jsonNrF   rK   rK   rK   rL   r     s   
r   F)totalc                      s  e Zd ZU ded< ded< i Zded< e Zded< e Zded	< e Zd
ed< dZ	ded< dZ
ded< e Zded< dZded< dZded< ereddZded< nG dd dejZddddd Zd!d"d#d$Zed*d%d&d d' fd(d)ZeseZ  ZS )+FinalRequestOptionsrg   r   r   r   r   zUnion[Headers, NotGiven]r   zUnion[int, NotGiven]r   z%Union[float, Timeout, None, NotGiven]r   NzUnion[HttpxRequestFiles, None]r   zUnion[str, None]r   z%Union[Callable[[Any], Any], NotGiven]post_parserzUnion[Body, None]r   zUnion[AnyMapping, None]r   T)arbitrary_types_allowedrP   rQ   c                   @  s   e Zd ZU dZded< dS )zFinalRequestOptions.ConfigTrD   r   N)rG   rH   rI   r   rJ   rK   rK   rK   rL   rZ     s   
rZ   r   )r   rS   c                 C  s   t | jtr|S | jS rT   )rx   r   r    )rW   r   rK   rK   rL   get_max_retries  s    z#FinalRequestOptions.get_max_retriesr   rR   c                 C  s6   t | jsd S | jtr2i | j| _| jt d S rT   )r%   r   ry   r:   poprV   rK   rK   rL   _strip_raw_response_header  s
    
z.FinalRequestOptions._strip_raw_response_headerrm   z Unpack[FinalRequestOptionsInput])rp   rq   rS   c                   sD   dd |  D }tr*t j|fi |S ttt j|fi |S )Nc                 S  s   i | ]\}}|t |qS rK   )r+   )r   ru   rs   rK   rK   rL   r     s   z1FinalRequestOptions.construct.<locals>.<dictcomp>)r{   r/   r   r   r
   r   r   )ro   rp   rq   r   r   rK   rL   r     s    zFinalRequestOptions.construct)N)rG   rH   rI   rJ   r   r    r   r   r   r   r   r   r   r   r/   r0   rQ   rY   r   rZ   r   r   r   r   r   r   r   rK   rK   r   rL   r     s*   
 r   )c
__future__r   r   r   typingr   r   r   r   r   r   r	   r
   r   r   typing_extensionsr   r   r   r   r   r   r   r   r   r   r   rY   Zpydantic.genericsZpydantic.fieldsr   _typesr   r   r   r   r   r   r    r!   r"   Z_utilsr#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   _compatr/   r0   r1   ZBaseGenericModelr2   r3   r4   r5   r6   r7   r8   r9   
_constantsr:   Zpydantic_core.core_schemar;   r<   r=   __all__r?   r@   rB   rC   r>   r}   r   r   r   r   r   r   r   r   r   r   r   r   Z_TypeAdapterZ_CachedTypeAdapterr   r   r   r   r   rK   rK   rK   rL   <module>   sj   (4,84  	j);
