
    5P@i                    V   U d dl mZ d dlZd dlmZmZmZ d dlZd dl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	Zd
Zej0                  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jB                  ejB                  dejB                  dejB                  ejD                  ejD                  dejD                  dejD                  iZ#de$d<   d"dZ%	 ejL                  Z'e		 	 	 d$	 	 	 	 	 	 	 	 	 	 	 d%d       Z*e		 	 	 d$	 	 	 	 	 	 	 	 	 	 	 d&d        Z*	 	 	 d$	 	 	 	 	 	 	 	 	 	 	 d'd!Z*y# e($ r  e
d      Z)d#dZ'Y Ww xY w)(    )annotationsN)IterableSequenceMapping)r   overloadTypeVarUnionr   )get_default_generative_client)
text_types)model_types)content_typeszmodels/embedding-001d   task_type_unspecifiedunspecified   retrieval_queryquery   retrieval_documentdocument   semantic_similarity
similarity   classification   
clusteringz1dict[EmbeddingTaskTypeOptions, EmbeddingTaskType]_EMBEDDING_TASK_TYPEc                T    t        | t              r| j                         } t        |    S N)
isinstancestrlowerr   )xs    g/home/www/lebenam.kofcorporation.com/venv/lib/python3.12/site-packages/google/generativeai/embedding.pyto_task_typer&   ?   s"    !SGGI""    Tc              #     K   |dk  rt        d|       g }| D ](  }|j                  |       t        |      |k(  s#| g }* |r| y y w)Nr   z Batch size `n` must be >0, got: )
ValueErrorappendlen)iterablenbatchitems       r%   _batchedr1   K   sd     q5?sCDD 	DLL5zQ		 K s
   :AAc                     y r     modelcontent	task_typetitleclients        r%   embed_contentr:   Y        r'   c                     y r    r3   r4   s        r%   r:   r:   d   r;   r'   c                    t        j                          |
t               }r&t              t        j
                  urt        d      rt              t        |t              rt        |t        t        f      sdg i} fd|D        }t        |t              D ]b  }t        j                   |      }|j                  |      }	t!        |	      j#                  |	      }
|d   j%                  d |
d   D               d |S t        j&                   t)        j*                  |            }|j-                  |      }	t!        |	      j#                  |	      }
|
d   d   |
d<   |
S )	a  
    Calls the API to create embeddings for content passed in.

    Args:
        model: Which model 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`.

    Return:
        Dictionary containing the embedding (list of float values) for the input content.
    zIIf a title is specified, the task must be a retrieval document type task.	embeddingc              3  v   K   | ]0  }t        j                  t        j                  |              2 yw)r5   r6   r7   r8   N)glmEmbedContentRequestr   
to_content).0cr5   r7   r8   s     r%   	<genexpr>z embed_content.<locals>.<genexpr>   s@      
  ##]%=%=a%@I]b 
s   69)r5   requestsc              3  &   K   | ]	  }|d      yw)valuesNr3   )rD   es     r%   rF   z embed_content.<locals>.<genexpr>   s     &Yqq{&Ys   
embeddingsr@   rI   )r   make_model_namer
   r&   EmbeddingTaskTypeRETRIEVAL_DOCUMENTr*   r!   r   r"   r   r1   EMBEDDING_MAX_BATCH_SIZErA   BatchEmbedContentsRequestbatch_embed_contentstypeto_dictextendrB   r   rC   r:   )r5   r6   r7   r8   r9   resultrG   r/   embedding_requestembedding_responseembedding_dicts   ` ``       r%   r:   r:   o   sq   , ''.E~.0i(0A0T0TTW
 	
  +	'8$Z#w-Pr"
 	
 h(@A 	ZE # = =ETY Z!'!<!<=N!O!"45==>PQN;&&&YN<<X&YY		Z
 33!9!9'!Bi_d
 $112CD0199:LM&4[&A(&K{#r'   )r$   EmbeddingTaskTypeOptionsreturnrM   )r-   zIterable[T]r.   intrZ   zIterable[list[T]])NNN)r5    model_types.BaseModelNameOptionsr6   zcontent_types.ContentTyper7   EmbeddingTaskTypeOptions | Noner8   
str | Noner9   "glm.GenerativeServiceClient | NonerZ   ztext_types.EmbeddingDict)r5   r\   r6   z#Iterable[content_types.ContentType]r7   r]   r8   r^   r9   r_   rZ   ztext_types.BatchEmbeddingDict)r5   r\   r6   z?content_types.ContentType | Iterable[content_types.ContentType]r7   r]   r8   r^   r9   zglm.GenerativeServiceClientrZ   z8text_types.EmbeddingDict | text_types.BatchEmbeddingDict)+
__future__r   dataclassescollections.abcr   r   r   	itertoolstypingr   r   r	   google.ai.generativelanguageaigenerativelanguagerA   google.generativeai.clientr
   google.generativeai.typesr   r   r   DEFAULT_EMB_MODELrO   TaskTyperM   r[   r"   rY   TASK_TYPE_UNSPECIFIEDRETRIEVAL_QUERYrN   SEMANTIC_SIMILARITYCLASSIFICATION
CLUSTERINGr   __annotations__r&   batchedr1   AttributeErrorr(   r:   r3   r'   r%   <module>rt      sK   #  7 7  > > * * D 0 1 3*  LL  c+<!<= K++->-T-TK..K .DDK $::	K
 %%'8'H'HK ((K (88K ..K ((*;*N*NK ++K +>>K !44K ))+<+P+PK ,,K ,@@K  #77!K" $$&7&F&F#K$ '''66  "3">">###..-K G 4#  H$ 
 2615+& / 	
 /  
 
 2615+0 / 	
 / # 
 26*.8+8L8 /8 	8
 (8 >8O  As   H H('H(