
    3i                      t    S SK JrJrJrJr  S SKJrJrJrJ	r	  S SK
r
S SKrS SKJr  S SKr " S S\\   5      rg)    )
Embeddings	DocumentsEmbeddingFunctionSpace)ListDictAnyOptionalNvalidate_config_schemac                   r   \ rS rSr          SS\\   S\S\\   S\\   S\\   S\\   S	\\   S
\\\\4      S\\   S\4S jjrS\	S\
4S jr\S\4S j5       rS\4S jrS\\   4S jr\S\\\4   SS4S j5       rS\\\4   4S jrS\\\4   S\\\4   SS4S jr\S\\\4   SS4S j5       rSrg)OpenAIEmbeddingFunction	   Napi_key
model_nameorganization_idapi_baseapi_typeapi_versiondeployment_iddefault_headers
dimensionsapi_key_env_varc                     SSK nUb  [        R                  " S[
        5        Xl        U=(       d    [        R                  " U
5      U l	        U R                  (       d  [        SU
 S35      eX l
        X0l        X@l        XPl        X`l        Xpl        Xl        Xl        SU R                  0nU R                  b  U R                  US'   U R                  b  U R                  US	'   U R                   b  U R                   US
'   UR$                  " S0 UD6U l        U R                  S:X  a  U R                  c  [        S5      eU R                  c  [        S5      eU R                  c  [        S5      eSSK Jn  U" U R                  U R                  U R                  U R                  U R                   S9U l        gg! [         a    [        S5      ef = f)a  
Initialize the OpenAIEmbeddingFunction.
Args:
    api_key_env_var (str, optional): Environment variable name that contains your API key for the OpenAI API.
        Defaults to "CHROMA_OPENAI_API_KEY".
    model_name (str, optional): The name of the model to use for text
        embeddings. Defaults to "text-embedding-ada-002".
    organization_id(str, optional): The OpenAI organization ID if applicable
    api_base (str, optional): The base path for the API. If not provided,
        it will use the base path for the OpenAI API. This can be used to
        point to a different deployment, such as an Azure deployment.
    api_type (str, optional): The type of the API deployment. This can be
        used to specify a different deployment, such as 'azure'. If not
        provided, it will use the default OpenAI deployment.
    api_version (str, optional): The api version for the API. If not provided,
        it will use the api version for the OpenAI API. This can be used to
        point to a different deployment, such as an Azure deployment.
    deployment_id (str, optional): Deployment ID for Azure OpenAI.
    default_headers (Dict[str, str], optional): A mapping of default headers to be sent with each API request.
    dimensions (int, optional): The number of dimensions for the embeddings.
        Only supported for `text-embedding-3` or later models from OpenAI.
        https://platform.openai.com/docs/api-reference/embeddings/create#embeddings-create-dimensions
r   NzWThe openai python package is not installed. Please install it with `pip install openai`zDirect api_key configuration will not be persisted. Please use environment variables via api_key_env_var for persistent storage.zThe z! environment variable is not set.r   organizationbase_urlr   azurez.api_version must be specified for Azure OpenAIz0deployment_id must be specified for Azure OpenAIz+api_base must be specified for Azure OpenAI)AzureOpenAI)r   r   azure_endpointazure_deploymentr    )openaiImportError
ValueErrorwarningswarnDeprecationWarningr   osgetenvr   r   r   r   r   r   r   r   r   OpenAIclientr   )selfr   r   r   r   r   r   r   r   r   r   r"   client_paramsr   s                 v/home/james-whalen/.local/lib/python3.13/site-packages/chromadb/utils/embedding_functions/openai_embedding_function.py__init__ OpenAIEmbeddingFunction.__init__
   s   H	 MM_"  /<"))O"<||tO#44UVWW$.  &*.$ *3DLL(A+,0,@,@M.)==$(,M*%+/3/C/CM+,mm4m4 ==G#' !QRR!!) !STT}}$ !NOO*% ,,#}}!%!3!3 $ 4 4DK $O  	i 	s   F8 8Ginputreturnc                 p   U(       d  / $ U R                   US.nU R                  b  SU R                   ;   a  U R                  US'   U R                  R                  R                  " S0 UD6nUR
                   Vs/ s H0  n[        R                  " UR                  [        R                  S9PM2     sn$ s  snf )z
Generate embeddings for the given documents.
Args:
    input: Documents to generate embeddings for.
Returns:
    Embeddings for the documents.
)modelr1   ztext-embedding-3r   )dtyper!   )
r   r   r+   
embeddingscreatedatanparray	embeddingfloat32)r,   r1   embedding_paramsresponser8   s        r.   __call__ OpenAIEmbeddingFunction.__call__i   s     I __,

 ??&+=+P-1__\* ;;))00D3CD HP}}U}trzz:}UUUs   97B3c                      g)Nr"   r!   r!       r.   nameOpenAIEmbeddingFunction.name       rB   c                     g)Ncosiner!   r,   s    r.   default_space%OpenAIEmbeddingFunction.default_space   rE   rB   c                 
    / SQ$ )N)rG   l2ipr!   rH   s    r.   supported_spaces(OpenAIEmbeddingFunction.supported_spaces   s    %%rB   configzEmbeddingFunction[Documents]c                 p   U R                  S5      nU R                  S5      nU R                  S5      nU R                  S5      nU R                  S5      nU R                  S5      nU R                  S5      nU R                  S5      nU R                  S	5      n	Ub  Uc   S
5       e[        UUUUUUUUU	S9	$ )Nr   r   r   r   r   r   r   r   r   zThis code should not be reached	r   r   r   r   r   r   r   r   r   )getr   )
rP   r   r   r   r   r   r   r   r   r   s
             r.   build_from_config)OpenAIEmbeddingFunction.build_from_config   s     !**%67ZZ-
 **%67::j)::j)jj/

?3 **%67ZZ-
"j&8;;;5 '+!+#'+!

 
	
rB   c           
          U R                   U R                  U R                  U R                  U R                  U R
                  U R                  U R                  U R                  S.	$ )NrR   rR   rH   s    r.   
get_config"OpenAIEmbeddingFunction.get_config   sU    #33//#33++!//#33//

 
	
rB   
old_config
new_configc                 &    SU;   a  [        S5      eg )Nr   zSThe model name cannot be changed after the embedding function has been initialized.)r$   )r,   rY   rZ   s      r.   validate_config_update.OpenAIEmbeddingFunction.validate_config_update   s!     :%e  &rB   c                     [        U S5        g)z
Validate the configuration using the JSON schema.

Args:
    config: Configuration to validate

Raises:
    ValidationError: If the configuration does not match the schema
r"   Nr   )rP   s    r.   validate_config'OpenAIEmbeddingFunction.validate_config   s     	vx0rB   )r   r   r   r   r   r+   r   r   r   r   r   )
Nztext-embedding-ada-002NNNNNNNCHROMA_OPENAI_API_KEY)__name__
__module____qualname____firstlineno__r
   strr   intr/   r   r   r?   staticmethodrC   r   rI   r   rN   r	   rT   rW   r\   r_   __static_attributes__r!   rB   r.   r   r   	   s    "&2)-"&"&%)'+48$(6]#] ] "#	]
 3-] 3-] c]]  }] "$sCx.1] SM] ]~Vi VJ V6 #  u &$u+ & 
$sCx. 
5S 
 
8
DcN 
sCx.6:38n	 
1S#X 
14 
1 
1rB   r   )chromadb.api.typesr   r   r   r   typingr   r   r	   r
   r(   numpyr9   *chromadb.utils.embedding_functions.schemasr   r%   r   r!   rB   r.   <module>rn      s1    N N , , 	  M C1/	: C1rB   