
    ug                         d dl Z d dlZd dlmZmZmZ  e j                  e      Z G d dee         Z	 G d dee         Z
 G d dee         Zy)	    N)	DocumentsEmbeddingFunction
Embeddingsc                   2    e Zd ZdZd	dedefdZdedefdZy)
GooglePalmEmbeddingFunctionzvTo use this EmbeddingFunction, you must have the google.generativeai Python package installed and have a PaLM API key.api_key
model_namec                     |st        d      |st        d      	 dd lm} |j	                  |       || _        || _        y # t        $ r t        d      w xY w)NzPlease provide a PaLM API key.Please provide the model name.r   rThe Google Generative AI python package is not installed. Please install it with `pip install google-generativeai`r   )
ValueErrorgoogle.generativeaigenerativeaiImportError	configure_palm_model_name)selfr   r	   palms       q/var/www/openai/venv/lib/python3.12/site-packages/chromadb/utils/embedding_functions/google_embedding_function.py__init__z$GooglePalmEmbeddingFunction.__init__   sk    =>>=>>	. 	w'
%  	 E 	s   A Ainputreturnc                 |    |D cg c],  }| j                   j                  | j                  |      d   . c}S c c}w )N)modeltext	embedding)r   generate_embeddingsr   r   r   r   s      r   __call__z$GooglePalmEmbeddingFunction.__call__   sO    
 	
  JJ**1A1A*M 	
 	
 
s   19N)zmodels/embedding-gecko-001	__name__
__module____qualname____doc__strr   r   r   r!        r   r   r   
   s.     A& & &$
i 
J 
r)   r   c                   <    e Zd ZdZ	 	 	 d
dededefdZdedefdZy	)#GoogleGenerativeAiEmbeddingFunctionzxTo use this EmbeddingFunction, you must have the google.generativeai Python package installed and have a Google API key.r   r	   	task_typec                     |st        d      |st        d      	 dd lm} |j	                  |       || _        || _        || _        d | _        | j                  dk(  rd| _        y y # t        $ r t        d      w xY w)Nz Please provide a Google API key.r   r   r   r   RETRIEVAL_DOCUMENTzEmbedding of single string)	r   r   r   r   r   _genair   
_task_type_task_title)r   r   r	   r,   genais        r   r   z,GoogleGenerativeAiEmbeddingFunction.__init__-   s     ?@@=>>	/ 	(%#??22;D 3  	 E 	s   A( (A=r   r   c           	          |D cg c]B  }| j                   j                  | j                  || j                  | j                        d   D c}S c c}w )N)r   contentr,   titler   )r/   embed_contentr   r0   r1   r    s      r   r!   z,GoogleGenerativeAiEmbeddingFunction.__call__H   sg     
  KK%%&&//&&	 & 
  
 	
 
s   AAN)zmodels/embedding-001r.   r"   r(   r)   r   r+   r+   (   sG     Cv
 1-	<< < 	<6	
i 	
J 	
r)   r+   c            	       <    e Zd Z	 	 	 d
dedededefdZdedefdZy	)GoogleVertexEmbeddingFunctionr   r	   
project_idregionc           	          d| d| d| d| d	| _         t        j                         | _        | j                  j                  j                  dd| i       y )Nzhttps://z'-aiplatform.googleapis.com/v1/projects/z/locations/z/publishers/goole/models/z:predictAuthorizationzBearer )_api_urlhttpxClient_sessionheadersupdate)r   r   r	   r9   r:   s        r   r   z&GoogleVertexEmbeddingFunction.__init__Y   st     #6(*QR\Q]]hiohp  qJ  KU  JV  V^  _$$o	7J%KLr)   r   r   c                     g }|D ][  }| j                   j                  | j                  dd|igi      j                         }d|v sB|j	                  |d   d   d          ] |S )N	instancesr4   )jsonpredictions
embeddingsvalues)r@   postr=   rE   append)r   r   rG   r   responses        r   r!   z&GoogleVertexEmbeddingFunction.__call__d   sy    
D}}))[It3D2E$F * df  (!!(="9,"G"QR  r)   N)ztextembedding-geckozcloud-large-language-modelszus-central1)r#   r$   r%   r'   r   r   r   r!   r(   r)   r   r8   r8   T   sP     07#	M	M 	M 		M
 	M
i 
J 
r)   r8   )loggingr>   chromadb.api.typesr   r   r   	getLoggerr#   loggerr   r+   r8   r(   r)   r   <module>rP      sZ      G G			8	$
"3I"> 
<)
*;I*F )
X$5i$@ r)   