
    Li/                     b   d Z ddlZddlZddlmZmZmZmZ ddlm	Z	 ddl
mZ ddl
mZ ddl
mZ dd	l
mZ  ej                   d
      Zdej$                  defdZ	 ddej$                  deej*                     dej$                  fdZ G d dej.                        Z G d dej.                        Zy)z&[Experimental] Auth Tokens API client.    N)AnyDictListOptional)	urlencode   )_api_module)_common)_tokens_converters)typeszgoogle_genai.tokenssetupreturnc                     g }| j                         D ]N  \  }}t        |t              r%|r#|j                         D cg c]	  }| d|  }}n|g}|j	                  |       P dj                  |      S c c}w )zReturn field_masks.,)items
isinstancedictkeysextendjoin)r   fieldskvkkfields         Q/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/google/genai/tokens.py_get_field_masksr      sx    &kkm da!Tq%&VVX.r!AbT{.e.ce
MM% 
&	 /s   A5request_dictconfigc                     | j                  d      }|r|j                  d      r|j                  d      | d<   t        | d         }t        |t              r"|j                  d      |j                  d      r2t        |t        j
                        r|j                  |j                  s|| d<   n7t        |t              r|j                  d      &t        |t        j
                        r|j                  | j                  dd       n| d   r| j                  d      }t	        j                         j                         j                         }|r$g }|D ]  }||v rd| }|j                  |        ng }|r|dz   dj                  |      z   n|| d<   nP| j                  dd       n=| j                  dg       }dj                  |      }|r|| d<   n| j                  dd       | j                  d      s| j                  dd       | S )z"Converts bidiGenerateContentSetup.bidiGenerateContentSetupr   lock_additional_fieldsN	fieldMaskzgenerationConfig.r   )getr   r   r   r   CreateAuthTokenConfigr#   popGenerationConfig
model_dumpr   appendr   )	r   r    
bidi_setup
field_maskadditional_fields_listgeneration_config_listfield_mask_listr   field_mask_strs	            r   "_convert_bidi_setup_to_token_setupr1   ,   s   
  :;*JNN7+ 0:~~g/FL+, ",/I"JKJ 	64 JJ/0<

3465667))5-- #-l;64 JJ/0865667))1 {D)	k	"4@4D4D
5  %557BBDIIK	+ 	(E,,'w/E

 
 
'	(
   s
SXXo6
6 ; {D)!!+r2JXXj)N"0l;{D)			4	5/6	    c                   ~    e Zd ZdZ ej
                  d      dddeej                     dej                  fd       Z
y)Tokenszb[Experimental] Auth Tokens API client.

  This class provides methods for creating auth tokens.
  [The SDK's token creation implementation is experimental, and may change in future versions.Nr    r    r   c                ~   t        j                  |      }| j                  j                  rt	        d      t        j                  | j                  |      }|j                  d      }|rdj                  |      }nd}|j                  d      }|r| dt        |       }|j                  dd       |rt        ||      }d}|8|j                  ,|j                  j                  |j                  j                  }t        j                  |      }t        j                   |      }| j                  j#                  d	|||      }|j$                  si nt'        j(                  |j$                        }	t         j*                  j-                  |	|j/                         
      }
| j                  j1                  |
       |
S )a  [Experimental] Creates an auth token.

    Args:
      config (CreateAuthTokenConfig): Optional configuration for the request.

    The CreateAuthTokenConfig's `live_constrained_parameters` attrubite
    Can be used to lock the parameters of the live session so they
    can't be changed client side. This behavior has two basic modes depending on
    whether `lock_additional_fields` is set:

    If you do not pass `lock_additional_fields` the entire
    `live_constrained_parameters` is locked and can't be changed
    by the token's user.

    If you set `lock_additional_fields`, then the non-null fields of
    `live_constrained_parameters` are locked, and any additional fields
    specified in `lock_additional_fields`.

    Usage:

    .. code-block:: python

      # Case 1: If LiveEphemeralParameters is unset, unlock LiveConnectConfig
      # when using the token in Live API sessions. Each session connection can
      # use a different configuration.

      config = types.CreateAuthTokenConfig(
          uses=10,
          expire_time='2025-05-01T00:00:00Z',
      )
      auth_token = client.tokens.create(config=config)

    .. code-block:: python

      # Case 2: If LiveEphemeralParameters is set, lock all fields in
      # LiveConnectConfig when using the token in Live API sessions. For
      # example, changing `output_audio_transcription` in the Live API
      # connection will be ignored by the API.

      auth_token = client.tokens.create(
          config=types.CreateAuthTokenConfig(
              uses=10,
              live_constrained_parameters=types.LiveEphemeralParameters(
                  model='gemini-live-2.5-flash-preview',
                  config=types.LiveConnectConfig(
                      system_instruction='You are an LLM called Gemini.'
                  ),
              ),
          )
      )

    .. code-block:: python

      # Case 3: If LiveEphemeralParameters is set and lockAdditionalFields is
      # empty, lock LiveConnectConfig with set fields (e.g.
      # system_instruction in this example) when using the token in Live API
      # sessions.
      auth_token = client.tokens.create(
          config=types.CreateAuthTokenConfig(
              uses=10,
              live_constrained_parameters=types.LiveEphemeralParameters(
                  config=types.LiveConnectConfig(
                      system_instruction='You are an LLM called Gemini.'
                  ),
              ),
              lock_additional_fields=[],
          )
      )

    .. code-block:: python

      # Case 4: If LiveEphemeralParameters is set and lockAdditionalFields is
      # set, lock LiveConnectConfig with set and additional fields (e.g.
      # system_instruction, temperature in this example) when using the token
      # in Live API sessions.
      auth_token = client.tokens.create(
          config=types.CreateAuthTokenConfig(
              uses=10,
              live_constrained_parameters=types.LiveEphemeralParameters(
                  model='gemini-live-2.5-flash-preview',
                  config=types.LiveConnectConfig(
                      system_instruction='You are an LLM called Gemini.'
                  ),
              ),
              lock_additional_fields=['temperature'],
          )
      )
    r6   =This method is only supported in the Gemini Developer client._urlauth_tokens_query?r    Npostresponsekwargs)r   CreateAuthTokenParameters_api_clientvertexai
