U
    hg                     @  sp   d dl mZ d dlmZmZmZmZmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZmZ G dd deZd	S )
    )annotations)AnyDictListMappingOptional)urlparse)CallbackManagerForLLMRun)LLM)FieldPrivateAttrc                      s   e Zd ZU dZded< ded< dZded< dZd	ed
< dZded< dZded< e	e
dZded< e Zded< dd fddZddddZeddddZedddd Zd'ddd!ddd"d#d$Zeddd%d&Z  ZS )(Mlflowa  MLflow LLM service.

    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.llms import Mlflow

            completions = Mlflow(
                target_uri="http://localhost:5000",
                endpoint="test",
                temperature=0.1,
            )
    strendpoint
target_urig        floattemperature   intnNzOptional[List[str]]stopzOptional[int]
max_tokens)default_factoryzDict[str, Any]extra_paramsr   _client)kwargsc              
     sd   t  jf | |   zddlm} || j| _W n, tk
r^ } ztd|W 5 d }~X Y nX d S )Nr   )get_deploy_clientzeFailed to create the client. Please run `pip install mlflow[genai]` to install required dependencies.)super__init___validate_uriZmlflow.deploymentsr   r   r   ImportError)selfr   r   e	__class__ C/tmp/pip-unpacked-wheel-9gdii04g/langchain_community/llms/mlflow.pyr   /   s    zMlflow.__init__None)returnc                 C  sD   | j dkrd S dddg}t| j j|kr@td| j  d| dd S )NZ
databrickshttphttpszInvalid target URI: z. The scheme must be one of .)r   r   scheme
ValueError)r!   allowedr%   r%   r&   r   =   s    

zMlflow._validate_uric                 C  s"   | j | j| j| j| j| j| jdS )Nr   r   r   r   r   r   r   r/   r!   r%   r%   r&   _default_paramsG   s    zMlflow._default_paramszMapping[str, Any]c                 C  s   | j S )N)r1   r0   r%   r%   r&   _identifying_paramsS   s    zMlflow._identifying_paramsz"Optional[CallbackManagerForLLMRun])promptr   run_managerr   r(   c                 K  sd   || j | jd| j|}| jp | }r.||d< | jd k	rB| j|d< | jj| j|d}|d d d S )N)r3   r   r   r   r   )r   inputschoicesr   text)r   r   r   r   r   r   Zpredictr   )r!   r3   r   r4   r   datarespr%   r%   r&   _callW   s    

zMlflow._callc                 C  s   dS )NZmlflowr%   r0   r%   r%   r&   	_llm_typem   s    zMlflow._llm_type)NN)__name__
__module____qualname____doc____annotations__r   r   r   r   r   dictr   r   r   r   r   propertyr1   r2   r:   r;   __classcell__r%   r%   r#   r&   r      s(   

  r   N)
__future__r   typingr   r   r   r   r   urllib.parser   Zlangchain_core.callbacksr	   Zlangchain_core.language_modelsr
   Zlangchain_core.pydantic_v1r   r   r   r%   r%   r%   r&   <module>   s   