
    7P[i                     
   d Z ddlmZmZmZmZmZ ddlZddlZddl	m
Z
 er
ddlmZ ddlZ G d de      Z G d	 d
e      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Ze
j.                  Zy)z Error classes for the GenAI SDK.    )AnyCallableOptionalTYPE_CHECKINGUnionN   )_common)ReplayResponsec                   Z    e Zd ZU dZeed<   edej                  df   ed<   dZ	e
e   ed<   dZe
e   ed<   	 dded	ede
edej                  df      f fd
Zdeed   eeeef      f   fdZedeeef   dd fd       Zd	edefdZd	edefdZd	edefdZdej2                  fdZededej                  f   ddfd       Zeded	ede
edej                  df      ddfd       Zededej                  df   ddfd       Zeded	ede
edej                  df      ddfd       Z xZ S )APIErrorz'General errors raised by the GenAI API.coder
   zaiohttp.ClientResponseresponseNstatusmessageresponse_jsonc                 ^   t        |t              rt        |      dk(  r|d   }|| _        || _        | j                  |      | _        | j                  |      | _        |r|n| j                  |      | _
        t        | 1  | j                   d| j                   d| j                          y )Nr   r    . )
isinstancelistlenr   details_get_messager   _get_statusr   	_get_coder   super__init__)selfr   r   r   	__class__s       a/var/www/html/chatbot/Makanify-Chatbot-2/venv/lib/python3.12/site-packages/google/genai/errors.pyr   zAPIError.__init__%   s     -&3}+=+B#A&mDM DL$$]3DL""=1DK$.."?DI	G		{!DKK=4<<.AB    return).r   c                 h    | j                   j                         }| j                  j                  |ffS )zGReturns a tuple that can be used to reconstruct the error for pickling.)__dict__copyr   _rebuild)r   states     r    
__reduce__zAPIError.__reduce__8   s-     MM ENN##eX..r!   r'   c                     t         j                  t               }|j                  j                  |        t        j                  ||j                   d|j                   d|j                          |S )z"Rebuilds the error from the state.r   r   )	r   __new__r$   update	Exceptionr   r   r   r   )r'   objs     r    r&   zAPIError._rebuild?   sX     

8
$CLLssxxj#**R}EFJr!   c                 f    |j                  d|j                  di       j                  dd             S )Nr   errorgetr   r   s     r    r   zAPIError._get_statusG   s4    -##GR044XtD r!   c                 f    |j                  d|j                  di       j                  dd             S )Nr   r/   r0   r2   s     r    r   zAPIError._get_messageL   s4    =$$Wb155iF r!   c                 f    |j                  d|j                  di       j                  dd             S )Nr   r/   r0   r2   s     r    r   zAPIError._get_codeQ   s4    !!'2.2264@ r!   c                 N    d| j                   | j                  | j                  diS )zReturns a dictionary representation of the error for replay recording.

    details is not included since it may expose internal information in the
    replay file.
    r/   r   r   r   r6   )r   s    r    _to_replay_recordzAPIError._to_replay_recordV   s+     	II||kk
 r!   c                    |j                   dk(  ryt        |t        j                        r"	 |j	                          |j                         }n|j                  d   j                  di       }| j                  |j                   ||       y# t
        j                  j                  $ r |j                  }||j                  d}Y Xw xY w)PRaises an error with detailed error message if the response has an error status.   Nr   r   r   r/   )status_coder   httpxResponsereadjsondecoderJSONDecodeErrortextreason_phrasebody_segmentsr1   raise_error)clsr   r   r   s       r    raise_for_responsezAPIError.raise_for_responsed   s    
 s"(ENN+
  ,,Q/33GR@mOOH((-B \\)) 
--,,

s    B
 
