a
    f                     @  s   d dl mZ d dlmZ d dlmZ d dlZddlmZ ddl	m
ZmZ ddlmZ d	d
dddZdddd
dddZddddddZdddddZ
dddddd ZdS )!    )annotations)Any)	TypeGuardN   )	NOT_GIVEN)is_dictis_list)model_json_schemaztype[pydantic.BaseModel]zdict[str, Any])modelreturnc                 C  s   t | }t|d|dS )N pathroot)r	   _ensure_strict_json_schema)r
   Zschemar   r   M/var/www/ai-form-bot/venv/lib/python3.9/site-packages/openai/lib/_pydantic.pyto_strict_json_schema   s    r   objectztuple[str, ...]zdict[str, object])json_schemar   r   r   c                  sp  t | std|  d  | d}t |r\| D ]$\}}t|g  d|R d q6| d}t |r| D ]$\}}t|g  d|R d qv| d}	|	dkrd| vrd	| d< | d
}
t |
rdd |
 D | d<  fdd|
 D | d
< | d}t |r4t|g  dR d| d< | d}t|rd fddt|D | d< | d}t|rt|dkr| 	t|d g  ddR d | 
d n fddt|D | d< | dtdu r| 
d | d}|rlt| drlt|ts&J d| t|d}t |sPtd| d| | 	i ||  | 
d | S )zkMutates the given JSON schema to ensure it conforms to the `strict` standard
    that the API expects.
    z	Expected z to be a dictionary; path=z$defsr   definitionstyper   ZadditionalPropertiesF
propertiesc                 S  s   g | ]}|qS r   r   ).0propr   r   r   
<listcomp>0       z._ensure_strict_json_schema.<locals>.<listcomp>requiredc                   s.   i | ]&\}}|t |g  d |R dqS )r   r   )r   )r   keyZprop_schemar   r   r   
<dictcomp>1   s   z._ensure_strict_json_schema.<locals>.<dictcomp>itemsanyOfc                   s0   g | ](\}}t |g  d t|R dqS )r    r   r   str)r   ivariantr   r   r   r   ?   s   allOf   r   0c                   s0   g | ](\}}t |g  d t|R dqS )r%   r   r!   )r   r#   entryr   r   r   r   K   s   defaultNz$refzReceived non-string $ref - )r   refzExpected `$ref: z&` to resolved to a dictionary but got )r   	TypeErrorgetr   r   keysr   	enumeratelenupdatepopr   has_more_than_n_keys
isinstancer"   resolve_ref
ValueError)r   r   r   ZdefsZdef_nameZ
def_schemar   Zdefinition_nameZdefinition_schematypr   r   Zany_ofZall_ofr*   resolvedr   r   r   r      s\    	












&




r   r"   )r   r*   r   c                 C  sf   | dstd|d|dd  d}| }|D ],}|| }t|s\J d| d| |}q4|S )Nz#/zUnexpected $ref format z; Does not start with #/r   /z1encountered non-dictionary entry while resolving z - )
startswithr5   splitr   )r   r*   r   r7   r   valuer   r   r   r4   j   s    
r4   zTypeGuard[dict[str, object]])objr   c                 C  s   t | S )N)_is_dict)r<   r   r   r   r   x   s    r   intbool)r<   nr   c                 C  s,   d}|   D ]}|d7 }||kr dS qdS )Nr   r&   TF)r-   )r<   r@   r#   _r   r   r   r2   ~   s    r2   )
__future__r   typingr   typing_extensionsr   Zpydantic_typesr   Z_utilsr   r=   r   _compatr	   r   r   r4   r2   r   r   r   r   <module>   s   X