o
    i'                     @  s   d dl mZ d dlZd dlZd dlmZ d dlmZ d dl	m
Z
mZ ddlmZmZ dd	lmZ ed
 ZeddG dd deZdddZg dZg dZe ZeddG dd deZdS )    )annotationsN)Sequence)	dataclass)AnyLiteral   )
JsonSchemaJsonSchemaTransformer   )ModelProfile)system	developeruserT)kw_onlyc                   @  s   e Zd ZU dZdZded< 	 dZded< 	 dZded< 	 dZded	< 	 d
Z	ded< 	 dZ
ded< 	 dZded< 	 dZded< 	 dd Zd
S )OpenAIModelProfilezProfile for models used with `OpenAIChatModel`.

    ALL FIELDS MUST BE `openai_` PREFIXED SO YOU CAN MERGE THEM WITH OTHER MODELS.
    Tbool&openai_supports_strict_tool_definition!openai_supports_sampling_settings zSequence[str]!openai_unsupported_model_settings$openai_supports_tool_choice_requiredNzOpenAISystemPromptRole | Noneopenai_system_prompt_roleFopenai_chat_supports_web_search+openai_supports_encrypted_reasoning_content3openai_responses_requires_function_call_status_nonec                 C  s   | j stdt d S d S )NzThe `openai_supports_sampling_settings` has no effect, and it will be removed in future versions. Use `openai_unsupported_model_settings` instead.)r   warningswarnDeprecationWarning)selfr   r   a/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/pydantic_ai/profiles/openai.py__post_init__6   s   z OpenAIModelProfile.__post_init__)__name__
__module____qualname____doc__r   __annotations__r   r   r   r   r   r   r   r    r   r   r   r   r      s&   
 r   
model_namestrreturnr   c              
   C  s|   |  d}|  d}|p|od| v}d| v }|rd}nd}|  dr$dnd	}ttd
d
|p7d| v p7d| v p7d| v ||||dS )z*Get the model profile for an OpenAI model.zgpt-5oz
gpt-5-chatz-search-preview)temperaturetop_ppresence_penaltyfrequency_penalty
logit_biaslogprobstop_logprobsr   zo1-minir   NTo3z4.14o)json_schema_transformersupports_json_schema_outputsupports_json_object_outputsupports_image_outputr   r   r   r   )
startswithr   OpenAIJsonSchemaTransformer)r&   is_gpt_5is_o_seriesis_reasoning_modelsupports_web_searchr   r   r   r   r   openai_model_profile?   s$   


r=   )	minLength	maxLengthpatternPropertiesunevaluatedPropertiespropertyNamesminPropertiesmaxPropertiesunevaluatedItemscontainsminContainsmaxContainsuniqueItems)	z	date-timetimedatedurationemailhostnameipv4ipv6uuidF)initc                      s@   e Zd ZdZddd fdd	Zd fddZdddZ  ZS )r8   ax  Recursively handle the schema to make it compatible with OpenAI strict mode.

    See https://platform.openai.com/docs/guides/function-calling?api-mode=responses#strict-mode for more details,
    but this basically just requires:
    * `additionalProperties` must be set to false for each object in the parameters
    * all fields in properties must be marked as required
    Nstrictschemar   rT   bool | Nonec                  s    t  j||d |d| _d S )NrS   $ref)super__init__getroot_ref)r   rU   rT   	__class__r   r   rY      s   z$OpenAIJsonSchemaTransformer.__init__r(   c                   sJ   t   }| jd ur#|dd  tdd| j}|| j|p!i  |S )NrW   z
^#/\$defs/ )	rX   walkr[   popresubupdatedefsrZ   )r   resultroot_keyr\   r   r   r_      s   

z OpenAIJsonSchemaTransformer.walkc                 C  sh  | dd  | dd  | dd  |dt}|tur0| jdu r(| dd  n| jd u r0d| _|d }rP|| jkr@d|d< t|d	krPd| dig|d
< i }tD ]}||t}|turd|||< qT|d }rt|tvrt||d< |d}|r| jdu rg }	|	 D ]\}}| | |	
| d|  qd|	}
|s|
n| d|
 d|d< n| jd u rd| _|d}d|v r| jdu r| d|d
< nd| _|dkr2| jdu rd|d< d|vrtttf  |d< t|d  |d< |S | jd u r2|dd dvr	d| _nd|d< d|vsd|vrd| _|S |d }|d  D ]}||vr0d| _q&|S )Ntitlez$schemadiscriminatordefaultTFrW   #r
   anyOfformatdescription=z, z ()typeoneOfobjectadditionalProperties
propertiesrequired)NF)r`   rZ   	_sentinelrT   is_strict_compatibler[   len_STRICT_INCOMPATIBLE_KEYS!_STRICT_COMPATIBLE_STRING_FORMATSitemsappendjoindictr'   r   listkeys)r   rU   ri   
schema_refincompatible_valueskeyvaluerl   rm   notesnotes_stringschema_typeru   kr   r   r   	transform   sv   












z%OpenAIJsonSchemaTransformer.transform)rU   r   rT   rV   )r(   r   )rU   r   r(   r   )r!   r"   r#   r$   rY   r_   r   __classcell__r   r   r\   r   r8      s
    r8   )r&   r'   r(   r   )
__future__r   _annotationsra   r   collections.abcr   dataclassesr   typingr   r   _json_schemar   r	   r^   r   OpenAISystemPromptRoler   r=   ry   rz   rr   rv   r8   r   r   r   r   <module>   s"    
/*