a
    !fS@                     @  s^  d dl m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 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, dd
l-m.Z.m/Z/ ddl-m0Z1 ddl-m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9 ddl:m;Z; ddgZ<e	dZ=eG dd deZ>G dd dej?Z?dddddddZ@dddddZAddddd d!ZBd"ddd#d$d%ZCere?Z0nG d&d de1e?Z0e.rd d'lmDZD d"ddd#d(d)ZEn>es0G d*d+ d+e0ee= ZFd"ddd#d,d)ZEdd-dd.d/ZGG d0d1 d1ed2d3ZHeG d4d5 d5ej?ZIdS )6    )annotationsN)TYPE_CHECKINGAnyTypeUnionGenericTypeVarCallablecast)datedatetime)	UnpackLiteralClassVarProtocolRequired	TypedDictfinaloverrideruntime_checkable)	FieldInfo   )	BodyIncExQueryModelTHeadersTimeoutNotGiven
AnyMappingHttpxRequestFiles)is_listis_given
is_mapping
parse_dateparse_datetimestrip_not_given)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	BaseModelr)   _Tc                   @  s   e Zd ZU ded< dS )_ConfigProtocolboolallow_population_by_field_nameN__name__
__module____qualname____annotations__ r=   r=   O/var/www/html/python-backend/venv/lib/python3.9/site-packages/openai/_models.pyr5   <   s   
r5   c                      s  e Zd ZU er"eddZded< n(eeddddZ	G d	d
 d
e
jZeddddZeed&dddddddZeseZesedddddddddd	ddddddddddd
 fdd Zedddddddddd!	d"dddddddddd#
 fd$d%Z  ZS )'r3   allow)extraClassVar[ConfigDict]model_configzset[str]returnc                 C  s   | j S N)__fields_set__selfr=   r=   r>   model_fields_setF   s    zBaseModel.model_fields_setc                   @  s   e Zd ZU ejjZded< dS )zBaseModel.Configr   r@   N)r9   r:   r;   pydanticZExtrar?   r@   r<   r=   r=   r=   r>   ConfigL   s   
rK   strc                 C  s   |    d| d dS )N(z, ))Z__repr_name__Z__repr_str__rG   r=   r=   r>   __str__O   s    zBaseModel.__str__NzType[ModelT]set[str] | Noneobjectr   )cls_fields_setvaluesrD   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__rF   )__new__r/   
isinstancer5   r7   getsetr0   itemsalias_construct_fieldaddr1   r'   rQ   __setattr__Z_init_private_attributes)rR   rS   rT   mZfields_valuesconfigrU   Zmodel_fieldsnamerW   rX   _extrarV   r=   r=   r>   	constructV   sB    



zBaseModel.constructpythonFT)	modeincludeexcludeby_aliasexclude_unsetexclude_defaultsexclude_none
round_tripwarningszLiteral['json', 'python'] | strr   r6   zdict[str, Any])
ri   rj   rk   rl   rm   rn   ro   rp   rq   rD   c       	   
        sH   |dkrt d|dkr t d|	dkr0t 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.
            rh   z%mode is only supported in Pydantic v2F+round_trip is only supported in Pydantic v2T)warnings is only supported in Pydantic v2)rj   rk   rl   rm   rn   ro   )
ValueErrorsuperdict)
rH   ri   rj   rk   rl   rm   rn   ro   rp   rq   	__class__r=   r>   
model_dump   s    "zBaseModel.model_dump)	indentrj   rk   rl   rm   rn   ro   rp   rq   z
int | None)
rz   rj   rk   rl   rm   rn   ro   rp   rq   rD   c       	   
   	     s:   |dkrt 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.
            Frr   Trs   )rz   rj   rk   rl   rm   rn   ro   )rt   ru   json)
rH   rz   rj   rk   rl   rm   rn   ro   rp   rq   rw   r=   r>   model_dump_json   s     zBaseModel.model_dump_json)N)r9   r:   r;   r'   r(   rB   r<   propertyr   rI   rJ   
BaseConfigrK   rO   classmethodrg   r   model_constructry   r|   __classcell__r=   r=   rw   r>   r3   A   sJ   
 7*0rQ   r   rL   )rV   rW   rX   rD   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 rV   type_)r1   r'   
annotationr
   typeZouter_type_RuntimeErrorconstruct_type)rV   rW   rX   r   r=   r=   r>   r`      s    r`   r   r6   )r   rD   c                 C  sH   t | p
