
    .IikA                       % S SK Jr  S SKJrJrJr  S SKrS SKrS SKJrJ	r	J
r
  S SKJr  S SKrS SKJr  \R                   r\
\\\4   r0 \R(                  \R(                  _S \R(                  _S\R(                  _S\R(                  _\R*                  \R*                  _S	\R*                  _S
\R*                  _S\R*                  _\R,                  \R,                  _S\R,                  _S\R,                  _S\R,                  _\R.                  \R.                  _S\R.                  _S\R.                  _S\R.                  _\R0                  \R0                  _S\R.                  S\R0                  S\R0                  \R2                  \R2                  S\R2                  S\R2                  S\R2                  \R4                  \R4                  S\R4                  S\R4                  S\R4                  0ErS\S'   S?S jrSSS.       S@S jjrSAS  jr " S! S"5      r \!\S#4   r"\
\#\\$\"\%S#   S4   r& " S$ S%\ 5      r'\
\ \R@                  \!\\4   \	S&\4   4   r(    SBS' jr)SCS( jr* " S) S*5      r+ " S+ S,\5      r,\
\+\RV                  \,\\(   \(4   r-SDS- jr. " S. S/5      r/\
\\-   \-4   r0SES0 jr1\
\/\04   r2SFS1 jr3\Rh                  Rj                  r6S	\6Rn                  \6Rn                  \6Rn                  S2\6Rn                  S3\6Rn                  S\6Rp                  \6Rp                  \6Rp                  S4\6Rp                  S5\6Rp                  S\6Rr                  \6Rr                  \6Rr                  S6\6Rr                  S7\6Rr                  0r:\
\6\\4   r;SGS8 jr< " S9 S:\5      r=\
\;\=\Rh                  4   r>SHS; jr? " S< S=5      r@\
\@\R                  4   rBSIS> jrCg)J    )annotations)IterableMappingSequenceN)AnyCallableUnion)	TypedDict)protostype_unspecifiedunspecified   type_stringstring   type_numbernumber   type_integerinteger   type_booleanboolean   
type_arrayarray   type_objectobjectzdict[TypeOptions, Type]
_TYPE_TYPEc                ^    [        U [        5      (       a  U R                  5       n [        U    $ N)
isinstancestrlowerr    xs    C/venv/lib/python3.13/site-packages/google/generativeai/responder.pyto_typer)   ?   s$    !SGGIa=    )descriptionsrequiredc                  Uc  0 nUc  / n[        [        R                  " U 5      R                  5      nUR	                  5        VVs0 s H  u  pEUR
                  [        R                  R                  [        R                  R                  [        R                  R                  4;   d  Mb  UUR                  [        R                  R                  :w  a  UR                  O[        [        R                  " UR                  US5      S94_M     nnn[        R                   " U R"                  40 UD6R%                  5       nUR'                  SS5        UR                  S0 5      R	                  5        Hx  u  pHUR'                  SS5        X4   R                  n	[(        R*                  " U	5      [(        R,                  L d  MN  [/        S5      [(        R0                  " U	5      ;   d  Ms  SUS'   Mz     U(       a  X'S'   OU V
s/ s H  n
X:   R2                  [        R                  R                  :X  d  M/  X:   R
                  [        R                  R                  [        R                  R                  [        R                  R                  4;   d  M  U
PM     sn
US'   [        U R"                  U R4                  US9nU$ s  snnf s  sn
f )	a  Generates the OpenAPI Schema for a python function.

Args:
    f: The function to generate an OpenAPI Schema for.
    descriptions: Optional. A `{name: description}` mapping for annotating input
        arguments of the function with user-provided descriptions. It
        defaults to an empty dictionary (i.e. there will not be any
        description for any of the inputs).
    required: Optional. For the user to specify the set of required arguments in
        function calls to `f`. If unspecified, it will be automatically
        inferred from `f`.

Returns:
    dict[str, Any]: The OpenAPI Schema for the function `f` in JSON format.
N)descriptiontitle
propertiesTnullabler,   namer.   
parameters)dictinspect	signaturer4   itemskind	ParameterPOSITIONAL_OR_KEYWORDKEYWORD_ONLYPOSITIONAL_ONLY
annotationemptyr   pydanticFieldgetcreate_model__name__model_json_schemapoptyping
get_originr	   typeget_argsdefault__doc__)fr+   r,   defaultsr3   paramfields_dictr4   function_argr>   kschemas               r(   _generate_schemarT   E   sd   * G%%a(334H  $>>+ ,KD::33**--

!	
 "'!1!1W5F5F5L5L!LURUNN ),,T48	
 	
 ,  0 &&qzzA[ASSUJ
 NN7D!(nn\2>DDF$'^..

 Z(FLL8T$Z6??L
 >
 (,L$ G !):
 "
##w'8'8'>'>>  K$$%%;;%%22%%55	 "

: qzzqyyZPFM{^"
s!   A!J=,A#J=?.K1AKKc                   U c  U $ U R                  5       n U R                  SS 5      nUb  XS'   U R                  SS 5      nUb  [        U5      U S'   U R                  SS 5      nUb  X S'   U R                  SS 5      nUb  [	        U5      U S'   U R                  SS 5      nUb2  UR                  5        VVs0 s H  u  pVU[	        U5      _M     snnU S'   U $ s  snnf )NrI   type_formatformat_r8   r0   )copyrF   rB   r)   _rename_schema_fieldsr8   )rS   rV   rX   r8   r0   rR   vs          r(   rZ   rZ      s    ~[[]FJJvt$EwJJw%E!%.wjj4(G#yJJw%E/6wL$/JHRHXHXHZ[HZ#8#; ;HZ[|M  \s   6Cc                      \ rS rSrSS.SS jjr\SS j5       r\SS j5       r\SS j5       r\	SS j5       r
SS	 jr\SSS
 jj5       rSrg)FunctionDeclaration   Nr4   c               J    [         R                  " X[        U5      S9U l        g)zmA  class wrapping a `protos.FunctionDeclaration`, describes a function for `genai.GenerativeModel`'s `tools`.r2   N)r   r]   rZ   _proto)selfr3   r.   r4   s       r(   __init__FunctionDeclaration.__init__   s     00;PQ[;\
r*   c                .    U R                   R                  $ r"   )ra   r3   rb   s    r(   r3   FunctionDeclaration.name   s    {{r*   c                .    U R                   R                  $ r"   )ra   r.   rf   s    r(   r.   FunctionDeclaration.description   s    {{&&&r*   c                .    U R                   R                  $ r"   )ra   r4   rf   s    r(   r4   FunctionDeclaration.parameters   s    {{%%%r*   c                "    U " SS0 S9nXl         U$ )N r2   ra   )clsprotorb   s      r(   
from_protoFunctionDeclaration.from_proto   s    r:r*   c                    U R                   $ r"   rn   rf   s    r(   to_protoFunctionDeclaration.to_proto       {{r*   c                <    Uc  0 n[        XS9n[        S0 UDSU 0D6$ )a  Builds a `CallableFunctionDeclaration` from a python function.

The function should have type annotations.

This method is able to generate the schema for arguments annotated with types:

`AllowedTypes = float | int | str | list[AllowedTypes] | dict`

This method does not yet build a schema for `TypedDict`, that would allow you to specify the dictionary
contents. But you can build these manually.
)r+   function )rT   CallableFunctionDeclaration)rx   r+   rS   s      r(   from_function!FunctionDeclaration.from_function   s,     L!(F*GVGhGGr*   rn   )r3   r$   r.   r$   r4   dict[str, Any] | None)returnr$   )r~   zprotos.Schema)r~   r]   )r~   protos.FunctionDeclarationr"   )rx   Callable[..., Any]r+   zdict[str, str] | None)rD   
__module____qualname____firstlineno__rc   propertyr3   r.   r4   classmethodrq   rt   staticmethodr{   __static_attributes__ry   r*   r(   r]   r]      su    [_ 
     ' ' & &  
 H Hr*   r]   	ValueTypec                  P   ^  \ rS rSrSrSS.       SU 4S jjjrS	S jrSrU =r$ )
rz      zAn extension of `FunctionDeclaration` that can be built from a Python function, and is callable.

Note: The Python function must have type annotations.
Nr_   c               .   > [         TU ]  XUS9  X@l        g )Nr2   )superrc   rx   )rb   r3   r.   r4   rx   	__class__s        r(   rc   $CallableFunctionDeclaration.__init__   s     	d
S r*   c                    U R                   " S0 UR                  D6n[        U[        5      (       d  SU0n[        R
                  " UR                  US9$ )Nresult)r3   responsery   )rx   argsr#   r5   r   FunctionResponser3   )rb   fcr   s      r(   __call__$CallableFunctionDeclaration.__call__  sE    ))&$'''F&&BGGfEEr*   )rx   )r3   r$   r.   r$   r4   r}   rx   r   )r   protos.FunctionCallr~   zprotos.FunctionResponse)	rD   r   r   r   rL   rc   r   r   __classcell__)r   s   @r(   rz   rz      sK     -1	! 	! 		!
 *	! %	! 	!F Fr*   rz   .c                B   [        U [        [        R                  45      (       a  U $ [        U [        5      (       a  SU ;   a  [	        S0 U D6$ [        S0 U D6$ [        U 5      (       a  [        R                  U 5      $ [        S[        U 5      R                   S3U 5      e)Nrx   z_Invalid argument type: Expected an instance of `genai.FunctionDeclarationType`. Received type: .ry   )
r#   r]   r   r5   rz   callabler{   	TypeErrorrI   rD   )funs    r(   _make_function_declarationr     s     #+V-G-GHII
	C		.555&---	#*88==mnrsvnw  oA  oA  nB  BC  D
 	
r*   c                d    [        U [        R                  5      (       a  U $ U R                  5       $ r"   )r#   r   r]   rt   )fds    r(   
_encode_fdr   $  s&    "f0011	;;=r*   c                  X    \ rS rSrSrS
S jr\SS j5       r    SS jrSS jr	S r
Srg	)Tooli+  z\A wrapper for `protos.Tool`, Contains a collection of related `FunctionDeclaration` objects.c                   U Vs/ s H  n[        U5      PM     snU l        0 U l        U R                   HA  nUR                  nX@R                  ;   a  [	        S5      eX0R                  UR                  '   MC     [
        R                  " U R                   Vs/ s H  n[        U5      PM     snS9U l        g s  snf s  snf )Nrm   function_declarations)	r   _function_declarations_indexr3   
ValueErrorr   r   r   ra   )rb   r   rM   r   r3   s        r(   rc   Tool.__init__.  s    Nc&dNc'A!'DNc&d#--B77D{{" n$#%KK 	 . kk<@<W<W"X<Wb:b><W"X
 'e #Ys   B8B=c                    U R                   $ r"   )r   rf   s    r(   r   Tool.function_declarations<  s    ***r*   c                b    [        U[        5      (       d  UR                  nU R                  U   $ r"   r#   r$   r3   r   rb   r3   s     r(   __getitem__Tool.__getitem__@  )     $$$99D{{4  r*   c                <    X   n[        U5      (       d  g U" U5      $ r"   )r   )rb   r   declarations      r(   r   Tool.__call__H  s!    h$$2r*   c                    U R                   $ r"   rn   rf   s    r(   rt   Tool.to_protoO  rv   r*   )r   r   ra   N)r   z!Iterable[FunctionDeclarationType])r~   z6list[FunctionDeclaration | protos.FunctionDeclaration]r3   zstr | protos.FunctionCallr~   0FunctionDeclaration | protos.FunctionDeclaration)r   r   r~   zprotos.FunctionResponse | None)rD   r   r   r   rL   rc   r   r   r   r   rt   r   ry   r*   r(   r   r   +  s=    f
 + +!-!	9!r*   r   c                       \ rS rSr% S\S'   Srg)ToolDictiS  zlist[FunctionDeclarationType]r   ry   NrD   r   r   r   __annotations__r   ry   r*   r(   r   r   S  s    88r*   r   c                   [        U [        5      (       a  U $ [        U [        R                  5      (       a  [        U R                  S9$ [        U [        5      (       a1  SU ;   a  [        S0 U D6$ U n[        [        R
                  " S0 UD6/S9$ [        U [        5      (       a	  [        U S9$  [        U /S9$ ! [         a)  n[        S[        U 5      R                   S3U 5      UeS nAff = f)Nr   r   zPInvalid argument type: Expected an instance of `genai.ToolType`. Received type: r   ry   )r#   r   r   r   r5   r]   r   	Exceptionr   rI   rD   )toolr   es      r(   
_make_toolr   \  s    $	D&++	&	&$*D*DEE	D$		"d*<$<Bv/I/I/OB/O.PQQ	D(	#	#$//	tf55 	bcghlcmcvcvbwwxy 	s   /	B9 9
C,$C''C,c                  D    \ rS rSrSrS	S jr    S
S jrSS jrS rSr	g)FunctionLibraryis  zYA container for a set of `Tool` objects, manages lookup and execution of their functions.c                   [        U5      n[        U5      U l        0 U l        U R                   HX  nUR                   HE  nUR
                  nX@R                  ;   a  [        SU S35      eX0R                  UR
                  '   MG     MZ     g )Nz2Invalid operation: A `FunctionDeclaration` named 'zI' is already defined. Each `FunctionDeclaration` must have a unique name.)_make_toolslist_toolsr   r   r3   r   )rb   toolsr   r   r3   s        r(   rc   FunctionLibrary.__init__v  s    E"5kKKD#99"'';;&$LTF  S\  ]  1<K,,-  :  r*   c                b    [        U[        5      (       d  UR                  nU R                  U   $ r"   r   r   s     r(   r   FunctionLibrary.__getitem__  r   r*   c                d    X   n[        U5      (       d  g U" U5      n[        R                  " US9$ )N)function_response)r   r   Part)rb   r   r   r   s       r(   r   FunctionLibrary.__call__  s/    h$$r?{{X66r*   c                `    U R                    Vs/ s H  oR                  5       PM     sn$ s  snf r"   )r   rt   )rb   r   s     r(   rt   FunctionLibrary.to_proto  s"    ,0KK8KDK888s   +)r   r   N)r   zIterable[ToolType]r   )r   r   r~   zprotos.Part | None)
rD   r   r   r   rL   rc   r   r   rt   r   ry   r*   r(   r   r   s  s)    c<!-!	9!79r*   r   c                ^   [        U [        5      (       a  [        U [        5      (       dl  U  Vs/ s H  n[        U5      PM     n n[	        U 5      S:  a@  [        S U  5       5      (       a)  [        U  Vs/ s H  oR                  S   PM     sn5      /n U $ U n[        U5      /$ s  snf s  snf )Nr   c              3  R   #    U  H  n[        UR                  5      S :H  v   M     g7f)r   N)lenr   ).0ts     r(   	<genexpr>_make_tools.<locals>.<genexpr>  s      !SU#a&=&=">!"CUs   %'r   )r#   r   r   r   r   allr   )r   r   r   s      r(   r   r     s    %"":eW+E+E(-.1A.u:>c!SU!SSSU KU!8!8!;U KLME4 !! / !Ls   B%5B*c                L    U c  U $ [        U [        5      (       a  U $ [        U S9$ )N)r   )r#   r   )libs    r(   to_function_libraryr     s)    
{
	C	)	)
S))r*   	mode_autoautomode_anyany	mode_nonenonec                ^    [        U [        5      (       a  U R                  5       n [        U    $ r"   )r#   r$   r%   _FUNCTION_CALLING_MODEr&   s    r(   to_function_calling_moder     s%    !SGGI!!$$r*   c                  *    \ rS rSr% S\S'   S\S'   Srg)FunctionCallingConfigDicti  FunctionCallingModeTypemodez	list[str]allowed_function_namesry   Nr   ry   r*   r(   r   r     s    
!!%%r*   r   c                   [        U [        R                  5      (       a  U $ [        U [        [        [
        45      (       a  S[        U 5      0n Oh[        U [        5      (       a0  U R                  5       n U R                  S5      n[        U5      U S'   O#[        S[        U 5      R                   S3U 5      e[        R                  " U 5      $ )Nr   zaInvalid argument type: Could not convert input to `protos.FunctionCallingConfig`. Received type: r   )r#   r   FunctionCallingConfigFunctionCallingModer$   intr   r5   rY   rF   r   rI   rD   )objr   s     r(   to_function_calling_configr     s    #v3344
	C-sC8	9	9/45	C		hhjwwv.t4F#Cy112!5
 	
 '',,r*   c                       \ rS rSr% S\S'   Srg)ToolConfigDicti  FunctionCallingConfigTypefunction_calling_configry   Nr   ry   r*   r(   r   r     s    66r*   r   c                   [        U [        R                  5      (       a  U $ [        U [        5      (       a6  U R	                  S5      n[        U5      nXS'   [        R                  " S0 U D6$ [        S[        U 5      R                   S35      e)Nr   zVInvalid argument type: Could not convert input to `protos.ToolConfig`. Received type: r   ry   )	r#   r   
ToolConfigr5   rF   r   r   rI   rD   )r   fccs     r(   to_tool_configr     s    #v(())
	C		gg/0(-),%&  '3''"3i0014
 	
r*   )r'   TypeOptionsr~   Type)rM   r   r+   zMapping[str, str] | Noner,   zSequence[str] | Noner~   dict[str, Any])rS   r   )r   FunctionDeclarationTyper~   r   )r   r   r~   r   )r   ToolTyper~   r   )r   	ToolsTyper~   z
list[Tool])r   zFunctionLibraryType | Noner~   zFunctionLibrary | None)r'   r   r~   r   )r   r   r~   zprotos.FunctionCallingConfig)r   ToolConfigTyper~   zprotos.ToolConfig)D
__future__r   collections.abcr   r   r   r6   rG   r   r   r	   typing_extensionsr
   r@   google.generativeair   r   r   r$   r   TYPE_UNSPECIFIEDSTRINGNUMBERINTEGERBOOLEANARRAYOBJECTr    r   r)   rT   rZ   r]   r5   
StructTypefloatboolr   r   rz   r   r   r   r   r   r   r   r   r   r   FunctionLibraryTyper   r   Moder   AUTOANYNONEr   r   r   r   r   r   r   r   r   r   ry   r*   r(   <module>r     sr   # 7 7   ' ' '  &{{CdN#'400't' --' 4((	'
 	KK' t{{' 4;;' dkk' 	KK' t{{' 4;;' dkk' 	LL$,,' t||' DLL'  t||!'" 	LL$,,#'$ t||DLLt||JJ

tzz$**TZZKKt{{4;;dkk9'
# @ .2%)	WW +W #	W
 Wt8/H /Hd #{"#
%dJ[0A4GH	F"5 F0  
cNS#X 
	 
5
&% %P9y 9 &++x*A!BD[[
.!9 !9H (8$h./		" OY67 * 2277  166$))
$$044#''	""166$))
$$ $   3S# => %&	 &
 "68T8TT 
-&7 7 ~v'8'889
r*   