a
    bg                     @  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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	List[str]intzIterator[List[str]])textssizereturnc                 c  s,   t dt| |D ]}| |||  V  qd S )Nr   )rangelen)r   r   i r   s/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/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d
 fddZ	e
ddddZddddZddddddZdddddZdd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              
     st   t  jf i | |   zddlm} || j| _W n8 tyn } z td| j d|W Y d }~n
d }~0 0 d S )Nr   )get_deploy_clientz;Failed to create the client. Please run `pip install mlflowz#` to install required dependencies.)	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   zList[List[float]])r   paramsr   c                 C  sJ   g }t |dD ]6}| jj| jd|i|d}|dd |d D  q|S )N   input)r   inputsc                 s  s   | ]}|d  V  qdS )Z	embeddingNr   ).0rr   r   r   	<genexpr>M       z)MlflowEmbeddings.embed.<locals>.<genexpr>data)r   r   Zpredictr   extend)r%   r   r1   Z
embeddingstxtrespr   r   r   embedF   s    
zMlflowEmbeddings.embed)r   r   c                 C  s   | j || jdS )Nr1   )r=   r   )r%   r   r   r   r   embed_documentsP   s    z MlflowEmbeddings.embed_documentszList[float])textr   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)__name__
__module____qualname____doc____annotations__r
   r   r   r   r!   propertyr$   r"   r=   r?   rA   __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)rB   rC   rD   rE   r   rF   r   r   r   r   r   rI   W   s   
rI   N)
__future__r   typingr   r   r   r   urllib.parser   Zlangchain_core.embeddingsr   Zpydanticr	   r
   r   r   rI   r   r   r   r   <module>   s   H