
    
!iN                       % 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  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.                  _\R0                  \R0                  _S\R0                  _S\R0                  _S\R0                  _\R2                  \R2                  _S\R2                  _S\R2                  _S\R2                  _\R4                  \R4                  _S\R2                  S\R4                  S\R4                  \R6                  \R6                  S\R6                  S\R6                  S\R6                  \R8                  \R8                  S\R8                  S\R8                  S\R8                  0ErS\S'   SFS jrSSS.       SGS  jjr S! r!S" r"S# r#S$ r$S% r%S& r&SHS' jr' " S( S)5      r(\)\S*4   r*\
\+\\,\*\-S*   S4   r. " S+ S,\(5      r/\
\(\RP                  \)\\4   \	S-\4   4   r0    SIS. jr1SJS/ jr2 " S0 S15      r3 " S2 S3\5      r4\
\3\Rf                  \4\\0   \04   r5SKS4 jr6 " S5 S65      r7\
\\5   \54   r8SLS7 jr9\
\7\84   r:SMS8 jr;\Rx                  Rz                  r>S
\>R~                  \>R~                  \>R~                  S9\>R~                  S:\>R~                  S\>R                  \>R                  \>R                  S;\>R                  S<\>R                  S\>R                  \>R                  \>R                  S=\>R                  S>\>R                  0rB\
\>\\4   rCSNS? jrD " S@ SA\5      rE\
\C\E\Rx                  4   rFSOSB jrG " SC SD5      rH\
\H\R                  4   rJSPSE jrKg)Q    )annotations)IterableMappingSequenceN)AnyCallableUnion)	TypedDict)protos)content_types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    W/home/james-whalen/.local/lib/python3.13/site-packages/google/generativeai/responder.pyto_typer*   @   s$    !SGGIa=    )descriptionsrequiredc                  Uc  0 n[        [        R                  " U 5      R                  5      n0 nUR	                  5        H  u  pVUR
                  [        R                  R                  [        R                  R                  [        R                  R                  4;   d  Mb  [        R                  " UR                  US5      S9nUR                  [        R                  R                  :w  a  UR                  U4XE'   M  [        U4XE'   M     [!        U R"                  U5      nUb  X(S'   OU V	s/ s H  n	X9   R$                  [        R                  R                  :X  d  M/  X9   R
                  [        R                  R                  [        R                  R                  [        R                  R                  4;   d  M  U	PM     sn	US'   [        U R"                  U R&                  S9n
US   (       a  XS'   U
$ 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)descriptionr-   )namer/   
properties
parameters)dictinspect	signaturer2   itemskind	ParameterPOSITIONAL_OR_KEYWORDKEYWORD_ONLYPOSITIONAL_ONLYpydanticFieldget
annotationemptyr   _build_schema__name__default__doc__)fr,   r-   defaultsfields_dictr0   paramfieldr2   kschemas              r)   _generate_schemarL   F   s   * G%%a(334HK~~'::33**--
 
 NN(,,T48E 7#4#4#:#::$)$4$4e$;!$'J!+ (. qzz;7J !):
 "
##w'8'8'>'>>  K$$%%;;%%22%%55	 "

: qzzqyy9F,)|M#"
s   1.G<#AG<G<c                *   [         R                  " U 40 UD6R                  5       nUR                  S0 5      nUR	                  5        H  u  pE[        XS5        M     [        X#5        [        U5        [        U5        [        U5        [        U5        U$ )Nz$defs)
r<   create_modelmodel_json_schemapopr6   unpack_defsconvert_to_nullableadd_object_typestrip_titlesstrip_additional_properties)fnamerG   r2   defsr0   values         r)   rA   rA      s|    &&u<<NNPJ>>'2&Dzz|E  $
! 
#J
 
+r+   c                N   U R                  SS 5      nUc  g UR                  5        H  u  p4UR                  SS 5      nUb'  XR                  S5      S      n[        Xa5        XbU'   MA  UR                  SS 5      nUbR  [	        U5       HA  u  pU	R                  SS 5      nUc  M  XR                  S5      S      n[        Xa5        XgU'   MC     M  UR                  SS 5      n
U
c  M  U
R                  SS 5      nUc  M  XR                  S5      S      n[        Xa5        XdS'   M     g )Nr1   z$refzdefs/anyOfr6   )r>   r6   splitrQ   	enumerate)rK   rW   r1   r0   rX   ref_keyrefanyofiatyper6   s              r)   rQ   rQ      s*   L$/J!'')))FD)}}W-b12C""t		'4(%e,))FD1&}}W5b9:C*"!H - 		'4(ii-G"==1"56C&!$g3 *r+   c                    U R                  SS 5      nU R                  SS 5      nUb$  UR                  5        H  u  p4[        U5        M     U R                  SS 5      nUb  [        U5        g g )Ntitler1   r6   )rP   r>   r6   rT   )rK   rd   r1   r0   rX   r6   s         r)   rT   rT      sj    JJw%EL$/J%++-KD . JJw%EU r+   c                    U R                  SS 5        U R                  SS 5      nUb$  UR                  5        H  u  p#[        U5        M     U R                  SS 5      nUb  [        U5        g g )NadditionalPropertiesr1   r6   )rP   r>   r6   rU   rK   r1   r0   rX   r6   s        r)   rU   rU      si    
JJ%t,L$/J%++-KD'. . JJw%E#E* r+   c                    U R                  SS 5      nUb;  U R                  SS 5        SU S'   UR                  5        H  u  p#[        U5        M     U R                  SS 5      nUb  [        U5        g g )Nr1   r-   r    typer6   )r>   rP   r6   rS   rg   s        r)   rS   rS      sq    L$/J

:t$!v%++-KDE" . JJw%E r+   c                   U R                  SS 5      nUbb  [        U5      S:w  a  [        S5      eUu  p#USS0:X  a  U R                  U5        O%USS0:X  a  U R                  U5        O[        S5      eSU S'   U R	                  SS 5      nUb$  UR                  5        H  u  pV[        U5        M     U R	                  S	S 5      nUb  [        U5        g g )
Nr[   r   zInvalid input: Type Unions are not supported, except for `Optional` types. Please provide an `Optional` type or a non-Union type.ri   nullTnullabler1   r6   )rP   len
ValueErrorupdater>   r6   rR   )rK   r`   abr1   r0   rX   r6   s           r)   rR   rR      s    JJw%Eu:?I    MM!66""MM!I  "zL$/J%++-KD& . JJw%EE" r+   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_r6   r1   )copyrP   r>   r*   _rename_schema_fieldsr6   )rK   rs   ru   r6   r1   rJ   vs          r)   rw   rw     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)FunctionDeclarationi,  Nr2   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`.r0   r/   r2   N)r   rz   rw   _proto)selfr0   r/   r2   s       r)   __init__FunctionDeclaration.__init__-  s     00;PQ[;\
r+   c                .    U R                   R                  $ r#   )r~   r0   r   s    r)   r0   FunctionDeclaration.name3  s    {{r+   c                .    U R                   R                  $ r#   )r~   r/   r   s    r)   r/   FunctionDeclaration.description7  s    {{&&&r+   c                .    U R                   R                  $ r#   )r~   r2   r   s    r)   r2   FunctionDeclaration.parameters;  s    {{%%%r+   c                "    U " SS0 S9nXl         U$ )N r}   r~   )clsprotor   s      r)   
from_protoFunctionDeclaration.from_proto?  s    r:r+   c                    U R                   $ r#   r   r   s    r)   to_protoFunctionDeclaration.to_protoE      {{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 )rL   CallableFunctionDeclaration)r   r,   rK   s      r)   from_function!FunctionDeclaration.from_functionH  s,     L!(F*GVGhGGr+   r   )r0   r%   r/   r%   r2   dict[str, Any] | None)returnr%   )r   zprotos.Schema)r   rz   )r   protos.FunctionDeclarationr#   )r   Callable[..., Any]r,   zdict[str, str] | None)rB   
__module____qualname____firstlineno__r   propertyr0   r/   r2   classmethodr   r   staticmethodr   __static_attributes__r   r+   r)   rz   rz   ,  su    [_ 
     ' ' & &  
 H Hr+   rz   	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$ )
r   ib  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 )Nr}   )superr   r   )r   r0   r/   r2   r   	__class__s        r)   r   $CallableFunctionDeclaration.__init__h  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)r0   responser   )r   argsr$   r3   r   FunctionResponser0   )r   fcr   s      r)   __call__$CallableFunctionDeclaration.__call__s  sE    ))&$'''F&&BGGfEEr+   )r   )r0   r%   r/   r%   r2   r   r   r   )r   protos.FunctionCallr   zprotos.FunctionResponse)	rB   r   r   r   rD   r   r   r   __classcell__)r   s   @r)   r   r   b  sK     -1	! 	! 		!
 *	! %	! 	!F Fr+   r   .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)Nr   z_Invalid argument type: Expected an instance of `genai.FunctionDeclarationType`. Received type: .r   )
r$   rz   r   r3   r   callabler   	TypeErrorri   rB   )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   rz   r   )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 )Nr   function_declarations)	r   _function_declarations_indexr0   rn   r   r   r   r~   )r   r   rE   r   r0   s        r)   r   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   r   s    r)   r   Tool.function_declarations  s    ***r+   c                b    [        U[        5      (       d  UR                  nU R                  U   $ r#   r$   r%   r0   r   r   r0   s     r)   __getitem__Tool.__getitem__  )     $$$99D{{4  r+   c                <    X   n[        U5      (       d  g U" U5      $ r#   )r   )r   r   declarations      r)   r   Tool.__call__  s!    h$$2r+   c                    U R                   $ r#   r   r   s    r)   r   Tool.to_proto  r   r+   )r   r   r~   N)r   z!Iterable[FunctionDeclarationType])r   z6list[FunctionDeclaration | protos.FunctionDeclaration]r0   zstr | protos.FunctionCallr   0FunctionDeclaration | protos.FunctionDeclaration)r   r   r   zprotos.FunctionResponse | None)rB   r   r   r   rD   r   r   r   r   r   r   r   r   r+   r)   r   r     s=    f
 + +!-!	9!r+   r   c                       \ rS rSr% S\S'   Srg)ToolDicti  zlist[FunctionDeclarationType]r   r   NrB   r   r   r   __annotations__r   r   r+   r)   r   r     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   r   )r$   r   r   r   r3   rz   r   	Exceptionr   ri   rB   )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)FunctionLibraryi  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   r0   rn   )r   toolsr   r   r0   s        r)   r   FunctionLibrary.__init__  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)r   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   r   )r   r   s     r)   r   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)
rB   r   r   r   rD   r   r   r   r   r   r   r+   r)   r   r     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)rm   r   ).0ts     r)   	<genexpr>_make_tools.<locals>.<genexpr>  s      !SU#a&=&=">!"CUs   %'r   )r$   r   r   r   rm   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)FunctionCallingConfigDictiA  FunctionCallingModeTypemodez	list[str]allowed_function_namesr   Nr   r   r+   r)   r  r  A  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   r3   rv   rP   r   ri   rB   )objr  s     r)   to_function_calling_configr  K  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_configr   Nr   r   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   r   )	r$   r   
ToolConfigr3   rP   r  r   ri   rB   )r
  fccs     r)   to_tool_configr  e  s    #v(())
	C		gg/0(-),%&  '3''"3i0014
 	
r+   )r(   TypeOptionsr   Type)rE   r   r,   zMapping[str, str] | Noner-   zSequence[str] | Noner   dict[str, Any])rK   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)L
__future__r   collections.abcr   r   r   r4   typingr   r   r	   typing_extensionsr
   r<   google.generativeair   google.generativeai.typesr   r  r	  r%   r  TYPE_UNSPECIFIEDSTRINGNUMBERINTEGERBOOLEANARRAYOBJECTr!   r   r*   rL   rA   rQ   rT   rU   rS   rR   rw   rz   r3   
StructTypefloatboolr   r   r   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  r   r+   r)   <module>r0     s   # 7 7   ' ' '  & 3{{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%)	JJ +J #	J
 JZ.B

+
#<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+   