o
    ZhU                     @  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( fddZd)ddZed*ddZed+dd Z		d,d-d$d%Ze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nNOptional[List[str]]stopzOptional[int]
max_tokens)default_factoryDict[str, Any]extra_paramsr   _clientkwargsc              
     s\   t  jdi | |   zddlm} || j| _W d S  ty- } ztd|d }~ww )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__r   V/var/www/html/lang_env/lib/python3.10/site-packages/langchain_community/llms/mlflow.pyr!   /   s   zMlflow.__init__return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Mlflow._validate_uric                 C  s"   | j | j| j| j| j| j| jdS )Nr   r   r   r   r   r   r   r2   r$   r   r   r(   _default_paramsG   s   zMlflow._default_paramsMapping[str, Any]c                 C  s   | j S )N)r4   r3   r   r   r(   _identifying_paramsS   s   zMlflow._identifying_paramspromptrun_manager"Optional[CallbackManagerForLLMRun]c                 K  sf   || j | jd| j|}| jp| }r||d< | jd ur"| j|d< | jj| j|d}|d d d S )N)r7   r   r   r   r   )r   Zinputschoicesr   text)r   r   r   r   r   r   Zpredictr   )r$   r7   r   r8   r   datarespr   r   r(   _callW   s   

zMlflow._callc                 C  s   dS )NZmlflowr   r3   r   r   r(   	_llm_typem   s   zMlflow._llm_type)r   r   )r)   r*   )r)   r   )r)   r5   )NN)
r7   r   r   r   r8   r9   r   r   r)   r   )r)   r   )__name__
__module____qualname____doc____annotations__r   r   r   r   r   dictr   r   r   r!   r"   propertyr4   r6   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pydanticr   r   r   r   r   r   r(   <module>   s    