
    rhF/                       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j4                  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jB                  ejB                  dejB                  dejB                  dejB                  ejD                  ejD                  dejD                  dejD                  dejD                  ejF                  ejF                  dejF                  dejF                  ejH                  ejH                  dejH                  dejH                  dejJ                  dejJ                  dejJ                  ejJ                  ejJ                  dejL                  d ejL                  d!ejL                  ejL                  ejL                  iZ'd"e(d#<   d-d$Z)	 ejT                  Z+e	 	 	 	 	 d/	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d0d'       Z.e	 	 	 	 	 d/	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d1d(       Z.	 	 	 	 	 d/	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d2d)Z.e	 	 	 	 	 d/	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d3d*       Z/e	 	 	 	 	 d/	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d4d+       Z/	 	 	 	 	 d/	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d5d,Z/y# e,$ r  ed%      Z-d.d&Z+Y w xY w)6    )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_TYPEc                T    t        | t              r| j                         } t        |    S N)
isinstancestrlowerr'   )xs    p/var/www/html/ai-insurance-compliance-backend/venv/lib/python3.12/site-packages/google/generativeai/embedding.pyto_task_typer/   H   s"    !SGGI""    Tc              #     K   |dk  rt        d| d      g }| D ](  }|j                  |       t        |      |k(  s#| g }* |r| y y w)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)iterablenbatchitems       r.   _batchedr:   T   sv     q5]^_]`  aH  I   	DLL5zQ		 K s
   ;AAc                     y r)    modelcontent	task_typetitleoutput_dimensionalityclientrequest_optionss          r.   embed_contentrE   d   s      #r0   c                     y r)   r<   r=   s          r.   rE   rE   p   s     %(r0   c                (    t        j                          |i }|
t               }r-t              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 ]d  }	t        j                   |	      }
 |j                  |
fi |}t!        |      j#                  |      }|d   j%                  d	 |d
   D               f |S t        j&                   t)        j*                  |            }
 |j,                  |
fi |}t!        |      j#                  |      }|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.
    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  x   K   | ]1  }t        j                  t        j                  |              3 ywr>   r?   r@   rA   rB   Nr
   EmbedContentRequestr   
to_content.0cr>   rB   r@   rA   s     r.   	<genexpr>z embed_content.<locals>.<genexpr>   E      	
  &&%003#&; 	
   7:r>   requestsc              3  &   K   | ]	  }|d      ywvaluesNr<   rT   es     r.   rV   z embed_content.<locals>.<genexpr>        &Yqq{&Y   
embeddingsrO   r]   )r   make_model_namer   r/   EmbeddingTaskTypeRETRIEVAL_DOCUMENTr3   r*   r   r+   r	   r:   EMBEDDING_MAX_BATCH_SIZEr
   BatchEmbedContentsRequestbatch_embed_contentstypeto_dictextendrQ   r   rR   rE   r>   r?   r@   rA   rB   rC   rD   resultrZ   r8   embedding_requestembedding_responseembedding_dicts   ` ```        r.   rE   rE   |   s   N ''.E~.0i(0A0T0TT B  CL  BM  MY  Z_  Y`  `a  b
 	
 !6!:_`u_vvwx
 	
  +	'8$Z#w-Pr"	
 	
 h(@A 	ZE & @ @uW\ ]!<!<!<!"!" ""45==>PQN;&&&YN<<X&YY	Z "66!,,W5"7
 2V11

 0199:LM&4[&A(&K{#r0   c                   K   y wr)   r<   r=   s          r.   embed_content_asyncrr      s       #   c                   K   y wr)   r<   r=   s          r.   rr   rr      s      %(rs   c                X   K   t        j                          |i }|
t               }r-t              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 ]l  }	t        j                   |		      }
 |j                  |
fi | d{   }t!        |      j#                  |      }|d   j%                  d
 |d   D               n |S t        j&                   t)        j*                  |            }
 |j,                  |
fi | d{   }t!        |      j#                  |      }|d   d   |d<   |S 7 7 -w)z?Calls the API to create async embeddings for content passed in.NrH   rI   rJ   r   rK   rL   c              3  x   K   | ]1  }t        j                  t        j                  |              3 ywrN   rP   rS   s     r.   rV   z&embed_content_async.<locals>.<genexpr>  rW   rX   rY   c              3  &   K   | ]	  }|d      ywr\   r<   r^   s     r.   rV   z&embed_content_async.<locals>.<genexpr>(  r`   ra   rb   rO   r]   )r   rc   r   r/   rd   re   r3   r*   r   r+   r	   r:   rf   r
   rg   rh   ri   rj   rk   rQ   r   rR   rE   rl   s   ` ```        r.   rr   rr      s     ''.E~46i(0A0T0TT B  CL  BM  MY  Z_  Y`  `a  b
 	
 !6!:_`u_vvwx
 	
  +	'8$Z#w-Pr"	
 	
 h(@A 	ZE & @ @uW\ ]'Bv'B'B!(!( " ""45==>PQN;&&&YN<<X&YY	Z "66!,,W5"7
 $86#7#7$
$
 
 0199:LM&4[&A(&K{#+"
s%   C0F*6F&7BF*:F(;,F*(F*)r-   EmbeddingTaskTypeOptionsreturnrd   )r6   zIterable[T]r7   intry   zIterable[list[T]])NNNNN)r>    model_types.BaseModelNameOptionsr?   content_types.ContentTyper@   EmbeddingTaskTypeOptions | NonerA   
str | NonerB   
int | NonerC   "glm.GenerativeServiceClient | NonerD   &helper_types.RequestOptionsType | Nonery   text_types.EmbeddingDict)r>   r{   r?   #Iterable[content_types.ContentType]r@   r}   rA   r~   rB   r   rC   r   rD   r   ry   text_types.BatchEmbeddingDict)r>   r{   r?   ?content_types.ContentType | Iterable[content_types.ContentType]r@   r}   rA   r~   rB   r   rC   zglm.GenerativeServiceClientrD   r   ry   8text_types.EmbeddingDict | text_types.BatchEmbeddingDict)r>   r{   r?   r|   r@   r}   rA   r~   rB   r   rC   'glm.GenerativeServiceAsyncClient | NonerD   r   ry   r   )r>   r{   r?   r   r@   r}   rA   r~   rB   r   rC   r   rD   r   ry   r   )r>   r{   r?   r   r@   r}   rA   r~   rB   r   rC   z glm.GenerativeServiceAsyncClientrD   r   ry   r   )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_MODELrf   TaskTyperd   rz   r+   rx   TASK_TYPE_UNSPECIFIEDRETRIEVAL_QUERYre   SEMANTIC_SIMILARITYCLASSIFICATION
CLUSTERINGQUESTION_ANSWERINGFACT_VERIFICATIONr'   __annotations__r/   batchedr:   AttributeErrorr1   rE   rr   r<   r0   r.   <module>r      s]   #  C C * * & D J 2 1 0 3*  OO  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">">###..+++>>

.
.((*;*N*N***<<%77''):)L)L=K G D#  H( 
 26(,15>B#+#&# /# 	#
 &# /# <# # 
# 
 26(,15>B(+(0( /( 	(
 &( /( <( #( 
( 26(,*.>B_+_L_ /_ 	_
 &_ (_ <_ >_D 
 26(,6:>B#+#&# /# 	#
 &# 4# <# # 
# 
 26(,6:>B(+(0( /( 	(
 &( 4( <( #( 
( 26(,/3>BB+BLB /B 	B
 &B -B <B >BK  As   >K5 5L	L	