
    7|h                        d dl mZ d dlmZmZmZmZ d dlmZ d dl	m
Z
 d dlmZmZ ddZ G d de
e      Z G d	 d
e      Zy)    )annotations)AnyDictIteratorList)urlparse)
Embeddings)	BaseModelPrivateAttrc              #  V   K   t        dt        |       |      D ]  }| |||z      y w)Nr   )rangelen)textssizeis      d/var/www/html/test/engine/venv/lib/python3.12/site-packages/langchain_community/embeddings/mlflow.py_chunkr   
   s3     1c%j$' "AD!!"s   ')c                       e Zd ZU dZded<   	 ded<   	  e       Zded<   	 i Zded<   	 i Zded	<   d fd
Z	e
dd       ZddZddZddZddZ xZS )MlflowEmbeddingsa  Embedding LLMs in MLflow.

    To use, you should have the `mlflow[genai]` python package installed.
    For more information, see https://mlflow.org/docs/latest/llms/deployments.

    Example:
        .. code-block:: python

            from langchain_community.embeddings import MlflowEmbeddings

            embeddings = MlflowEmbeddings(
                target_uri="http://localhost:5000",
                endpoint="embeddings",
            )
    strendpoint
target_urir   _clientDict[str, str]query_paramsdocuments_paramsc                    t        |   di | | j                          	 ddlm}  || j
                        | _        y # t        $ r}t        d| j                   d      |d }~ww xY w)Nr   )get_deploy_clientz;Failed to create the client. Please run `pip install mlflowz#` to install required dependencies. )	super__init___validate_urimlflow.deploymentsr   r   r   ImportError_mlflow_extras)selfkwargsr   e	__class__s       r   r!   zMlflowEmbeddings.__init__*   su    "6"		<,T__=DL 	1151D1D0E F)) 		s   A   	A(	A##A(c                     y)Nz[genai]r   )r&   s    r   r%   zMlflowEmbeddings._mlflow_extras8   s        c                    | j                   dk(  ry g d}t        | j                         j                  |vrt        d| j                    d| d      y )N
databricks)httphttpsr-   zInvalid target URI: z. The scheme must be one of .)r   r   scheme
ValueError)r&   alloweds     r   r"   zMlflowEmbeddings._validate_uri<   s\    ??l*1DOO$++7:&t&7 8--4IQ8  ;r+   c                    g }t        |d      D ]H  }| j                  j                  | j                  d|i|      }|j	                  d |d   D               J |S )N   input)r   inputsc              3  &   K   | ]	  }|d      yw)	embeddingNr   ).0rs     r   	<genexpr>z)MlflowEmbeddings.embed.<locals>.<genexpr>M   s     CanCs   data)r   r   predictr   extend)r&   r   params
embeddingstxtresps         r   embedzMlflowEmbeddings.embedF   sn    (*
%$ 	DC<<''// ( D Cd6lCC	D r+   c                <    | j                  || j                        S )Nr@   )rD   r   )r&   r   s     r   embed_documentsz MlflowEmbeddings.embed_documentsP   s    zz%(=(=z>>r+   c                D    | j                  |g| j                        d   S )NrF   r   )rD   r   )r&   texts     r   embed_queryzMlflowEmbeddings.embed_queryS   s"    zz4&):):z;A>>r+   )r'   r   )returnr   )rK   None)r   	List[str]r@   r   rK   List[List[float]])r   rM   rK   rN   )rI   r   rK   zList[float])__name__
__module____qualname____doc____annotations__r   r   r   r   r!   propertyr%   r"   rD   rG   rJ   __classcell__)r)   s   @r   r   r      sn      MO =GS ,#%L.%.')n)  ??r+   r   c                  6    e Zd ZU dZddiZded<   ddiZded<   y)	MlflowCohereEmbeddingsz Cohere embedding LLMs in MLflow.
input_typesearch_queryr   r   search_documentr   N)rO   rP   rQ   rR   r   rS   r   r   r+   r   rW   rW   W   s%    *$0.#AL.A(46G'HnHr+   rW   N)r   rM   r   intrK   zIterator[List[str]])
__future__r   typingr   r   r   r   urllib.parser   langchain_core.embeddingsr	   pydanticr
   r   r   r   rW   r   r+   r   <module>ra      s<    " , , ! 0 +"
E?z9 E?PI- Ir+   