Ë
    ümxiê6  ã            	      ó&  — U d dl mZ d dlZd dlmZ d dlZd dlmZmZmZm	Z	m
Z
 d dlmZ d dlmc mZ d dlmZ d dl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 d dlmZ dZej>                  j@                  Z ee!e"e f   Z#i e jH                  e jH                  “d e jH                  “de jH                  “de jH                  “e jJ                  e jJ                  “de jJ                  “de jJ                  “de jJ                  “e jL                  e jL                  “de jL                  “de jL                  “de jL                  “e jN                  e jN                  “de jN                  “de jN                  “de jN                  “Z(de)d<   d'd„Z*eejV                  e,e"ejZ                  f   ejZ                  f   fZ.eej^                  ee.   e	e"ejZ                  f   f   Z0d(d„Z1ee"ejd                  ejd                  ejf                  ejf                  f   Z4 G d„ de«      Z5ee4e5ejl                  f   Z7d)d „Z8	 	 	 	 	 	 d*d!„Z9edddddd"œ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d+d#„Z:edddddddd$œ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d,d%„Z;edddddddd$œ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d,d&„Z<y)-é    )Ú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                óT   — t        | t        «      r| j                  «       } t        |    S ©N)Ú
isinstanceÚstrÚlowerr   )Úxs    úQ/home/htdocs/ttos/venv/lib/python3.12/site-packages/google/generativeai/answer.pyÚto_answer_styler&   ?   s"   € Ü�!”SÔØ�G‰G‹IˆÜ˜!ÑÐó    c                óf  — t        | t        j                  «      r| S t        | t        «      s"t	        dt        | «      j                  › d�«      ‚g }t        | t        «      r| j                  «       } t        | «      D ]ž  \  }}t        |t        j                  «      r|j                  |«       Œ2t        |t        «      r-|\  }}|j                  |t        j                  |«      dœ«       Œo|j                  t        |«      t        j                  |«      dœ«       Œ  t        j                  |¬«      S )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Øˆä�fœhÔ'ÜØrÔswÐx~Ós÷  tIñ  tIð  sJð  J[ð  \ó
ð 	
ð €HÜ�&œ'Ô"Ø—‘“ˆä˜VÓ$ò W‰ˆˆ4Ü�dœF×3Ñ3Ô4Ø�O‰O˜DÕ!Ü˜œeÔ$Ø‰KˆB�Ø�O‰O 2´-×2JÑ2JÈ7Ó2SÑTÕUà�O‰O¤3 q£6´m×6NÑ6NÈtÓ6TÑUÕVðWô ×#Ñ#¨XÔ6Ð6r'   c                  ó@   — e Zd ZU ded<   ded<   ded<   ded<   d	ed
<   y)ÚSemanticRetrieverConfigDictÚSourceNameTyper6   úcontent_types.ContentsTypeÚqueryz"Optional[Iterable[MetadataFilter]]Úmetadata_filterzOptional[int]Úmax_chunks_countzOptional[float]Úminimum_relevance_scoreN)r/   Ú
__module__Ú__qualname__Ú__annotations__© r'   r%   r;   r;   z   s    … ØÓØ%Ó%Ø7Ó7Ø#Ó#Ø,Ô,r'   r;   c                óÐ   — t        | t        «      r| S t        | t        j                  t        j                  t        j
                  t        j
                  f«      r| j                  S y r    )r!   r"   r   ÚCorpusr
   ÚDocumentÚname)r6   s    r%   Ú_maybe_get_source_namerJ   ‰   sM   € Ü�&œ#ÔØˆÜ	Ø”×'Ñ'¬¯©¼×8PÑ8PÔRX×RaÑRaÐbô
ð �{‰{Ðàr'   c                ó†  — t        | t        j                  «      r| S t        | «      }|�d|i} nFt        | t        «      rt        | d   «      | d<   n$t        dt        | «      j                  › d| › �«      ‚| d   €|| d<   n.t        | d   t        «      rt        j                  | d   «      | d<   t        j                  | «      S )Nr6   zlInvalid input: Failed to create a 'protos.SemanticRetrieverConfig' from the provided source. Received type: z, Received value: r>   )r!   r
   ÚSemanticRetrieverConfigrJ   Údictr-   r.   r/   r"   r   r5   )r6   r>   rI   s      r%   Ú_make_semantic_retriever_configrN   ”   sÎ   € ô �&œ&×8Ñ8Ô9Øˆä! &Ó)€DØÐØ˜DÐ!‰Ü	�FœDÔ	!Ü1°&¸Ñ2BÓCˆˆxÒäðÜ" 6›l×3Ñ3Ð4ð 5Ø%˜hð(ó
ð 	
ð ˆg�ÐØˆˆwŠÜ	�F˜7‘O¤SÔ	)Ü'×2Ñ2°6¸'±?ÓCˆˆw‰ä×)Ñ)¨&Ó1Ð1r'   )ÚmodelÚinline_passagesÚsemantic_retrieverÚanswer_styleÚsafety_settingsÚtemperaturec           	     óf  — t        j                  | «      } t        j                  |«      }|rt	        j
                  |«      }|�|�t        d|› d|› d�«      ‚|�t        |«      }n$|�t        ||d   «      }nt        d|› d|› d�«      ‚|rt        |«      }t        j                  | ||||||¬«      S )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().
    z‡Invalid configuration: Please set either 'inline_passages' or 'semantic_retriever_config', but not both. Received for inline_passages: z, and for semantic_retriever: ú.éÿÿÿÿzžInvalid configuration: Either 'inline_passages' or 'semantic_retriever_config' must be provided, but currently both are 'None'. Received for inline_passages: ©rO   ÚcontentsrP   rQ   rS   rT   rR   )r   Úmake_model_namer   Úto_contentsr   Únormalize_safety_settingsÚ
