§
     Âiê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 j$        e j$        “d e j$        “de j$        “de j$        “e j%        e j%        “de j%        “de j%        “de j%        “e j&        e j&        “de j&        “de j&        “de j&        “e j'        e j'        “de j'        “de j'        “de j'        “Z(de)d<   dEd „Z*eej+        e,e"ej-        f         ej-        f         fZ.eej/        ee.         e	e"ej-        f         f         Z0dFd$„Z1ee"ej2        ej2        ej3        ej3        f         Z4 G d%„ d&e¦  «        Z5ee4e5ej6        f         Z7dGd(„Z8dHd-„Z9edddddd.œdId=„Z:edddddddd>œdJdC„Z;edddddddd>œdJdD„Z<dS )Ké    )Ú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_STYLESÚxÚAnswerStyleOptionsÚreturnÚAnswerStylec                ón   — t          | t          ¦  «        r|                      ¦   «         } t          |          S ©N)Ú
isinstanceÚstrÚlowerr   )r   s    úd/var/www/html/jarvis.com/web/backend/venv/lib/python3.11/site-packages/google/generativeai/answer.pyÚto_answer_styler)   ?   s,   € Ý�!•SÑÔð Ø�GŠG‰IŒIˆÝ˜!ÔÐó    ÚsourceÚGroundingPassagesOptionsúprotos.GroundingPassagesc                ó°  — t          | t          j        ¦  «        r| S t          | t          ¦  «        s%t	          dt          | ¦  «        j        › d�¦  «        ‚g }t          | t          ¦  «        r|                      ¦   «         } t          | ¦  «        D ]±\  }}t          |t          j
        ¦  «        r|                     |¦  «         Œ5t          |t          ¦  «        r0|\  }}|                     |t          j        |¦  «        dœ¦  «         Œz|                     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&   )r+   r1   ÚnÚdatar/   r0   s         r(   Ú_make_grounding_passagesr>   R   sa  € õ �&�&Ô2Ñ3Ô3ð Øˆå�f�hÑ'Ô'ð 
Ýð \ÕswÐx~ÑsÔsô  tIð  \ð  \ð  \ñ
ô 
ð 	
ð €HÝ�&�'Ñ"Ô"ð  Ø—’‘”ˆå˜VÑ$Ô$ð Wð W‰ˆˆ4Ý�d�FÔ3Ñ4Ô4ð 	WØ�OŠO˜DÑ!Ô!Ð!Ð!Ý˜�eÑ$Ô$ð 	WØ‰KˆB�Ø�OŠO 2µ-Ô2JÈ7Ñ2SÔ2SÐTÐTÑUÔUÐUÐUà�OŠO¥3 q¡6¤6µmÔ6NÈtÑ6TÔ6TÐUÐUÑVÔVÐVÐVåÔ#¨XÐ6Ñ6Ô6Ð6r*   c                  óB   — e Zd ZU ded<   ded<   ded<   ded<   d	ed
<   dS )ÚSemanticRetrieverConfigDictÚSourceNameTyper+   úcontent_types.ContentsTypeÚqueryz"Optional[Iterable[MetadataFilter]]Úmetadata_filterzOptional[int]Úmax_chunks_countzOptional[float]Úminimum_relevance_scoreN)r5   Ú
__module__Ú__qualname__Ú__annotations__© r*   r(   r@   r@   z   sN   € € € € € € ØÐÐÑØ%Ð%Ð%Ñ%Ø7Ð7Ð7Ñ7Ø#Ð#Ð#Ñ#Ø,Ð,Ð,Ñ,Ð,Ð,r*   r@   ú
str | Nonec                óº   — t          | t          ¦  «        r| S t          | t          j        t          j        t          j        t          j        f¦  «        r| j        S d S r$   )r%   r&   r   ÚCorpusr
   ÚDocumentÚname)r+   s    r(   Ú_maybe_get_source_namerP   ‰   sT   € Ý�&�#ÑÔð ØˆÝ	Ø•Ô'­¬½Ô8PÕRXÔRaÐbñ
ô 
ð ð Œ{Ðàˆtr*   ÚSemanticRetrieverConfigOptionsrC   rB   úprotos.SemanticRetrieverConfigc                óÄ  — t          | t          j        ¦  «        r| S t          | ¦  «        }|�d|i} nUt          | t          ¦  «        rt          | d         ¦  «        | d<   n't          dt          | ¦  «        j        › d| › �¦  «        ‚| d         €|| d<   n8t          | d         t          ¦  «        rt          j
        | d         ¦  «        | d<   t          j        | ¦  «        S )Nr+   zlInvalid input: Failed to create a 'protos.SemanticRetrieverConfig' from the provided source. Received type: z, Received value: rC   )r%   r
   ÚSemanticRetrieverConfigrP   Údictr3   r4   r5   r&   r   r;   )r+   rC   rO   s      r(   Ú_make_semantic_retriever_configrV   ”   sú   € õ �&�&Ô8Ñ9Ô9ð Øˆå! &Ñ)Ô)€DØÐØ˜DÐ!ˆˆÝ	�F�DÑ	!Ô	!ð 