8CCr<   c                     d|cxk  rdk  rn nt        |||      d|cxk  rdk  rn nt        |||       | |||      a  Raises an appropriate APIError subclass based on the status code.

    Args:
      status_code: The HTTP status code of the response.
      response_json: The JSON body of the response, or a dict containing error
        details.
      response: The original response object.

    Raises:
      ClientError: If the status code is in the 4xx range.
      ServerError: If the status code is in the 5xx range.
      APIError: For other error status codes.
    i  i  iX  ClientErrorServerErrorrG   r<   r   r   s       r    rF   zAPIError.raise_error{   sK    , kC]H==		!c	!]H==]H55r!   c                   K   d}d}t        |t        j                        rF|j                  dk(  ry	 |j	                          d{    |j                         }|j                  }nt        |d      rHt        |d      r<|j                  dk(  ry|j                  d   j                  di       }|j                  }ni	 ddl}t        ||j                        r6|j                  dk(  ry	 |j                          d{   }|j                  }nt'        dt)        |             	 | j-                  |||       d{    y7 # t
        j                  j                  $ r |j                  }||j                  d}Y #w xY w7 # |j                   j"                  $ r+ |j                          d{  7  }||j$                  d}Y w xY w# t*        $ r t'        dt)        |             w xY w7 w)	r9   r   Nr:   r;   rE   r<   r/   zUnsupported response type: )r   r=   r>   r<   areadr@   rA   rB   rC   rD   hasattrrE   r1   aiohttpClientResponser   client_exceptionsContentTypeErrorreason
ValueErrortypeImportErrorraise_error_async)rG   r   r<   r   r   rR   s         r    raise_for_async_responsez!APIError.raise_for_async_response   s     KM(ENN+				$
nn  ((k	?	+-1 
			$,,Q/33GR@m((kIh 6 67__#"*--/1M !+8h8HIJ
J  

]H
EEEK 	\\)) 
--,,

, 2**;; $MMO++G""//M  I6tH~6FGHHI Fs   /G0E E E A!G0<)G
 %G0'F :F;F ?$G
 #G0:G.;G0 E 8E>:G0=E>>G0F ,G/F20GG
 GG
 
!G++G0c                    K   d|cxk  rdk  rn nt        |||      d|cxk  rdk  rn nt        |||       | |||      wrJ   rK   rN   s       r    rZ   zAPIError.raise_error_async   sO     & kC]H==		!c	!]H==]H55s   AA)N)!__name__
__module____qualname____doc__int__annotations__r   r=   r>   r   r   strr   r   r   tupler   dictr(   staticmethodr&   r   r   r   r	   
StringDictr7   classmethodrH   rF   r[   rZ   __classcell__)r   s   @r    r   r      s;   /)"ENN4LLMM&(3-'8C= CC C 
 %..2JJ
K	C&/Xo&d38n(==>/ d38n   s s 
  
S S 
!3!3  C+U^^;<CC C, 66 6 
 %..2JJ
K	6 6 68 2F
ENN,D
D2F
 2F 2Fh 66,/6;C
 %..2JJ
K<6 	6 6r!   r   c                       e Zd ZdZy)rL   z%Client error raised by the GenAI API.Nr]   r^   r_   r`    r!   r    rL   rL          -r!   rL   c                       e Zd ZdZy)rM   z%Server error raised by the GenAI API.Nrk   rl   r!   r    rM   rM      rm   r!   rM   c                       e Zd ZdZy) UnknownFunctionCallArgumentErrorzWRaised when the function call argument cannot be converted to the parameter annotation.Nrk   rl   r!   r    rp   rp      s    _r!   rp   c                       e Zd ZdZy)UnsupportedFunctionErrorz*Raised when the function is not supported.Nrk   rl   r!   r    rr   rr      s    2r!   rr   c                       e Zd ZdZy)FunctionInvocationErrorzDRaised when the function cannot be invoked with the given arguments.Nrk   rl   r!   r    rt   rt      s    Lr!   rt   c                       e Zd ZdZy)UnknownApiResponseErrorz?Raised when the response from the API cannot be parsed as JSON.Nrk   rl   r!   r    rv   rv     s    Gr!   rv   )r`   typingr   r   r   r   r   r=   r@    r	   replay_api_clientr
   rR   r,   r   rL   rM   rW   rp   rr   rt   rv   ExperimentalWarningrl   r!   r    <module>r{      s     ' @ @    /H6y H6V( 
( 
z 
z 
j 
j  11 r!   