§
    é˜ºh90  ã            
      óü  — d dl mZ d dlZd dlmZmZ d dlZd dlmZmZm	Z	 d dl
mc 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dZ	 ej        Zn# e$ r  e	d¦  «        ZdCd„ZY nw xY wdDd„Zedddddddddœ	dEd)„Zeddddddddd*œ	dFd/„Zej          ej!        d0¬1¦  «         G d2„ d3ej"        ¦  «        ¦   «         ¦   «         Z"	 dGdHd6„Z#	 dGdId8„Z$e	 dGdJd<„¦   «         Z%e	 dGdKd?„¦   «         Z%	 dGdLdB„Z%dS )Mé    )ÚannotationsN)ÚIterableÚSequence)r   ÚoverloadÚTypeVar)Úget_default_text_client)Ústring_utils)Ú
text_types)Úmodel_types)Úmodels)Úsafety_typeszmodels/text-bison-001éd   ÚTÚiterableúIterable[T]ÚnÚintÚreturnúIterable[list[T]]c              #  ó´   K  — |dk     rt          d|› �¦  «        ‚g }| D ]0}|                     |¦  «         t          |¦  «        |k    r|V — g }Œ1|r|V — d S d S )Né   z Batch size `n` must be >1, got: )Ú
ValueErrorÚappendÚlen)r   r   ÚbatchÚitems       ú`/var/www/html/services/rag-service/venv/lib/python3.11/site-packages/google/generativeai/text.pyÚ_batchedr   (   s‰   è è € ØˆqŠ5ˆ5ÝÐCÀÐCÐCÑDÔDÐDØˆØð 	ð 	ˆDØ�LŠL˜ÑÔÐÝ�5‰zŒz˜QŠˆØ���Ø�øàð 	ØˆKˆKˆKˆKˆKð	ð 	ó    Úpromptústr | dict[str, str]úglm.TextPromptc                óÊ   — t          | t          ¦  «        rt          j        | ¬¦  «        S t          | t          ¦  «        rt          j        | ¦  «        S t          d¦  «         dS )aP  
    Creates a `glm.TextPrompt` object based on the provided prompt input.

    Args:
        prompt: The prompt input, either a string or a dictionary.

    Returns:
        glm.TextPrompt: A TextPrompt object containing the prompt text.

    Raises:
        TypeError: If the provided prompt is neither a string nor a dictionary.
    )Útextz.Expected string or dictionary for text prompt.N)Ú
isinstanceÚstrÚglmÚ
TextPromptÚdictÚ	TypeError©r    s    r   Ú_make_text_promptr,   6   sb   € õ �&�#ÑÔð DÝŒ~ 6Ð*Ñ*Ô*Ð*Ý	�F�DÑ	!Ô	!ð DÝŒ~˜fÑ%Ô%Ð%åÐBÑCÔCÐCÐCÐCr   ©	Úmodelr    ÚtemperatureÚcandidate_countÚmax_output_tokensÚtop_pÚtop_kÚsafety_settingsÚstop_sequencesr.   úmodel_types.AnyModelNameOptionsú
str | Noner/   úfloat | Noner0   ú
int | Noner1   r2   r3   r4   ú(safety_types.SafetySettingOptions | Noner5   ústr | Iterable[str] | Noneúglm.GenerateTextRequestc        	        ó  — t          j        | ¦  «        } t          |¬¦  «        }t          j        |d¬¦  «        }t          |t          ¦  «        r|g}|rt          |¦  «        }t          j	        | ||||||||¬¦	  «	        S )a‡  
    Creates a `glm.GenerateTextRequest` object based on the provided parameters.

    This function generates a `glm.GenerateTextRequest` object with the specified
    parameters. It prepares the input parameters and creates a request that can be
    used for generating text using the chosen model.

    Args:
        model: The model to use for text generation.
        prompt: The prompt for text generation. Defaults to None.
        temperature: The temperature for randomness in generation. Defaults to None.
        candidate_count: The number of candidates to consider. Defaults to None.
        max_output_tokens: The maximum number of output tokens. Defaults to None.
        top_p: The nucleus sampling probability threshold. Defaults to None.
        top_k: The top-k sampling parameter. Defaults to None.
        safety_settings: Safety settings for generated text. Defaults to None.
        stop_sequences: Stop sequences to halt text generation. Can be a string
             or iterable of strings. Defaults to None.

    Returns:
        `glm.GenerateTextRequest`: A `GenerateTextRequest` object configured with the specified parameters.
    r+   Úold)Úharm_category_setr-   )
r   Úmake_model_namer,   r   Únormalize_safety_settingsr%   r&   Úlistr'   ÚGenerateTextRequestr-   s	            r   Ú_make_generate_text_requestrD   K   s§   € õD Ô'¨Ñ.Ô.€EÝ fÐ-Ñ-Ô-€FÝ"Ô<Ø¨5ðñ ô €Oõ �.¥#Ñ&Ô&ð *Ø(Ð)ˆØð .Ý˜nÑ-Ô-ˆåÔ"ØØØØ'Ø+ØØØ'Ø%ð
ñ 
ô 
ð 
r   )	r.   r/   r0   r1   r2   r3   r4   r5   Úclientr&   rE   úglm.TextServiceClient | Noneútext_types.Completionc        
        óT   — t          | ||||||||¬¦	  «	        }
t          |	|
¬¦  «        S )aH  Calls the API and returns a `types.Completion` containing the response.

    Args:
        model: Which model to call, as a string or a `types.Model`.
        prompt: Free-form input text given to the model. Given a prompt, the model will
                generate text that completes the input text.
        temperature: Controls the randomness of the output. Must be positive.
            Typical values are in the range: `[0.0,1.0]`. Higher values produce a
            more random and varied response. A temperature of zero will be deterministic.
        candidate_count: The **maximum** number of generated response messages to return.
            This value must be between `[1, 8]`, inclusive. If unset, this
            will default to `1`.

            Note: Only unique candidates are returned. Higher temperatures are more
            likely to produce unique candidates. Setting `temperature=0.0` will always
            return 1 candidate regardless of the `candidate_count`.
        max_output_tokens: Maximum number of tokens to include in a candidate. Must be greater
                           than zero. If unset, will default to 64.
        top_k: The API uses combined [nucleus](https://arxiv.org/abs/1904.09751) and top-k sampling.
            `top_k` sets the maximum number of tokens to sample from on each step.
        top_p: The API uses combined [nucleus](https://arxiv.org/abs/1904.09751) and top-k sampling.
            `top_p` configures the nucleus sampling. It sets the maximum cumulative
            probability of tokens to sample from.
            For example, if the sorted probabilities are
            `[0.5, 0.2, 0.1, 0.1, 0.05, 0.05]` a `top_p` of `0.8` will sample
            as `[0.625, 0.25, 0.125, 0, 0, 0]`.
        safety_settings: A list of unique `types.SafetySetting` instances for blocking unsafe content.
           These will be enforced on the `prompt` and
           `candidates`. There should not be more than one
           setting for each `types.SafetyCategory` type. The API will block any prompts and
           responses that fail to meet the thresholds set by these settings. This list
           overrides the default settings for each `SafetyCategory` specified in the
           safety_settings. If there is no `types.SafetySetting` for a given
           `SafetyCategory` provided in the list, the API will use the default safety
           setting for that category.
        stop_sequences: A set of up to 5 character sequences that will stop output generation.
          If specified, the API will stop at the first appearance of a stop
          sequence. The stop sequence will not be included as part of the response.
        client: If you're not relying on a default client, you pass a `glm.TextServiceClient` instead.

    Returns:
        A `types.Completion` containing the model's text completion response.
    r-   )rE   Úrequest)rD   Ú_generate_response)r.   r    r/   r0   r1   r2   r3   r4   r5   rE   rI   s              r   Úgenerate_textrK   „   sI   € õp *ØØØØ'Ø+ØØØ'Ø%ð
ñ 
ô 
€Gõ  V°WÐ=Ñ=Ô=Ð=r   F)Úinitc                  ó   — e Zd Zd„ ZdS )Ú
Completionc                ó¬   — |                      ¦   «         D ]\  }}t          | ||¦  «         Œd | _        | j        r| j        d         d         | _        d S d S )Nr   Úoutput)ÚitemsÚsetattrÚresultÚ
candidates)ÚselfÚkwargsÚkeyÚvalues       r   Ú__init__zCompletion.__init__Î   sd   € Ø Ÿ,š,™.œ.ð 	&ð 	&‰JˆC�Ý�D˜#˜uÑ%Ô%Ð%Ð%àˆŒØŒ?ð 	7Øœ/¨!Ô,¨XÔ6ˆDŒKˆKˆKð	7ð 	7r   N)Ú__name__Ú
__module__Ú__qualname__rY   © r   r   rN   rN   Ë   s#   € € € € € ð7ð 7ð 7ð 7ð 7r   rN   rI   úglm.TextServiceClientc                óZ  — |€t          ¦   «         }|                     | ¦  «        }t          |¦  «                             |¦  «        }t	          j        |d         ¦  «        |d<   t	          j        |d         ¦  «        |d<   t	          j        |d         ¦  «        |d<   t          dd|i|¤ŽS )a€  
    Generates a response using the provided `glm.GenerateTextRequest` and client.

    Args:
        request: The text generation request.
        client: The client to use for text generation. Defaults to None, in which
            case the default text client is used.

    Returns:
        `Completion`: A `Completion` object with the generated text and response information.
    NÚfiltersÚsafety_feedbackrT   Ú_clientr]   )	r   rK   ÚtypeÚto_dictr   Úconvert_filters_to_enumsÚ convert_safety_feedback_to_enumsÚconvert_candidate_enumsrN   )rI   rE   Úresponses      r   rJ   rJ   ×   s°   € ð €~Ý(Ñ*Ô*ˆà×#Ò# GÑ,Ô,€HÝ�H‰~Œ~×%Ò% hÑ/Ô/€Hå&Ô?ÀÈÔ@SÑTÔT€HˆYÑÝ".Ô"OØÐ"Ô#ñ#ô #€HÐÑõ *ÔAÀ(È<ÔBXÑYÔY€Hˆ\ÑåÐ1Ð1˜fÐ1¨Ð1Ð1Ð1r   útext_types.TokenCountc                óä   — t          j        | ¦  «        }|€t          ¦   «         }|                     t	          j        |d|i¬¦  «        ¦  «        }t          |¦  «                             |¦  «        S )Nr$   )r.   r    )r   Úget_base_model_namer   Úcount_text_tokensr'   ÚCountTextTokensRequestrc   rd   )r.   r    rE   Ú
base_modelrS   s        r   rl   rl   ô   sm   € õ
 Ô+¨EÑ2Ô2€Jà€~Ý(Ñ*Ô*ˆà×%Ò%ÝÔ"¨¸VÀVÐ<LÐMÑMÔMñô €Fõ �‰<Œ<×Ò Ñ'Ô'Ð'r   ú model_types.BaseModelNameOptionsr$   útext_types.EmbeddingDictc                ó   — d S ©Nr]   ©r.   r$   rE   s      r   Úgenerate_embeddingsrt     ó	   € ð €Cr   úSequence[str]útext_types.BatchEmbeddingDictc                ó   — d S rr   r]   rs   s      r   rt   rt     ru   r   ústr | Sequence[str]ú8text_types.EmbeddingDict | text_types.BatchEmbeddingDictc                ób  — t          j        | ¦  «        } |€t          ¦   «         }t          |t          ¦  «        r_t          j        | |¬¦  «        }|                     |¦  «        }t          |¦  «         	                    |¦  «        }|d         d         |d<   n–dg i}t          |t          ¦  «        D ]z}t          j        | |¬¦  «        }|                     |¦  «        }t          |¦  «         	                    |¦  «        }|d                              d„ |d         D ¦   «         ¦  «         Œ{|S |S )añ  Calls the API to create an embedding for the text passed in.

    Args:
        model: Which model to call, as a string or a `types.Model`.

        text: Free-form input text given to the model. Given a string, the model will
              generate an embedding based on the input text.

        client: If you're not relying on a default client, you pass a `glm.TextServiceClient` instead.

    Returns:
        Dictionary containing the embedding (list of float values) for the input text.
    N)r.   r$   Ú	embeddingrX   )r.   Útextsc              3  ó&   K  — | ]}|d          V — ŒdS )rX   Nr]   )Ú.0Úes     r   ú	<genexpr>z&generate_embeddings.<locals>.<genexpr>:  s&   è è € Ð&XÐ&X°a q¨¤zÐ&XÐ&XÐ&XÐ&XÐ&XÐ&Xr   Ú
embeddings)r   r@   r   r%   r&   r'   ÚEmbedTextRequestÚ
embed_textrc   rd   r   ÚEMBEDDING_MAX_BATCH_SIZEÚBatchEmbedTextRequestÚbatch_embed_textÚextend)r.   r$   rE   Úembedding_requestÚembedding_responseÚembedding_dictrS   r   s           r   rt   rt     s>  € õ$ Ô'¨Ñ.Ô.€Eà€~Ý(Ñ*Ô*ˆå�$�ÑÔð ÝÔ0°uÀ4ÐHÑHÔHÐØ#×.Ò.Ð/@ÑAÔAÐÝÐ0Ñ1Ô1×9Ò9Ð:LÑMÔMˆØ&4°[Ô&AÀ'Ô&Jˆ�{Ñ#Ð#à˜rÐ"ˆÝ˜dÕ$<Ñ=Ô=ð 	Yð 	YˆEå #Ô 9ÀÈUÐ SÑ SÔ SÐØ!'×!8Ò!8Ð9JÑ!KÔ!KÐÝ!Ð"4Ñ5Ô5×=Ò=Ð>PÑQÔQˆNØ�;Ô×&Ò&Ð&XÐ&X¸>È,Ô;WÐ&XÑ&XÔ&XÑXÔXÐXÐXØˆàÐr   )r   r   r   r   r   r   )r    r!   r   r"   )r.   r6   r    r7   r/   r8   r0   r9   r1   r9   r2   r9   r3   r9   r4   r:   r5   r;   r   r<   )r.   r6   r    r&   r/   r8   r0   r9   r1   r9   r2   r8   r3   r8   r4   r:   r5   r;   rE   rF   r   rG   rr   )rI   r<   rE   r^   r   rN   )r.   r6   r    r&   rE   rF   r   ri   )r.   ro   r$   r&   rE   r^   r   rp   )r.   ro   r$   rv   rE   r^   r   rw   )r.   ro   r$   ry   rE   r^   r   rz   )&Ú
__future__r   ÚdataclassesÚcollections.abcr   r   Ú	itertoolsÚtypingr   r   Úgoogle.ai.generativelanguageÚaiÚgenerativelanguager'   Úgoogle.generativeai.clientr   Úgoogle.generativeair	   Úgoogle.generativeai.typesr
   r   r   r   ÚDEFAULT_TEXT_MODELr…   Úbatchedr   ÚAttributeErrorr   r,   rD   rK   ÚprettyprintÚ	dataclassrN   rJ   rl   rt   r]   r   r   ú<module>rœ      sú  ðð #Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ø .Ð .Ð .Ð .Ð .Ð .Ð .Ð .Ø Ð Ð Ð Ø .Ð .Ð .Ð .Ð .Ð .Ð .Ð .Ð .Ð .à *Ð *Ð *Ð *Ð *Ð *Ð *Ð *Ð *à >Ð >Ð >Ð >Ð >Ð >Ø ,Ð ,Ð ,Ð ,Ð ,Ð ,Ø 0Ð 0Ð 0Ð 0Ð 0Ð 0Ø 1Ð 1Ð 1Ð 1Ð 1Ð 1Ø &Ð &Ð &Ð &Ð &Ð &Ø 2Ð 2Ð 2Ð 2Ð 2Ð 2à,Ð ØÐ ðàÔ €H€HøØð ð ð Øˆ�‰Œ€Aðð ð ð ð ð ðøøøð"Dð Dð Dð Dð. .@ØØ $Ø"&Ø$(ØØØ@DØ15ð6ð 6ð 6ð 6ð 6ð 6ðv .@à $Ø"&Ø$(ØØØ@DØ15Ø+/ðD>ð D>ð D>ð D>ð D>ð D>ðN ÔØ€Ô˜EÐ"Ñ"Ô"ð7ð 7ð 7ð 7ð 7�Ô&ñ 7ô 7ñ #Ô"ñ Ôð7ð GKð2ð 2ð 2ð 2ð 2ð@ ,0ð(ð (ð (ð (ð (ð" 
ð %)ðð ð ð ñ 
„ðð 
ð %)ðð ð ð ñ 
„ðð %)ð&ð &ð &ð &ð &ð &ð &s   ÁA ÁA2Á1A2