ValueErrorr9   rN   r-   r&   r
   ÚGenerateAnswerRequest)rO   rY   rP   rQ   rR   rS   rT   s          r%   Ú_make_generate_answer_requestr_   ¯   sû   € ô< ×'Ñ'¨Ó.€Eä×(Ñ(¨Ó2€HáÜ&×@Ñ@ÀÓQˆàÐ"Ð'9Ð'EÜð-Ø-<Ð,=Ð=[Ð\nÐ[oÐopðró
ð 	
ð 
Ð	$Ü2°?ÓC‰Ø	Ð	'Ü<Ð=OÐQYÐZ\ÑQ]Ó^Ñäð-Ø-<Ð,=Ð=[Ð\nÐ[oÐopðró
ð 	
ñ
 Ü& |Ó4ˆä×'Ñ'ØØØ'Ø-Ø'ØØ!ôð r'   )rO   rP   rQ   rR   rS   rT   ÚclientÚrequest_optionsc        	   	     óp   — |€i }|€
t        «       }t        | ||||||¬«      }	 |j                  |	fi |¤Ž}
|
S )a¿  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.
    rX   )r   r_   Úgenerate_answer©rO   rY   rP   rQ   rR   rS   rT   r`   ra   ÚrequestÚresponses              r%   rc   rc   ñ   sZ   € ðf ÐØˆà€~Ü.Ó0ˆä+ØØØ'Ø-Ø'ØØ!ô€Gð &ˆv×%Ñ% gÑA°ÑA€Hà€Or'   c        	   	   ƒ  óŒ   K  — |€i }|€
t        «       }t        | ||||||¬«      }	 |j                  |	fi |¤Žƒ d{  –—† }
|
S 7 Œ­w)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.
    NrX   )r   r_   rc   rd   s              r%   Úgenerate_answer_asyncrh   9  sg   è ø€ ð@ ÐØˆà€~Ü4Ó6ˆä+ØØØ'Ø-Ø'ØØ!ô€Gð ,�V×+Ñ+¨GÑG°ÑG×G€Hà€Oð Hús   ‚9A»A¼A)r$   ÚAnswerStyleOptionsÚreturnÚAnswerStyle)r6   ÚGroundingPassagesOptionsrj   zprotos.GroundingPassages)rj   z
str | None)r6   ÚSemanticRetrieverConfigOptionsr>   r=   rj   zprotos.SemanticRetrieverConfig)rO   úmodel_types.AnyModelNameOptionsrY   r=   rP   úGroundingPassagesOptions | NonerQ   ú%SemanticRetrieverConfigOptions | NonerR   úAnswerStyle | NonerS   ú(safety_types.SafetySettingOptions | NonerT   úfloat | Nonerj   zprotos.GenerateAnswerRequest)rO   rn   rY   r=   rP   ro   rQ   rp   rR   rq   rS   rr   rT   rs   r`   z"glm.GenerativeServiceClient | Nonera   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_MODELr^   rk   Úintr"   ri   ÚANSWER_STYLE_UNSPECIFIEDÚABSTRACTIVEÚ
EXTRACTIVEÚVERBOSEr   rD   r&   r2   r4   ÚContentTypeÚGroundingPassageOptionsr,   rl   r9   rG   rH   r<   r;   rL   rm   rJ   rN   r_   rc   rh   rE   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ó ó(ð 
Ø×Ñ  s¨M×,EÑ,EÐ'EÑ!FÈ×HaÑHaÐañðÐ ð !Ø
×ÑØÐ$Ñ%ØˆC�×*Ñ*Ð*Ñ+ð-ñÐ ó 7ðF Øˆ×	Ñ	 §¡°×0HÑ0HÈ&Ï/É/Ð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'   