o
    Zh                     @  s|   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dZG dd de
eZG dd deZdS )    )annotations)AnyDictIteratorList)urlparse)
Embeddings)	BaseModelPrivateAttrtexts	List[str]sizeintreturnIterator[List[str]]c                 c  s.    t dt| |D ]}| |||  V  q	d S )Nr   )rangelen)r   r   i r   \/var/www/html/lang_env/lib/python3.10/site-packages/langchain_community/embeddings/mlflow.py_chunk
   s   r   c                      s   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dZ	e
d ddZd!ddZd"ddZd#ddZd$ddZ  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_paramskwargsc              
     sf   t  jdi | |   zddlm} || j| _W d S  ty2 } z
td| j d|d }~ww )Nr   )get_deploy_clientz;Failed to create the client. Please run `pip install mlflowz#` to install required dependencies.r   )	super__init___validate_uriZmlflow.deploymentsr    r   r   ImportError_mlflow_extras)selfr   r    e	__class__r   r   r"   *   s   zMlflowEmbeddings.__init__r   c                 C  s   dS )Nz[genai]r   )r&   r   r   r   r%   8   s   zMlflowEmbeddings._mlflow_extrasNonec                 C  sB   | j dkrd S g d}t| j j|vrtd| j  d| dd S )N
databricks)httphttpsr+   zInvalid target URI: z. The scheme must be one of .)r   r   scheme
ValueError)r&   allowedr   r   r   r#   <   s   

zMlflowEmbeddings._validate_urir   r   paramsList[List[float]]c                 C  sJ   g }t |dD ]}| jj| jd|i|d}|dd |d D  q|S )N   input)r   Zinputsc                 s  s    | ]}|d  V  qdS )Z	embeddingNr   ).0rr   r   r   	<genexpr>M   s    z)MlflowEmbeddings.embed.<locals>.<genexpr>data)r   r   Zpredictr   extend)r&   r   r2   Z
embeddingstxtrespr   r   r   embedF   s   
zMlflowEmbeddings.embedc                 C  s   | j || jdS )Nr2   )r=   r   )r&   r   r   r   r   embed_documentsP   s   z MlflowEmbeddings.embed_documentstextList[float]c                 C  s   | j |g| jdd S )Nr>   r   )r=   r   )r&   r@   r   r   r   embed_queryS   s   zMlflowEmbeddings.embed_query)r   r   )r   r   )r   r*   )r   r   r2   r   r   r3   )r   r   r   r3   )r@   r   r   rA   )__name__
__module____qualname____doc____annotations__r
   r   r   r   r"   propertyr%   r#   r=   r?   rB   __classcell__r   r   r(   r   r      s$   
 




r   c                   @  s2   e Zd ZU dZddiZded< ddiZded< dS )	MlflowCohereEmbeddingsz Cohere embedding LLMs in MLflow.Z
input_typeZsearch_queryr   r   Zsearch_documentr   N)rC   rD   rE   rF   r   rG   r   r   r   r   r   rJ   W   s   
 rJ   N)r   r   r   r   r   r   )
__future__r   typingr   r   r   r   urllib.parser   Zlangchain_core.embeddingsr   Zpydanticr	   r
   r   r   rJ   r   r   r   r   <module>   s    
H