o
    ß­jF/  ã                   @  s€  U d dl mZ d dlZd dlmZmZmZmZmZm	Z	 d dl
m  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 d
lmZ dZdZe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"“ej#ej#“dej#dej#ej$ej$dej$d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&i¥Z'd"e(d#< dPd(d)„Z)zej*Z+W n e,yó   ed*ƒZ-dQd0d1„Z+Y nw e					dRdSdAdB„ƒZ.e					dRdTdEdB„ƒZ.					dRdUdIdB„Z.e					dRdVdKdL„ƒZ/e					dRdWdMdL„ƒZ/					dRdXdOdL„Z/dS )Yé    )ÚannotationsN)ÚAnyÚIterableÚoverloadÚTypeVarÚUnionÚMapping)Úprotos)Úget_default_generative_client)Ú#get_default_generative_async_client)Úhelper_types)Ú
text_types)Úmodel_types)Úcontent_typeszmodels/embedding-001éd   Útask_type_unspecifiedÚunspecifiedé   Úretrieval_queryÚqueryé   Úretrieval_documentÚdocumenté   Úsemantic_similarityÚ
similarityé   Úclassificationé   Ú
clusteringé   Úquestion_answeringÚqaé   Úfact_verificationÚverificationz1dict[EmbeddingTaskTypeOptions, EmbeddingTaskType]Ú_EMBEDDING_TASK_TYPEÚxÚEmbeddingTaskTypeOptionsÚreturnÚEmbeddingTaskTypec                 C  s   t | tƒr	|  ¡ } t|  S ©N)Ú
isinstanceÚstrÚlowerr&   )r'   © r/   úZ/var/www/html/CropPilot/venv/lib/python3.10/site-packages/google/generativeai/embedding.pyÚto_task_typeH   s   
r1   ÚTÚiterableúIterable[T]ÚnÚintúIterable[list[T]]c                 c  sZ   � |dk rt d|› d�ƒ‚g }| D ]}| |¡ t|ƒ|kr#|V  g }q|r+|V  d S d S )Nr   zKInvalid input: The batch size 'n' must be a positive integer. You entered: z'. Please enter a number greater than 0.)Ú
ValueErrorÚappendÚlen)r3   r5   ÚbatchÚitemr/   r/   r0   Ú_batchedT   s   €
ÿ
€
ÿr=   Úmodelú model_types.BaseModelNameOptionsÚcontentúcontent_types.ContentTypeÚ	task_typeúEmbeddingTaskTypeOptions | NoneÚtitleú
str | NoneÚoutput_dimensionalityú
int | NoneÚclientú"glm.GenerativeServiceClient | NoneÚrequest_optionsú&helper_types.RequestOptionsType | Noneútext_types.EmbeddingDictc                 C  ó   d S r+   r/   ©r>   r@   rB   rD   rF   rH   rJ   r/   r/   r0   Úembed_contentd   ó   	rO   ú#Iterable[content_types.ContentType]útext_types.BatchEmbeddingDictc                 C  rM   r+   r/   rN   r/   r/   r0   rO   p   rP   ú?content_types.ContentType | Iterable[content_types.ContentType]úglm.GenerativeServiceClientú8text_types.EmbeddingDict | text_types.BatchEmbeddingDictc                   sX  t  ˆ ¡‰ |du ri }|du rtƒ }ˆr&tˆƒtjur&tdˆ› dˆ› d�ƒ‚ˆr4ˆdk r4tdˆ› d�ƒ‚ˆr:tˆƒ‰t|tƒr…t|t	t
fƒs…dg i}‡ ‡‡‡fdd	„|D ƒ}t|tƒD ]'}	tjˆ |	d
�}
|j|
fi |¤Ž}t|ƒ |¡}|d  dd	„ |d D ƒ¡ q[|S tjˆ t |¡ˆˆˆd�}
|j|
fi |¤Ž}t|ƒ |¡}|d d |d< |S )a™  Calls the API to create embeddings for content passed in.

    Args:
        model:
            Which [model](https://ai.google.dev/models/gemini#embedding) to
            call, as a string or a `types.Model`.

        content:
            Content to embed.

        task_type:
            Optional task type for which the embeddings will be used. Can only
            be set for `models/embedding-001`.

        title:
            An optional title for the text. Only applicable when task_type is
            `RETRIEVAL_DOCUMENT`.

        output_dimensionality:
            Optional reduced dimensionality for the output embeddings. If set,
            excessive values from the output embeddings will be truncated from
            the end.

        request_options:
            Options for the request.

    Return:
        Dictionary containing the embedding (list of float values) for the
        input content.
    NúsInvalid task type: When a title is specified, the task must be of a 'retrieval document' type. Received task type: ú and title: Ú.r   úQInvalid value: `output_dimensionality` must be a non-negative integer. Received: Ú	embeddingc                 3  ó*   � | ]}t jˆ t |¡ˆˆˆd �V  qdS ©©r>   r@   rB   rD   rF   N©r	   ÚEmbedContentRequestr   Ú