Ý1°&¸Ô2BÑCÔCˆˆxÑÐåð(Ý" 6™lœlÔ3ð(ð (à%ð(ð (ñ
ô 
ð 	
ð ˆg„ÐØˆˆw‰ˆÝ	�F˜7”O¥SÑ	)Ô	)ð DÝ'Ô2°6¸'´?ÑCÔCˆˆw‰åÔ)¨&Ñ1Ô1Ð1r*   )ÚmodelÚinline_passagesÚsemantic_retrieverÚanswer_styleÚsafety_settingsÚtemperaturerW   úmodel_types.AnyModelNameOptionsÚcontentsrX   úGroundingPassagesOptions | NonerY   ú%SemanticRetrieverConfigOptions | NonerZ   úAnswerStyle | Noner[   ú(safety_types.SafetySettingOptions | Noner\   úfloat | Noneúprotos.GenerateAnswerRequestc           	     óŒ  — 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().
    Nz‡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: ©rW   r^   rX   rY   r[   r\   rZ   )r   Úmake_model_namer   Úto_contentsr   Únormalize_safety_settingsÚ
ValueErrorr>   rV   r3   r)   r
   ÚGenerateAnswerRequest)rW   r^   rX   rY   rZ   r[   r\   s          r(   Ú_make_generate_answer_requestrn   ¯   s?  € õ< Ô'¨Ñ.Ô.€EåÔ(¨Ñ2Ô2€Hàð RÝ&Ô@ÀÑQÔQˆàÐ"Ð'9Ð'EÝðrØ-<ðrð rØ\nðrð rð rñ
ô 
ð 	
ð 
Ð	$Ý2°?ÑCÔCˆˆØ	Ð	'Ý<Ð=OÐQYÐZ\ÔQ]Ñ^Ô^ÐÐåðrØ-<ðrð rØ\nðrð rð rñ
ô 
ð 	
ð
 ð 5Ý& |Ñ4Ô4ˆåÔ'ØØØ'Ø-Ø'ØØ!ðñ ô ð r*   )rW   rX   rY   rZ   r[   r\   ÚclientÚrequest_optionsro   ú"glm.GenerativeServiceClient | Nonerp   ú&helper_types.RequestOptionsType | Nonec        	   	     óv   — |€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.
    Nrh   )r   rn   Úgenerate_answer©rW   r^   rX   rY   rZ   r[   r\   ro   rp   ÚrequestÚresponses              r(   rt   rt   ñ   sj   € ðf ÐØˆà€~Ý.Ñ0Ô0ˆå+ØØØ'Ø-Ø'ØØ!ðñ ô €Gð &ˆvÔ% gÐAÐA°ÐAÐA€Hà€Or*   c        	   	   ƒ  ó†   K  — |€i }|€t          ¦   «         }t          | ||||||¬¦  «        }	 |j        |	fi |¤Žƒ d{V —†}
