
    
!i6              	      :   % S SK Jr  S SKrS SKJr  S SKrS SKJrJrJrJ	r	J
r
  S SKJr  S SKJs  Jr  S SKJr  S SKJrJr  S SKJr  S S	KJr  S S
KJr  S SKJr  S SKJr  S SKJr  Sr\R>                  R@                  r \\!\"\ 4   r#0 \ RH                  \ RH                  _S \ RH                  _S\ RH                  _S\ RH                  _\ RJ                  \ RJ                  _S\ RJ                  _S\ RJ                  _S\ RJ                  _\ RL                  \ RL                  _S\ RL                  _S\ RL                  _S\ RL                  _\ RN                  \ RN                  _S\ RN                  _S\ RN                  _S\ RN                  _r(S\)S'   S'S jr*\\RV                  \,\"\RZ                  4   \RZ                  4   4r.\\R^                  \\.   \	\"\RZ                  4   4   r0S(S jr1\\"\Rd                  \Rd                  \Rf                  \Rf                  4   r4 " S S\5      r5\\4\5\Rl                  4   r7S)S  jr8      S*S! jr9\SSSSSS".               S+S# jjr:\SSSSSSSS$.                 S,S% jjr;\SSSSSSSS$.                 S,S& jjr<g)-    )annotationsN)Iterable)Anyr   UnionMappingOptional)	TypedDict)protos)get_default_generative_client#get_default_generative_async_client)model_types)helper_types)safety_types)content_types)retriever_types)MetadataFilterz
models/aqaanswer_style_unspecifiedunspecified   answer_style_abstractiveabstractive   answer_style_extractive
extractive   answer_style_verboseverbosez%dict[AnswerStyleOptions, AnswerStyle]_ANSWER_STYLESc                ^    [        U [        5      (       a  U R                  5       n [        U    $ N)
isinstancestrlowerr   )xs    T/home/james-whalen/.local/lib/python3.13/site-packages/google/generativeai/answer.pyto_answer_styler&   ?   s%    !SGGI!    c                   [        U [        R                  5      (       a  U $ [        U [        5      (       d"  [	        S[        U 5      R                   S35      e/ n[        U [        5      (       a  U R                  5       n [        U 5       H  u  p#[        U[        R                  5      (       a  UR                  U5        M7  [        U[        5      (       a.  Uu  pEUR                  U[        R                  " U5      S.5        Mz  UR                  [        U5      [        R                  " U5      S.5        M     [        R                  " US9$ )a  
Converts the `source` into a `protos.GroundingPassage`. A `GroundingPassages` contains a list of
`protos.GroundingPassage` objects, which each contain a `protos.Content` and a string `id`.

Args:
    source: `Content` or a `GroundingPassagesOptions` that will be converted to protos.GroundingPassages.

Return:
    `protos.GroundingPassages` to be passed into `protos.GenerateAnswer`.
zdInvalid input: The 'source' argument must be an instance of 'GroundingPassagesOptions'. Received a 'z' object instead.)idcontent)passages)r!   r
   GroundingPassagesr   	TypeErrortype__name__r   items	enumerateGroundingPassageappendtupler   
to_contentr"   )sourcer+   ndatar)   r*   s         r%   _make_grounding_passagesr9   R   s    &&2233fh''rswx~s  tI  tI  sJ  J[  \
 	
 H&'""V$dF3344OOD!e$$KBOO2-2J2J72STUOO3q6m6N6Nt6TUV % ##X66r'   c                  H    \ rS rSr% S\S'   S\S'   S\S'   S\S	'   S
\S'   Srg)SemanticRetrieverConfigDictz   SourceNameTyper6   content_types.ContentsTypequeryz"Optional[Iterable[MetadataFilter]]metadata_filterzOptional[int]max_chunks_countzOptional[float]minimum_relevance_score N)r/   
__module____qualname____firstlineno____annotations____static_attributes__rC   r'   r%   r;   r;   z   s     %%77##,,r'   r;   c                    [        U [        5      (       a  U $ [        U [        R                  [        R                  [        R
                  [        R
                  45      (       a  U R                  $ g r    )r!   r"   r   Corpusr
   Documentname)r6   s    r%   _maybe_get_source_namerM      sU    &#	''8P8PRXRaRab
 
 {{r'   c                   [        U [        R                  5      (       a  U $ [        U 5      nUb  SU0n OK[        U [        5      (       a  [        U S   5      U S'   O$[        S[        U 5      R                   SU  35      eU S   c  XS'   O4[        U S   [        5      (       a  [        R                  " U S   5      U S'   [        R                  " U 5      $ )Nr6   zlInvalid input: Failed to create a 'protos.SemanticRetrieverConfig' from the provided source. Received type: z, Received value: r?   )r!   r
   SemanticRetrieverConfigrM   dictr-   r.   r/   r"   r   r5   )r6   r?   rL   s      r%   _make_semantic_retriever_configrQ      s     &&8899!&)DD!	FD	!	!1&2BCx"6l334 5%h(
 	
 gw	F7OS	)	)'226'?Cw))&11r'   )modelinline_passagessemantic_retrieveranswer_stylesafety_settingstemperaturec           
        [         R                  " U 5      n [        R                  " U5      nU(       a  [        R
                  " U5      nUb  Ub  [        SU SU S35      eUb  [        U5      nO$Ub  [        X1S   5      nO[        SU SU S35      eU(       a  [        U5      n[        R                  " U UUUUUUS9$ )a  
constructs a protos.GenerateAnswerRequest object by organizing the input parameters for the API call to generate a grounded answer from the model.

Args:
    model: Name of the model used to generate the grounded response.
    contents: Content of the current conversation with the model. For single-turn query, this is a
        single question to answer. For multi-turn queries, this is a repeated field that contains
        conversation history and the last `Content` in the list containing the question.
    inline_passages: Grounding passages (a list of `Content`-like objects or `(id, content)` pairs,
        or a `protos.GroundingPassages`) to send inline with the request. Exclusive with `semantic_retriever`,
        one must be set, but not both.
    semantic_retriever: A Corpus, Document, or `protos.SemanticRetrieverConfig` to use for grounding. Exclusive with
         `inline_passages`, one must be set, but not both.
    answer_style: Style for grounded answers.
    safety_settings: Safety settings for generated output.
    temperature: The temperature for randomness in the output.

Returns:
    Call for protos.GenerateAnswerRequest().
zInvalid configuration: Please set either 'inline_passages' or 'semantic_retriever_config', but not both. Received for inline_passages: z, and for semantic_retriever: .zInvalid configuration: Either 'inline_passages' or 'semantic_retriever_config' must be provided, but currently both are 'None'. Received for inline_passages: rR   contentsrS   rT   rV   rW   rU   )r   make_model_namer   to_contentsr   normalize_safety_settings
ValueErrorr9   rQ   r-   r&   r
   GenerateAnswerRequest)rR   r\   rS   rT   rU   rV   rW   s          r%   _make_generate_answer_requestrb      s    < ''.E((2H&@@Q"'9'E--<,==[\n[oopr
 	
 
	$2?C		'<=OZ\Q]^--<,==[\n[oopr
 	

 &|4'''-'! r'   )rR   rS   rT   rU   rV   rW   clientrequest_optionsc        	   
     n    Uc  0 nUc
  [        5       n[        U UUUUUUS9n	UR                  " U	40 UD6n
U
$ )aC  Calls the GenerateAnswer API and returns a `types.Answer` containing the response.

You can pass a literal list of text chunks:

>>> from google.generativeai import answer
>>> answer.generate_answer(
...     content=question,
...     inline_passages=splitter.split(document)
... )

Or pass a reference to a retreiver Document or Corpus:

>>> from google.generativeai import answer
>>> from google.generativeai import retriever
>>> my_corpus = retriever.get_corpus('my_corpus')
>>> genai.generate_answer(
...     content=question,
...     semantic_retriever=my_corpus
... )


Args:
    model: Which model to call, as a string or a `types.Model`.
    contents: The question to be answered by the model, grounded in the
            provided source.
    inline_passages: Grounding passages (a list of `Content`-like objects or (id, content) pairs,
        or a `protos.GroundingPassages`) to send inline with the request. Exclusive with `semantic_retriever`,
        one must be set, but not both.
    semantic_retriever: A Corpus, Document, or `protos.SemanticRetrieverConfig` to use for grounding. Exclusive with
         `inline_passages`, one must be set, but not both.
    answer_style: Style in which the grounded answer should be returned.
    safety_settings: Safety settings for generated output. Defaults to None.
    temperature: Controls the randomness of the output.
    client: If you're not relying on a default client, you pass a `glm.GenerativeServiceClient` instead.
    request_options: Options for the request.

Returns:
    A `types.Answer` containing the model's text answer response.
r[   )r   rb   generate_answerrR   r\   rS   rT   rU   rV   rW   rc   rd   requestresponses              r%   rf   rf      sX    f ~.0+'-'!G %%gAAHOr'   c        	   
        #    Uc  0 nUc
  [        5       n[        U UUUUUUS9n	UR                  " U	40 UD6I Sh  vN n
U
$  N7f)a  
Calls the API and returns a `types.Answer` containing the answer.

Args:
    model: Which model to call, as a string or a `types.Model`.
    contents: The question to be answered by the model, grounded in the
            provided source.
    inline_passages: Grounding passages (a list of `Content`-like objects or (id, content) pairs,
        or a `protos.GroundingPassages`) to send inline with the request. Exclusive with `semantic_retriever`,
        one must be set, but not both.
    semantic_retriever: A Corpus, Document, or `protos.SemanticRetrieverConfig` to use for grounding. Exclusive with
         `inline_passages`, one must be set, but not both.
    answer_style: Style in which the grounded answer should be returned.
    safety_settings: Safety settings for generated output. Defaults to None.
    temperature: Controls the randomness of the output.
    client: If you're not relying on a default client, you pass a `glm.GenerativeServiceClient` instead.

Returns:
    A `types.Answer` containing the model's text answer response.
Nr[   )r   rb   rf   rg   s              r%   generate_answer_asyncrk   9  sd     @ ~46+'-'!G ++GGGGHO Hs   8AAA)r$   AnswerStyleOptionsreturnAnswerStyle)r6   GroundingPassagesOptionsrm   zprotos.GroundingPassages)rm   z
str | None)r6   SemanticRetrieverConfigOptionsr?   r>   rm   zprotos.SemanticRetrieverConfig)rR   model_types.AnyModelNameOptionsr\   r>   rS   GroundingPassagesOptions | NonerT   %SemanticRetrieverConfigOptions | NonerU   AnswerStyle | NonerV   (safety_types.SafetySettingOptions | NonerW   float | Nonerm   zprotos.GenerateAnswerRequest)rR   rq   r\   r>   rS   rr   rT   rs   rU   rt   rV   ru   rW   rv   rc   z"glm.GenerativeServiceClient | Nonerd   z&helper_types.RequestOptionsType | None)=
__future__r   dataclassescollections.abcr   	itertoolstypingr   r   r   r   typing_extensionsr	   google.ai.generativelanguageaigenerativelanguageglmgoogle.generativeair
   google.generativeai.clientr   r   google.generativeai.typesr   r   r   r   r   )google.generativeai.types.retriever_typesr   DEFAULT_ANSWER_MODELra   rn   intr"   rl   ANSWER_STYLE_UNSPECIFIEDABSTRACTIVE
EXTRACTIVEVERBOSEr   rG   r&   r2   r4   ContentTypeGroundingPassageOptionsr,   ro   r9   rJ   rK   r=   r;   rO   rp   rM   rQ   rb   rf   rk   rC   r'   r%   <module>r      s   #  $  : : ' * * & 2 2 2 3 5 D# **663[01 9((+*N*N9{++9  D D9 ;77	9
 [449 {9  7 79 ;**9 K229 {9 {559 +((9 ,,9 {9 K//9  {""!95 ( 
sM,E,E'E!FHaHaa  !
$%C***+-  7F 		0H0H&//Y
-) - "'
""$" 2*2%2 $2: .B7;@D'+@D $?*? )? 5	?
 >? %? >? ? "?H .B7;@D'+@D $15>BE*E )E 5	E
 >E %E >E E /E <ET .B7;@D'+@D $15>B2*2 )2 5	2
 >2 %2 >2 2 /2 <2r'   