to_content©Ú.0Úc©r>   rF   rB   rD   r/   r0   Ú	<genexpr>º   ó   € ùû
ÿz embed_content.<locals>.<genexpr>©r>   Úrequestsc                 s  ó   � | ]}|d  V  qdS ©ÚvaluesNr/   ©rb   Úer/   r/   r0   re   Ë   ó   € Ú
embeddingsr]   rk   )r   Úmake_model_namer
   r1   r*   ÚRETRIEVAL_DOCUMENTr8   r,   r   r-   r   r=   ÚEMBEDDING_MAX_BATCH_SIZEr	   ÚBatchEmbedContentsRequestÚbatch_embed_contentsÚtypeÚto_dictÚextendr_   r   r`   rO   ©r>   r@   rB   rD   rF   rH   rJ   Úresultrh   r;   Úembedding_requestÚembedding_responseÚembedding_dictr/   rd   r0   rO   |   sZ   
'ÿ
ÿø
ÿþûÿþú'glm.GenerativeServiceAsyncClient | Nonec                 Ã  ó   �d S r+   r/   rN   r/   r/   r0   Úembed_content_asyncÞ   ó   €	r   c                 Ã  r~   r+   r/   rN   r/   r/   r0   r   ê   r€   ú glm.GenerativeServiceAsyncClientc                 ƒ  sf  �t  ˆ ¡‰ |du ri }|du rtƒ }ˆr'tˆƒtjur'tdˆ› dˆ› d�ƒ‚ˆr5ˆdk r5tdˆ› d�ƒ‚ˆr;tˆƒ‰t|tƒr‰t|t	t
fƒs‰dg i}‡ ‡‡‡fdd	„|D ƒ}t|tƒD ]*}	tjˆ |	d
�}
|j|
fi |¤ŽI dH }t|ƒ |¡}|d  dd	„ |d D ƒ¡ q\|S tjˆ t |¡ˆˆˆd�}
|j|
fi |¤ŽI dH }t|ƒ |¡}|d d |d< |S )z?Calls the API to create async embeddings for content passed in.NrV   rW   rX   r   rY   rZ   c                 3  r[   r\   r^   ra   rd   r/   r0   re     rf   z&embed_content_async.<locals>.<genexpr>rg   c                 s  ri   rj   r/   rl   r/   r/   r0   re   (  rn   ro   r]   rk   )r   rp   r   r1   r*   rq   r8   r,   r   r-   r   r=   rr   r	   rs   rt   ru   rv   rw   r_   r   r`   rO   rx   r/   rd   r0   r   ö   s\   €
ÿ
ÿø
ÿþûÿþ)r'   r(   r)   r*   )r3   r4   r5   r6   r)   r7   )NNNNN)r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   r)   rL   )r>   r?   r@   rQ   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   r)   rR   )r>   r?   r@   rS   rB   rC   rD   rE   rF   rG   rH   rT   rJ   rK   r)   rU   )r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   r}   rJ   rK   r)   rL   )r>   r?   r@   rQ   rB   rC   rD   rE   rF   rG   rH   r}   rJ   rK   r)   rR   )r>   r?   r@   rS   rB   rC   rD   rE   rF   rG   rH   r�   rJ   rK   r)   rU   )0Ú
__future__r   Ú	itertoolsÚtypingr   r   r   r   r   r   Úgoogle.ai.generativelanguageÚaiÚgenerativelanguageÚglmÚgoogle.generativeair	   Úgoogle.generativeai.clientr
   r   Úgoogle.generativeai.typesr   r   r   r   ÚDEFAULT_EMB_MODELrr   ÚTaskTyper*   r6   r-   r(   ÚTASK_TYPE_UNSPECIFIEDÚRETRIEVAL_QUERYrq   ÚSEMANTIC_SIMILARITYÚCLASSIFICATIONÚ
CLUSTERINGÚQUESTION_ANSWERINGÚFACT_VERIFICATIONr&   Ú__annotations__r1   Úbatchedr=   ÚAttributeErrorr2   rO   r   r/   r/   r/   r0   Ú<module>   sÞ    ÿþýüûúùø	÷
öõôóòñðïâ
"
ýùùùbùùù