|
S )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.
    Nrh   )r   rn   rt   ru   s              r(   Úgenerate_answer_asyncry   9  s€   è è € ð@ ÐØˆà€~Ý4Ñ6Ô6ˆå+ØØØ'Ø-Ø'ØØ!ðñ ô €Gð ,�VÔ+¨GÐGÐG°ÐGÐGÐGÐGÐGÐGÐGÐG€Hà€Or*   )r   r    r!   r"   )r+   r,   r!   r-   )r!   rK   )r+   rQ   rC   rB   r!   rR   )rW   r]   r^   rB   rX   r_   rY   r`   rZ   ra   r[   rb   r\   rc   r!   rd   )rW   r]   r^   rB   rX   r_   rY   r`   rZ   ra   r[   rb   r\   rc   ro   rq   rp   rr   )=Ú
__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_MODELrm   r"   Úintr&   r    ÚANSWER_STYLE_UNSPECIFIEDÚABSTRACTIVEÚ
EXTRACTIVEÚVERBOSEr   rI   r)   r8   r:   ÚContentTypeÚGroundingPassageOptionsr2   r,   r>   rM   rN   rA   r@   rT   rQ   rP   rV   rn   rt   ry   rJ   r*   r(   ú<module>r�      sO  ðð #Ð "Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ø $Ð $Ð $Ð $Ð $Ð $Ø Ð Ð Ð Ø :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ø 'Ð 'Ð 'Ð 'Ð 'Ð 'à *Ð *Ð *Ð *Ð *Ð *Ð *Ð *Ð *Ø &Ð &Ð &Ð &Ð &Ð &ðð ð ð ð ð ð ð ð 2Ð 1Ð 1Ð 1Ð 1Ð 1Ø 2Ð 2Ð 2Ð 2Ð 2Ð 2Ø 2Ð 2Ð 2Ð 2Ð 2Ð 2Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3Ø 5Ð 5Ð 5Ð 5Ð 5Ð 5Ø DÐ DÐ DÐ DÐ DÐ Dà#Ð àÔ*Ô6€à˜3  [Ð0Ô1Ð ð9ØÔ(¨+Ô*Nð9à€{Ô+ð9ð  Ô Dð9ð �;Ô7ð	9ð
 Ô˜[Ô4ð9ð €{Ôð9ð  Ô 7ð9ð �;Ô*ð9ð Ô˜KÔ2ð9ð €{Ôð9ð ˜{Ô5ð9ð �+Ô(ð9ð Ô˜Ô,ð9ð €{Ôð9ð ˜KÔ/ð9ð  ˆ{Ô"ð!9€ð ð ð ñ ð(ð ð ð ð 
ØÔ  s¨MÔ,EÐ'EÔ!FÈÔHaÐaôðÐ ð !Ø
ÔØÐ$Ô%ØˆC�Ô*Ð*Ô+ð-ôÐ ð 7ð  7ð  7ð  7ðF ØˆÔ	 ¤°Ô0HÈ&Ì/ÐYô€ð
-ð -ð -ð -ð - )ñ -ô -ð -ð "'ØØØ
Ô"ð$ô"Ð ðð ð ð ð2ð 2ð 2ð 2ð: .Bà7;Ø@DØ'+Ø@DØ $ð?ð ?ð ?ð ?ð ?ð ?ðH .Bà7;Ø@DØ'+Ø@DØ $Ø15Ø>BðEð Eð Eð Eð Eð EðT .Bà7;Ø@DØ'+Ø@DØ $Ø15Ø>Bð2ð 2ð 2ð 2ð 2ð 2ð 2ð 2r*   