ValueErrortokens_converters#_CreateAuthTokenParameters_to_mldevr%   
format_mapr   r'   r1   r    http_optionsr
   convert_to_dictencode_unserializable_typesrequestbodyjsonloads	AuthToken_from_responser)   _verify_responseselfr    parameter_modelr   request_url_dictpathquery_paramsrH   r?   response_dictreturn_values              r   createzTokens.createw   s   @ 55O   
I  'JJ



l &))&1	''(89##H-LvQy./0d Xt$ 7fMl04L#"".""//;$++88l**<8L66|DL''lLH 'mmBHMM1JM??11'A'A'C 2 L 	%%l3r2   __name__
__module____qualname____doc__r
   experimental_warningr   r   CreateAuthTokenConfigOrDictrO   rZ    r2   r   r4   r4   q   sW    
  7+
 FJO A ABOO	Or2   r4   c                   ~    e Zd ZdZ ej
                  d      dddeej                     dej                  fd       Z
y)AsyncTokenszu[Experimental] Async Auth Tokens API client.

  This class provides asynchronous methods for creating auth tokens.
  r5   Nr6   r    r   c                  K   t        j                  |      }| j                  j                  rt	        d      t        j                  | j                  |      }|j                  d      }|rdj                  |      }nd}|j                  d      }|r| dt        |       }|j                  dd       t        ||      }d}|8|j                  ,|j                  j                  |j                  j                  }t        j                  |      }t        j                   |      }| j                  j#                  d	|||
       d{   }|j$                  si nt'        j(                  |j$                        }	t         j*                  j-                  |	|j/                               }
| j                  j1                  |
       |
S 7 }w)a  Creates an auth token asynchronously. Support in v1alpha only.

    Args:
      config (CreateAuthTokenConfig): Optional configuration for the request.

    Usage:

    .. code-block:: python

      client = genai.Client(
          api_key=API_KEY,
          http_options=types.HttpOptions(api_version='v1alpha'),
      )

      auth_token = await client.aio.tokens.create(
          config=types.CreateAuthTokenConfig(
              uses=10,
              live_constrained_parameters=types.LiveEphemeralParameters(
                  model='gemini-live-2.5-flash-preview',
                  config=types.LiveConnectConfig(
                      system_instruction='You are an LLM called Gemini.'
                  ),
              ),
          )
      )
    r6   r8   r9   r:   r;   r<   r    Nr=   )rH   r>   )r   rA   rB   rC   rD   rE   rF   r%   rG   r   r'   r1   r    rH   r
   rI   rJ   async_requestrL   rM   rN   rO   rP   r)   rQ   rR   s              r   rZ   zAsyncTokens.create  s    D 55O
   
I  'JJ



l &))&1	''(89##H-LvQy./0dXt$ 6lFKL04L#"".""//;$++88l**<8L66|DL%%33!	 4  H 'mmBHMM1JM??11'A'A'C 2 L 	%%l3s   EG

GA>G
r[   rb   r2   r   rd   rd     sW    
  7+
 FJS A ABSS	Sr2   rd   )N)r_   rM   loggingtypingr   r   r   r   urllib.parser    r	   r
   r   rE   r   	getLoggerlogger
StringDictstrr   ra   r1   
BaseModuler4   rd   rb   r2   r   <module>rp      s     -   , , "   5 			0	1G.. 3   ;?B$$BU667B BJY[## Yx]+(( ]r2   