o
    i                     @   s,  d dl mZmZmZ ddlmZmZ ddlmZm	Z	 ddl
mZ ddlZG dd	 d	eZG d
d deZG dd deZddddddddddgdddiddidddddddddgdddZe Zd ed! d d"< d ed"< ed#e	dee d$d%d&ZG d'd( d(ejZed)kre  dS dS )*   )pydantic_model_from_json#response_format_from_pydantic_modelrec_strict_json_schema    )	BaseModelValidationError   )ResponseFormat
JSONSchema)UnsetNc                   @   s   e Zd ZU eed< eed< dS )StudentnameageN)__name__
__module____qualname__str__annotations__int r   r   f/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/mistralai/extra/tests/test_utils.pyr         
 r   c                   @   s   e Zd ZU eed< eed< dS )ExplanationexplanationoutputN)r   r   r   r   r   r   r   r   r   r      r   r   c                   @   s"   e Zd ZU ee ed< eed< dS )MathDemonstrationstepsfinal_answerN)r   r   r   listr   r   r   r   r   r   r   r      s   
 r   string)titletypeOutputr   r   r   r   object)
propertiesrequiredr    r!   z$refz#/$defs/ExplanationStepsarray)itemsr    r!   zFinal Answerr   r   r   r   )$defsr%   r&   r    r!   Fr+   additionalPropertiesjson_schemaT)r   schema_definitiondescriptionstrict)r!   r-   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestResponseFormatc                 C   s
  ddi}ddd}dddd}ddd	d
ddd
ddd
ddd
ddd
gd}|  t|ttddd |  t|ttddd |  t|tttdd	d
tddd
tddd
tddd
tddd
gdd | t t|t W d    d S 1 s~w   Y  d S )Nr   zJean Dupont   )r   r   extra_value)r   r   extra_fieldzx = -4zStart with the given equation.z8x + 7 = -23r#   z6Subtract 7 from both sides to isolate the term with x.z8x = -23 - 7z(Simplify the right side of the equation.z8x = -30z&Divide both sides by 8 to solve for x.zx = -30 / 8z.Simplify the fraction to get the final answer.)r   r   r*   )assertEqualr   r   r   r   assertRaisesr   )selfmissing_json_datagood_json_dataextra_json_datacomplex_json_datar   r   r   test_pydantic_model_from_jsonF   s|   


"z0TestResponseFormat.test_pydantic_model_from_jsonc                 C   s   |  ttt d S )N)r5   r   r   mathdemo_response_format)r7   r   r   r   (test_response_format_from_pydantic_model   s   z;TestResponseFormat.test_response_format_from_pydantic_modelc                 C   sT   t ddiB }| tt t | t t| W d    d S 1 s#w   Y  d S )Nwrong_value   )mathdemo_schemar5   r   mathdemo_strict_schemar6   
ValueError)r7   invalid_schemar   r   r   test_rec_strict_json_schema   s   
"z.TestResponseFormat.test_rec_strict_json_schemaN)r   r   r   r<   r>   rE   r   r   r   r   r1   E   s    Kr1   __main__)utils.response_formatr   r   r   pydanticr   r   modelsr	   r
   types.basemodelr   unittestr   r   r   rA   copyrB   r=   TestCaser1   r   mainr   r   r   r   <module>   sV    \