
    ; iF/                       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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 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#<   dLd(Z)	 ej*        Z+n# e,$ r  ed)          Z-dMd/Z+Y nw xY we	 	 	 	 	 dNdOd?            Z.e	 	 	 	 	 dNdPdB            Z.	 	 	 	 	 dNdQdFZ.e	 	 	 	 	 dNdRdH            Z/e	 	 	 	 	 dNdSdI            Z/	 	 	 	 	 dNdTdKZ/dS )U    )annotationsN)AnyIterableoverloadTypeVarUnionMapping)protos)get_default_generative_client)#get_default_generative_async_client)helper_types)model_types)
text_types)content_typeszmodels/embedding-001d   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                n    t          | t                    r|                                 } t          |          S N)
isinstancestrlowerr'   )r(   s    u/var/www/development/aibuddy-work/election-extract/venv/lib/python3.11/site-packages/google/generativeai/embedding.pyto_task_typer2   H   s,    !S GGII""    TiterableIterable[T]nintIterable[list[T]]c              #     K   |dk     rt          d| d          g }| D ]0}|                    |           t          |          |k    r|V  g }1|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)r5   r7   batchitems       r1   _batchedr@   T   s      q55 I^_  I  I  I    	 	DLL5zzQ 	KKKKK	 	r3   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                    d S r-    rA   rC   rE   rG   rI   rK   rM   s          r1   embed_contentrS   d   s	      #sr3   #Iterable[content_types.ContentType]text_types.BatchEmbeddingDictc                    d S r-   rQ   rR   s          r1   rS   rS   p   s	     %(Cr3   ?content_types.ContentType | Iterable[content_types.ContentType]glm.GenerativeServiceClient8text_types.EmbeddingDict | text_types.BatchEmbeddingDictc                    t          j                    |i }|t                      }r1t                    t          j        urt          d d d          rdk     rt          d d          rt                    t          |t                    rt          |t          t          f          sdg i} fd|D             }t          |t                    D ]s}	t          j         |		          }
 |j        |
fi |}t!          |                              |          }|d                             d
 |d         D                        t|S t          j         t)          j        |                    }
 |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.
    NsInvalid 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  n   K   | ]/}t          j        t          j        |                     V  0dS rA   rC   rE   rG   rI   Nr
   EmbedContentRequestr   
to_content.0crA   rI   rE   rG   s     r1   	<genexpr>z embed_content.<locals>.<genexpr>   e       	
 	
  &%033#&;  	
 	
 	
 	
 	
 	
r3   rA   requestsc              3  &   K   | ]}|d          V  dS valuesNrQ   rg   es     r1   ri   z embed_content.<locals>.<genexpr>   &      &Y&Yqq{&Y&Y&Y&Y&Y&Yr3   
embeddingsrb   ro   )r   make_model_namer   r2   r+   RETRIEVAL_DOCUMENTr;   r.   r   r/   r	   r@   EMBEDDING_MAX_BATCH_SIZEr
   BatchEmbedContentsRequestbatch_embed_contentstypeto_dictextendrd   r   re   rS   rA   rC   rE   rG   rI   rK   rM   resultrl   r>   embedding_requestembedding_responseembedding_dicts   ` ```        r1   rS   rS   |   s   N '..E~.00 
i((0A0TTT b  CL  b  b  Z_  b  b  b
 
 	
  
!6!:!:x`uxxx
 
 	
  , ++	'8$$ #Z#w-P-P #r"	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 h(@AA 	Z 	ZE & @uW\ ] ] ]!<!<!" "!" " ""455==>PQQN;&&&Y&YN<<X&Y&Y&YYYYY"6!,W55"7
 
 
 2V1
 

 
 01199:LMM&4[&A(&K{#r3   'glm.GenerativeServiceAsyncClient | Nonec                
   K   d S r-   rQ   rR   s          r1   embed_content_asyncr      s        #sr3   c                
   K   d S r-   rQ   rR   s          r1   r   r      s       %(Cr3    glm.GenerativeServiceAsyncClientc                   K   t          j                    |i }|t                      }r1t                    t          j        urt          d d d          rdk     rt          d d          rt                    t          |t                    rt          |t          t          f          sdg i} fd|D             }t          |t                    D ]y}	t          j         |		          }
 |j        |
fi | d{V }t!          |                              |          }|d                             d
 |d         D                        z|S t          j         t)          j        |                    }
 |j        |
fi | d{V }t!          |                              |          }|d         d         |d<   |S )z?Calls the API to create async embeddings for content passed in.Nr[   r\   r]   r   r^   r_   c              3  n   K   | ]/}t          j        t          j        |                     V  0dS ra   rc   rf   s     r1   ri   z&embed_content_async.<locals>.<genexpr>  rj   r3   rk   c              3  &   K   | ]}|d          V  dS rn   rQ   rp   s     r1   ri   z&embed_content_async.<locals>.<genexpr>(  rr   r3   rs   rb   ro   )r   rt   r   r2   r+   ru   r;   r.   r   r/   r	   r@   rv   r
   rw   rx   ry   rz   r{   rd   r   re   rS   r|   s   ` ```        r1   r   r      s      '..E~466 
i((0A0TTT b  CL  b  b  Z_  b  b  b
 
 	
  
!6!:!:x`uxxx
 
 	
  , ++	'8$$ #Z#w-P-P #r"	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 h(@AA 	Z 	ZE & @uW\ ] ] ]'Bv'B!( (!( ( " " " " " " ""455==>PQQN;&&&Y&YN<<X&Y&Y&YYYYY"6!,W55"7
 
 
 $86#7$
 $
$
 $
 
 
 
 
 
 
 01199:LMM&4[&A(&K{#r3   )r(   r)   r*   r+   )r5   r6   r7   r8   r*   r9   )NNNNN)rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   r*   rO   )rA   rB   rC   rT   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   r*   rU   )rA   rB   rC   rW   rE   rF   rG   rH   rI   rJ   rK   rX   rM   rN   r*   rY   )rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   r   rM   rN   r*   rO   )rA   rB   rC   rT   rE   rF   rG   rH   rI   rJ   rK   r   rM   rN   r*   rU   )rA   rB   rC   rW   rE   rF   rG   rH   rI   rJ   rK   r   rM   rN   r*   rY   )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_MODELrv   TaskTyper+   r8   r/   r)   TASK_TYPE_UNSPECIFIEDRETRIEVAL_QUERYru   SEMANTIC_SIMILARITYCLASSIFICATION
CLUSTERINGQUESTION_ANSWERINGFACT_VERIFICATIONr'   __annotations__r2   batchedr@   AttributeErrorr4   rS   r   rQ   r3   r1   <module>r      s   # " " " " " "     C C C C C C C C C C C C C C C C * * * * * * * * * & & & & & & D D D D D D J J J J J J 2 2 2 2 2 2 1 1 1 1 1 1 0 0 0 0 0 0 3 3 3 3 3 3*  O  c+<!<= K+->-TK.K .DK $:	K
 %'8'HK (K (8K .K (*;*NK +K +>K !4K )+<+PK ,K ,@K  #7!K" $&7&F#K$ ''6 "3">##.++>

.(*;*N**<%7'):)L=K K     D# # # # HH   A     & 
 26(,15>B# # # # 
# 
 26(,15>B( ( ( ( 
( 26(,*.>B_ _ _ _ _D 
 26(,6:>B# # # # 
# 
 26(,6:>B( ( ( ( 
( 26(,/3>BB B B B B B Bs   >F FF