o
    i                     @  sZ   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ZG dd deZdS )    )annotationsN)	UserError   )
JsonSchemaJsonSchemaTransformer   )ModelProfile
model_namestrreturnModelProfile | Nonec                 C  s    d| v }t t|| | | dS )z)Get the model profile for a Google model.image)json_schema_transformersupports_image_outputsupports_json_schema_outputsupports_json_object_outputsupports_tools)r   GoogleJsonSchemaTransformer)r	   is_image_model r   a/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/pydantic_ai/profiles/google.pygoogle_model_profile   s   r   c                      s2   e Zd ZdZddd fdd	ZdddZ  ZS )r   uw  Transforms the JSON Schema from Pydantic to be suitable for Gemini.

    Gemini which [supports](https://ai.google.dev/gemini-api/docs/function-calling#function_declarations)
    a subset of OpenAPI v3.0.3.

    Specifically:
    * gemini doesn't allow the `title` keyword to be set
    * gemini doesn't allow `$defs` — we need to inline the definitions where possible
    N)strictschemar   r   bool | Nonec                  s   t  j||ddd d S )NT)r   prefer_inlined_defssimplify_nullable_unions)super__init__)selfr   r   	__class__r   r   r   "   s   z$GoogleJsonSchemaTransformer.__init__r   c                 C  s  | dd }|ri |d|i}td| j d| dt | dd  | dd  | dd  }d ur9|g|d< | d	d  | d
d  | dd  | dd  |d }red|d< dd |D |d< |d}d|v ryd|vry| d|d< |dkr| dd  }r|d}|r| d| d|d< nd| |d< d|v rtd|d  d|v r| d}	|d}
|
d ur|
gng }|	D ]}||vr|| qt|dkrd|i|d< nt|dkr|d |d< |	dt|	 |
d u r|	dt|	 |S ) NadditionalPropertieszn`additionalProperties` is not supported by Gemini; it will be removed from the tool JSON schema. Full schema: z9

Source of additionalProperties within the full schema: z

If this came from a field with a type like `dict[str, MyType]`, that field will always be empty.

If Google's APIs are updated to support this properly, please create an issue on the Pydantic AI GitHub and we will fix this behavior.titlez$schemaconstenumdiscriminatorexamplesexclusiveMaximumexclusiveMinimumstringtypec                 S  s   g | ]}t |qS r   )r
   ).0valr   r   r   
<listcomp>G   s    z9GoogleJsonSchemaTransformer.transform.<locals>.<listcomp>oneOfanyOfformatdescriptionz
 (format: )zFormat: z$refz>Recursive `$ref`s in JSON Schema are not supported by Gemini: prefixItemsitemsr   r   minItemsmaxItems)
popwarningswarnr   UserWarninggetr   appendlen
setdefault)r   r   additional_propertiesoriginal_schemar$   r%   type_fmtr2   prefix_itemsr5   unique_itemsitemr   r   r   	transform%   sd   






z%GoogleJsonSchemaTransformer.transform)r   r   r   r   )r   r   r   r   )__name__
__module____qualname____doc__r   rG   __classcell__r   r   r    r   r      s    
r   )r	   r
   r   r   )
__future__r   _annotationsr9   pydantic_ai.exceptionsr   _json_schemar   r    r   r   r   r   r   r   r   <module>   s    
