o
    ii                     @  s   d dl mZ d dlZd dlZd dlmZmZ d dlm	Z	 ej
dk r(d dlmZ neZer2ddlmZ d	ZG d
d deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd dee ZG dd deZG dd deZdS )     )annotationsN)TYPE_CHECKINGAny)core_schema)      )ExceptionGroup   )RetryPromptPart)

ModelRetryCallDeferredApprovalRequired	UserErrorAgentRunErrorUnexpectedModelBehaviorUsageLimitExceededModelHTTPErrorIncompleteToolCallFallbackExceptionGroupc                      sP   e Zd ZU dZded< 	 d fddZdd
dZdddZedddZ	  Z
S )r   zException to raise when a tool function should be retried.

    The agent will return the message to the model and ask it to try calling the function/tool again.
    strmessagec                      || _ t | d S Nr   super__init__selfr   	__class__ \/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/pydantic_ai/exceptions.pyr   (      zModelRetry.__init__otherr   returnboolc                 C  s   t || jo|j| jkS r   )
isinstancer   r   )r   r#   r    r    r!   __eq__,   s   zModelRetry.__eq__intc                 C  s   t | j| jfS r   )hashr   r   r   r    r    r!   __hash__/   s   zModelRetry.__hash_____core_schema.CoreSchemac                 C  sJ   t t t  t t dgd}t jdd |t jdd |ddS )z@Pydantic core schema to allow `ModelRetry` to be (de)serialized.model-retryr   kindc                 S  s   t | d S )Nr   )r   )dctr    r    r!   <lambda><       z9ModelRetry.__get_pydantic_core_schema__.<locals>.<lambda>c                 S  s   | j ddS )Nr/   r0   r   )xr    r    r!   r3   ?   r4   )return_schema)serialization)r   typed_dict_schematyped_dict_field
str_schemaliteral_schema no_info_after_validator_function$plain_serializer_function_ser_schema)clsr,   r-   schemar    r    r!   __get_pydantic_core_schema__2   s   z'ModelRetry.__get_pydantic_core_schema__r   r   )r#   r   r$   r%   )r$   r(   )r,   r   r-   r   r$   r.   )__name__
__module____qualname____doc____annotations__r   r'   r+   classmethodrA   __classcell__r    r    r   r!   r      s   
 

r   c                   @     e Zd ZdZdS )r   zException to raise when a tool call should be deferred.

    See [tools docs](../deferred-tools.md#deferred-tools) for more information.
    NrC   rD   rE   rF   r    r    r    r!   r   E       r   c                   @  rJ   )r   zException to raise when a tool call requires human-in-the-loop approval.

    See [tools docs](../deferred-tools.md#human-in-the-loop-tool-approval) for more information.
    NrK   r    r    r    r!   r   N   rL   r   c                      s.   e Zd ZU dZded< 	 d fddZ  ZS )r   uE   Error caused by a usage mistake by the application developer — You!r   r   c                   r   r   r   r   r   r    r!   r   ]   r"   zUserError.__init__rB   rC   rD   rE   rF   rG   r   rI   r    r    r   r!   r   W   s
   
 r   c                      s8   e Zd ZU dZded< 	 d	 fddZd
ddZ  ZS )r   z4Base class for errors occurring during an agent run.r   r   c                   r   r   r   r   r   r    r!   r   h   r"   zAgentRunError.__init__r$   c                 C  s   | j S r   r5   r*   r    r    r!   __str__l   s   zAgentRunError.__str__rB   r$   r   rC   rD   rE   rF   rG   r   rN   rI   r    r    r   r!   r   b   s   
 r   c                   @  rJ   )r   z?Error raised when a Model's usage exceeds the specified limits.NrK   r    r    r    r!   r   p       r   c                      sD   e Zd ZU dZded< 	 ded< 	 dd fddZdd
dZ  ZS )r   zLError caused by unexpected Model behavior, e.g. an unexpected response code.r   r   
str | NonebodyNc                   sZ   || _ |d u rd | _nztjt|dd| _W n ty$   || _Y nw t | d S )N   )indent)r   rS   jsondumpsloads
ValueErrorr   r   )r   r   rS   r   r    r!   r   |   s   
z UnexpectedModelBehavior.__init__r$   c                 C  s   | j r| j d| j  S | jS )Nz, body:
)rS   r   r*   r    r    r!   rN      s   zUnexpectedModelBehavior.__str__r   )r   r   rS   rR   rO   rP   r    r    r   r!   r   t   s   
 r   c                      sN   e Zd ZU dZded< 	 ded< 	 ded< 	 ded< 	 dd fd
dZ  ZS )r   zGRaised when an model provider response has a status code of 4xx or 5xx.r(   status_coder   
model_nameobject | NonerS   r   Nc                   s8   || _ || _|| _d| d| d| }t | d S )Nzstatus_code: z, model_name: z, body: )rZ   r[   rS   r   r   )r   rZ   r[   rS   r   r   r    r!   r      s
   zModelHTTPError.__init__r   )rZ   r(   r[   r   rS   r\   rM   r    r    r   r!   r      s   
 r   c                   @  rJ   )r   zGA group of exceptions that can be raised when all fallback models fail.NrK   r    r    r    r!   r      rQ   r   c                      s"   e Zd ZdZd fddZ  ZS )ToolRetryErrorzMException used to signal a `ToolRetry` message should be returned to the LLM.
tool_retryr
   c                   s   || _ t   d S r   )r^   r   r   )r   r^   r   r    r!   r      s   zToolRetryError.__init__)r^   r
   )rC   rD   rE   rF   r   rI   r    r    r   r!   r]      s    r]   c                   @  rJ   )r   zNError raised when a model stops due to token limit while emitting a tool call.NrK   r    r    r    r!   r      rQ   r   )
__future__r   _annotationsrV   systypingr   r   pydantic_corer   version_infoexceptiongroupr   messagesr
   __all__	Exceptionr   r   r   RuntimeErrorr   r   r   r   r   r   r]   r   r    r    r    r!   <module>   s,    
&		