| }t| r4t| D ]}t|r dS qdS t|tpFt|tS )zWReturns whether or not the given type is either a `BaseModel` or a union of `BaseModel`TF)r-   r+   r*   is_basemodel
issubclassr3   r)   )r   originvariantr=   r=   r>   r   
  s    r   )rV   r   rD   c              	     s  t p
}t}t|rzt| dW S  ty<   Y n0 |D ].}zt| |dW   S  tyn   Y qBY qB0 qBtd |tkrt| s| S t\}fdd| 	 D S t
s,t|tst|tr,t| rfdd| D S t| r,ttrjf i | S ttjf i | S |tkr^t| sD| S |d   fd	d| D S |tkrt| trt| }|| kr| S |S | S tkrz
t| W S  ty   |  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.
    r   rV   r   z0Could not convert data into a valid instance of c                   s   i | ]\}}|t | d qS r   r   ).0rX   item)
items_typer=   r>   
<dictcomp>6      z"construct_type.<locals>.<dictcomp>c                   s.   g | ]&}t |r&tt jf i |n|qS r=   )r#   r
   r   rg   r   entryr   r=   r>   
<listcomp>:  r   z"construct_type.<locals>.<listcomp>r   c                   s   g | ]}t | d qS r   r   r   )
inner_typer=   r>   r   G  r   )r-   r*   r+   validate_type	Exceptionr   r   rv   r#   r^   r.   r   r3   r)   r!   rg   r
   r   listfloatr[   intr   r%   r   r$   )rV   r   r   argsr   _Zcoercedr=   )r   r   r   r>   r     s`     










r   ztype[_T])r   rV   rD   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   )	inspectisclassr   rJ   r3   r
   r4   r,   _validate_non_model_typer   r=   r=   r>   r   a  s    r   c                   @  s   e Zd ZdS )r)   N)r9   r:   r;   r=   r=   r=   r>   r)   o  s   )TypeAdapterc                 C  s   t | |S rE   )r   Zvalidate_pythonr   r=   r=   r>   r   v  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
        ```
        r4   __root__N)r9   r:   r;   __doc__r<   r=   r=   r=   r>   r   {  s   

r   c                 C  s   t | |}tt|jS rE   )_create_pydantic_modelvalidater
   r4   r   )r   rV   modelr=   r=   r>   r     s    zType[RootModel[_T]]c                 C  s   t |  S rE   )r   r   r=   r=   r>   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filesrL   idempotency_keyr   	json_datar   
extra_jsonNr8   r=   r=   r=   r>   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 )+FinalRequestOptionsrL   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_allowedrA   rB   c                   @  s   e Zd ZU dZded< dS )zFinalRequestOptions.ConfigTr6   r   N)r9   r:   r;   r   r<   r=   r=   r=   r>   rK     s   
rK   r   )r   rD   c                 C  s   t | jtr|S | jS rE   )r[   r   r   )rH   r   r=   r=   r>   get_max_retries  s    z#FinalRequestOptions.get_max_retriesNonerC   c                 C  s6   t | jsd S | jtr2i | j| _| jt d S rE   )r"   r   r\   r2   poprG   r=   r=   r>   _strip_raw_response_header  s
    
z.FinalRequestOptions._strip_raw_response_headerrP   z Unpack[FinalRequestOptionsInput])rS   rT   rD   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 r=   )r&   )r   rX   rV   r=   r=   r>   r     s   z1FinalRequestOptions.construct.<locals>.<dictcomp>)r^   r'   ru   r   r
   r   rg   )rR   rS   rT   kwargsrw   r=   r>   rg     s    zFinalRequestOptions.construct)N)r9   r:   r;   r<   r   r   r   r   r   r   r   r   r   r   r'   r(   rB   rJ   r~   rK   r   r   r   rg   r   r   r   r=   r=   rw   r>   r     s*   
 r   )J
__future__r   r   typingr   r   r   r   r   r   r	   r
   r   r   Ztyping_extensionsr   r   r   r   r   r   r   r   r   rJ   Zpydantic.genericsZpydantic.fieldsr   _typesr   r   r   r   r   r   r   r   r    _utilsr!   r"   r#   r$   r%   r&   Z_compatr'   r(   r)   ZBaseGenericModelr*   r+   r,   r-   r.   r/   r0   r1   
_constantsr2   __all__r4   r5   r3   r`   r   r   r   r   r   r   r   r   r   r=   r=   r=   r>   <module>   sH   (,, (
 ;J
