-;iNUddlmZddlmZmZmZddlZddlZddlmZm Z m Z ddl m Z ddl Z ddlmZddlmZejZe eeefZiejejdejdejd ejejejd ejd ejd ejejejd ejdejdejejejdejdejdejejejdejdejdejejejdejdejdejejejdejdejdeji Zded<dfd"Zddd#dgd+Z d,Z!d-Z"d.Z#d/Z$d0Z%d1Z&dhd3Z'Gd4d5Z(e)ed6fZ*e e+ee,e*e-d6dfZ.Gd7d8e(Z/e e(ej(e)eefe d9effZ0did=Z1djd@Z2GdAdBZ3GdCdDe Z4e e3ej3e4ee0e0fZ5dkdGZ6GdHdIZ7e ee5e5fZ8dldMZ9e e7e8fZ:dmdQZ;ej<j=Z>d e>j?e>j?e>j?dRe>j?dSe>j?d e>j@e>j@e>j@dTe>j@dUe>j@de>jAe>jAe>jAdVe>jAdWe>jAi ZBe e>eefZCdndZZDGd[d\e ZEe eCeEej<fZFdod`ZGGdadbZHe eHejIfZJdpdeZKdS)q) annotations)IterableMappingSequenceN)AnyCallableUnion) TypedDict)protos) content_typestype_unspecified unspecified type_stringstring type_numbernumber type_integerinteger type_booleanboolean type_arrayarray type_objectobjectzdict[TypeOptions, Type] _TYPE_TYPEx TypeOptionsreturnTypecnt|tr|}t|SN) isinstancestrlowerr!r"s QC:\PYTHON\MyICR_Workspace\venv\Lib\site-packages\google/generativeai/responder.pyto_typer-@s+!S GGII a=) descriptionsrequiredfCallable[..., Any]r/Mapping[str, str] | Noner0Sequence[str] | Nonedict[str, Any]cj |i}ttj|j i} D]\}}|jtjjtjjtjj fvr\tj | |d}|j tjjkr |j |f||<t|f||<t!|j|}|||d<n fd D|d<t|j|j}|dr||d<|S)aGenerates 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) descriptionr0cg|]c}|jtjjkrA|jtjjtjjtjjfva|dS)defaultinspect ParameteremptykindPOSITIONAL_OR_KEYWORD KEYWORD_ONLYPOSITIONAL_ONLY).0kdefaultss r, z$_generate_schema..su " " "  #w'8'>>>QK$%;%2%5 r.)namer7 properties parameters)dictr; signaturerHitemsr>r<r?r@rApydanticFieldget annotationr=r _build_schema__name____doc__) r1r/r0 fields_dictrFparamfieldrHschemarDs @r,_generate_schemarWFsh* G%a((344HK~~''// e :   3   *   -   N(,,T488E7#4#:::$)$4e$; D!!$'J D!qz;77J!) : " " " "  " " " :qzqy 9 9 9F,*)| Mr.cftj|fi|}|di}|D]\}}t ||t ||t |t|t|t||S)Nz$defs) rL create_modelmodel_json_schemapoprK unpack_defsconvert_to_nullableadd_object_type strip_titlesstrip_additional_properties)fnamerSrHdefsrFvalues r,rPrPs&u<< <<NNPPJ >>'2 & &Dzz||!! eE4     D!!!  ###J  +++ r.c|dd}|dS|D]9\}}|dd}|7||dd}t|||||<U|dd}|dt |D]S\}} | dd}|6||dd}t|||||<T|dd} | P| dd}|8||dd}t||||d<9;dS)NrGz$refzdefs/anyOfrK)rNrKsplitr\ enumerate) rVrbrGrFrcref_keyrefanyofiatyperKs r,r\r\sL$//J!'')) e))FD))  w}}W--b12C T " " ""Jt   '4((  %e,, # #5))FD11&w}}W55b9:CT***"E!H  '4((  ii--G"7==11"56C&&&!$g3r.c|dd}|dd}|)|D]\}}t||dd}|t|dSdS)NtitlerGrK)r[rNrKr_)rVrorGrFrcrKs r,r_r_s JJw % %EL$//J%++--  KD%      JJw % %E Ur.c|dd|dd}|)|D]\}}t||dd}|t|dSdS)NadditionalPropertiesrGrK)r[rNrKr`rVrGrFrcrKs r,r`r`s JJ%t,,,L$//J%++-- / /KD% ' . . . . JJw % %E #E*****r.c|dd}|D|ddd|d<|D]\}}t||dd}|t|dSdS)NrGr0r typerK)rNr[rKr^rrs r,r^r^sL$//J :t$$$!v%++-- # #KD% E " " " " JJw % %E r.c|dd}|wt|dkrtd|\}}|ddikr||n-|ddikr||ntdd|d<|dd}|)|D]\}}t ||d d}|t |dSdS) NrfrzInvalid input: Type Unions are not supported, except for `Optional` types. Please provide an `Optional` type or a non-Union type.rtnullTnullablerGrK)r[len ValueErrorupdaterNrKr])rVrkabrGrFrcrKs r,r]r]s9 JJw % %E  u::??I 1  MM!     66" " " MM!    I "zL$//J%++-- ' 'KD%  & & & & JJw % %E E"""""r.rVc||S|}|dd}|||d<|dd}|t||d<|dd}|||d<|dd}|t ||d<|dd}|!d|D|d<|S)Nrttype_formatformat_rKrGc4i|]\}}|t|Sr9)_rename_schema_fields)rBrCvs r, z)_rename_schema_fields..'s'[[[1#8#;#;[[[r.)copyr[rNr-rrK)rVr~rrKrGs r,rrs ~ [[]]F JJvt $ $E w JJw % %E !%..wjj4((G#y JJw % %E /66wL$//J[[ HXHXHZHZ[[[| Mr.ceZdZddddZedd Zedd Zedd ZeddZ ddZ e dddZ dS)FunctionDeclarationNrHrFr)r7rHdict[str, Any] | NonecXtj||t||_dS)zmA class wrapping a `protos.FunctionDeclaration`, describes a function for `genai.GenerativeModel`'s `tools`.rFr7rHN)r rr_proto)selfrFr7rHs r,__init__zFunctionDeclaration.__init__-s00;;PQ[;\;\    r.r$c|jjSr')rrFrs r,rFzFunctionDeclaration.name3s {r.c|jjSr')rr7rs r,r7zFunctionDeclaration.description7s {&&r. protos.Schemac|jjSr')rrHrs r,rHzFunctionDeclaration.parameters;s {%%r.c0|ddi}||_|S)Nrr)clsprotors r, from_protozFunctionDeclaration.from_proto?s$sr:::  r.protos.FunctionDeclarationc|jSr'rrs r,to_protozFunctionDeclaration.to_protoE {r.functionr2r/dict[str, str] | NonecL|i}t||}tdi|d|iS)aBuilds 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. N)r/rr9)rWCallableFunctionDeclaration)rr/rVs r, from_functionz!FunctionDeclaration.from_functionHs@  L!(FFF*GGVGGhGGGGr.)rFr)r7r)rHr)r$r))r$r)r$r)r$rr')rr2r/r) rQ __module__ __qualname__rpropertyrFr7rH classmethodrr staticmethodrr9r.r,rr,s[_         X '''X'&&&X&[ HHHH\HHHr.r ValueTypec2eZdZdZdddfd ZddZxZS)rzAn extension of `FunctionDeclaration` that can be built from a Python function, and is callable. Note: The Python function must have type annotations. NrrFr)r7rHrrr2c^t|||||_dS)Nr)superrr)rrFr7rHr __class__s r,rz$CallableFunctionDeclaration.__init__hs/ d SSS  r.fcprotos.FunctionCallr$protos.FunctionResponsec|jdi|j}t|tsd|i}t j|j|S)Nresult)rFresponser9)rargsr(rIr FunctionResponserF)rrrs r,__call__z$CallableFunctionDeclaration.__call__ssO))))&$'' ('F&BGfEEEEr.)rFr)r7r)rHrrr2)rrr$r)rQrrrRrr __classcell__)rs@r,rrbsr-1 ! ! ! ! ! ! ! !FFFFFFFFr.r.funFunctionDeclarationType0FunctionDeclaration | protos.FunctionDeclarationcHt|ttjfr|St|trd|vr t di|Stdi|St |rt|Stdt|j d|)Nrz_Invalid argument type: Expected an instance of `genai.FunctionDeclarationType`. Received type: .r9) r(rr rIrcallabler TypeErrorrtrQ)rs r,_make_function_declarationrs#+V-GHII   C      .5555 5&---- - # *88=== DnrsvnwnwoA D D D    r.fdrcbt|tjr|S|Sr')r(r rr)rs r, _encode_fdrs*"f011 ;;==r.cHeZdZdZddZeddZdd ZddZdZ dS)Toolz\A wrapper for `protos.Tool`, Contains a collection of related `FunctionDeclaration` objects.function_declarations!Iterable[FunctionDeclarationType]cd|D|_i|_|jD]0}|j}||jvrtd||j|j<1t jd|jD|_dS)Nc,g|]}t|Sr9)r)rBr1s r,rEz!Tool.__init__..s!&d&d&d'A!'D'D&d&d&dr.rc,g|]}t|Sr9)r)rBrs r,rEz!Tool.__init__..s"X"X"Xb:b>>"X"X"Xr.r)_function_declarations_indexrFryr rr)rrrrFs r,rz Tool.__init__s&d&dNc&d&d&d# - & &B7Dt{"" nn$#%DK k"X"XD}|jD]4}|j}||jvrt d|d||j|j<5?dS)Nz2Invalid operation: A `FunctionDeclaration` named 'zI' is already defined. Each `FunctionDeclaration` must have a unique name.) _make_toolslist_toolsrrrFry)rrrrrFs r,rzFunctionLibrary.__init__sE""5kk  K < .s 888D 888r.)rrs r,rzFunctionLibrary.to_protos88DK8888r.N)rrr)rrr$r)rQrrrRrrrrr9r.r,rrsecc < < < <!!!!777799999r.rr ToolsType list[Tool]c"t|trit|tsTd|D}t|dkr3t d|Drt d|Dg}|S|}t |gS)Nc,g|]}t|Sr9)rrBts r,rEz_make_tools.. s...1A...r.rc3FK|]}t|jdkVdS)rN)rxrrs r, z_make_tools..s2!S!S#a&=">">!"C!S!S!S!S!S!Sr.c(g|]}|jdS)rrrs r,rEz_make_tools..s K K K!8!; K K Kr.)r(rrrxallr)rrs r,rr s%""":eW+E+E"..... u::>>c!S!SU!S!S!SSS> K KU K K KLLME 4  !!r.libFunctionLibraryType | NoneFunctionLibrary | NonecX||St|tr|St|S)N)r)r(r)rs r,to_function_libraryrs4 { C ) )* S))))r. mode_autoautomode_anyany mode_nonenoneFunctionCallingModeTypeFunctionCallingModecnt|tr|}t|Sr')r(r)r*_FUNCTION_CALLING_MODEr+s r,to_function_calling_moder ;s,!S GGII !! $$r.c$eZdZUded<ded<dS)FunctionCallingConfigDictrmodez list[str]allowed_function_namesNrr9r.r,r r As*!!!!%%%%%%r.r objFunctionCallingConfigTypeprotos.FunctionCallingConfigct|tjr|St|ttt frdt |i}nwt|tr<|}| d}t ||d<n&tdt|j d|tj|S)NrzaInvalid argument type: Could not convert input to `protos.FunctionCallingConfig`. Received type: r) r(r FunctionCallingConfigrr)intr rIrr[rrtrQ)rrs r,to_function_calling_configrKs#v344   C-sC8 9 9  /445 C    hhjjwwv.t44F  5#Cyy1 5 5 5     ' , ,,r.ceZdZUded<dS)ToolConfigDictrfunction_calling_configNrr9r.r,rr^s666666r.rToolConfigTypeprotos.ToolConfigc"t|tjr|St|tr:|d}t |}||d<tjdi|St dt|jd)NrzVInvalid argument type: Could not convert input to `protos.ToolConfig`. Received type: rr9) r(r ToolConfigrIr[rrrtrQ)rfccs r,to_tool_configres#v())   C    gg/00(--), %& ''3''' 4"3ii0 4 4 4   r.)r"r#r$r%)r1r2r/r3r0r4r$r5)rVr5)rrr$r)rrr$r)rrr$r)rrr$r)rrr$r)r"rr$r)rrr$r)rrr$r)L __future__rcollections.abcrrrr;typingrrr typing_extensionsr rLgoogle.generativeair google.generativeai.typesr r%rr)r#TYPE_UNSPECIFIEDSTRINGNUMBERINTEGERBOOLEANARRAYOBJECTr!rr-rWrPr\r_r`r^r]rrrI StructTypefloatboolrrrrrrrrrrrrrFunctionLibraryTyperrModerAUTOANYNONEr rr r rrrrrrr9r.r,r5s9#""""""7777777777 ''''''''''''''''&&&&&&333333 {CdN# '40't'-'4( '  K ' t{ '4;' dk' K't{'4;' dk' L$,'t|'DL' t|!'" L$,#'$t|DL t|J tz$* TZKt{4; dk9'' @.2%) JJJJJJZ.B    + + +   ###<8/H/H/H/H/H/H/H/Hd#{" # %dJ[0A4G H FFFFF"5FFF0  cN S#X    &%%%%%%%%P99999y999 &+x*A!BD[[  .!9!9!9!9!9!9!9!9H (8$h. /  " " " "OY67****2716$)  $04#'  "16$)  $$ 3S# =>%%%% &&&&& &&& "68TT ----&77777777~v'889       r.