§
    æ˜ºhµ  ã                   ó‚   — d dl mZmZmZmZmZmZmZmZ d dl	m
Z
 d dlmZ erd dlmZmZ d dlmZ  G d„ de¦  «        ZdS )	é    )ÚTYPE_CHECKINGÚAnyÚDictÚ	GeneratorÚListÚMappingÚOptionalÚUnion)ÚCallbackManagerForLLMRun)ÚLLM)ÚRESTfulChatModelHandleÚRESTfulGenerateModelHandle)ÚLlamaCppGenerateConfigc                   óŒ  ‡ — e Zd ZU dZeed<   ee         ed<   	 ee         ed<   	 eeef         ed<   	 	 	 ddee         dee         defˆ fd„Z	e
defd	„¦   «         Ze
deeef         fd
„¦   «         Z	 	 ddedeee                  dee         dedef
d„Z	 	 dded         dedee         ded         deeddf         f
d„Zˆ xZS )Ú
Xinferencea  `Xinference` large-scale model inference service.

    To use, you should have the xinference library installed:

    .. code-block:: bash

       pip install "xinference[all]"

    Check out: https://github.com/xorbitsai/inference
    To run, you need to start a Xinference supervisor on one server and Xinference workers on the other servers

    Example:
        To start a local instance of Xinference, run

        .. code-block:: bash

           $ xinference

        You can also deploy Xinference in a distributed cluster. Here are the steps:

        Starting the supervisor:

        .. code-block:: bash

           $ xinference-supervisor

        Starting the worker:

        .. code-block:: bash

           $ xinference-worker

    Then, launch a model using command line interface (CLI).

    Example:

    .. code-block:: bash

       $ xinference launch -n orca -s 3 -q q4_0

    It will return a model UID. Then, you can use Xinference with LangChain.

    Example:

    .. code-block:: python

        from langchain_community.llms import Xinference

        llm = Xinference(
            server_url="http://0.0.0.0:9997",
            model_uid = {model_uid} # replace model_uid with the model UID return from launching the model
        )

        llm(
            prompt="Q: where can we visit in the capital of France? A:",
            generate_config={"max_tokens": 1024, "stream": True},
        )

    To view all the supported builtin models, run:

    .. code-block:: bash

        $ xinference list --all

    ÚclientÚ
server_urlÚ	model_uidÚmodel_kwargsNc                 ó  •— 	 ddl m} n"# t          $ r}t          d¦  «        |‚d }~ww xY w|pi } t          ¦   «         j        di |||dœ¤Ž | j        €t          d¦  «        ‚| j        €t          d¦  «        ‚ ||¦  «        | _        d S )Nr   )ÚRESTfulClientz`Could not import RESTfulClient from xinference. Please install it with `pip install xinference`.©r   r   r   zPlease provide server URLzPlease provide the model UID© )	Úxinference.clientr   ÚImportErrorÚsuperÚ__init__r   Ú
ValueErrorr   r   )Úselfr   r   r   r   ÚeÚ	__class__s         €úk/var/www/html/services/rag-service/venv/lib/python3.11/site-packages/langchain_community/llms/xinference.pyr   zXinference.__init__V   sá   ø€ ð	Ø7Ð7Ð7Ð7Ð7Ð7Ð7øÝð 	ð 	ð 	Ýð2ñô ð ðøøøøð	øøøð $Ð) rˆà�‰ŒÔð 	
ð 	
à(Ø&Ø ,ðð ð	
ð 	
ð 	
ð Œ?Ð"ÝÐ8Ñ9Ô9Ð9àŒ>Ð!ÝÐ;Ñ<Ô<Ð<à#�m JÑ/Ô/ˆŒˆˆs   ƒ
 Š
)”$¤)Úreturnc                 ó   — dS )zReturn type of llm.Ú
xinferencer   ©r   s    r"   Ú	_llm_typezXinference._llm_typev   s	   € ð ˆ|ó    c                 ó<   — i d| j         i¥d| j        i¥d| j        i¥S )zGet the identifying parameters.r   r   r   r   r&   s    r"   Ú_identifying_paramszXinference._identifying_params{   s<   € ð
Ø˜Tœ_Ð-ð
à˜DœNÐ+ð
ð ˜tÔ0Ð1ð
ð 	
r(   ÚpromptÚstopÚrun_managerÚkwargsc                 ó^  — | j                              | j        ¦  «        }|                     di ¦  «        }i | j        ¥|¥}|r||d<   |r:|                     d¦  «        r%d}|                      ||||¬¦  «        D ]}||z  }Œ|S |                     ||¬¦  «        }	|	d         d         d	         S )
aq  Call the xinference model and return the output.

        Args:
            prompt: The prompt to use for generation.
            stop: Optional list of stop words to use when generating.
            generate_config: Optional dictionary for the configuration used for
                generation.

        Returns:
            The generated string by the model.
        Úgenerate_configr,   ÚstreamÚ )Úmodelr+   r-   r0   ©r+   r0   Úchoicesr   Útext)r   Ú	get_modelr   Úgetr   Ú_stream_generateÚgenerate)
r   r+   r,   r-   r.   r3   r0   Úcombined_text_outputÚtokenÚ
completions
             r"   Ú_callzXinference._call„   sé   € ð$ ”×%Ò% d¤nÑ5Ô5ˆà4:·J²JÐ?PÐRTÑ4UÔ4UˆàB˜TÔ.ÐB°/ÐBˆàð 	+Ø&*ˆO˜FÑ#àð 	4˜×2Ò2°8Ñ<Ô<ð 	4Ø#%Ð Ø×.Ò.ØØØ'Ø /ð	 /ñ ô ð .ð .�ð %¨Ñ-Ð$Ð$Ø'Ð'ð Ÿš¨vÀ˜ÑWÔWˆJØ˜iÔ(¨Ô+¨FÔ3Ð3r(   r3   )r   r   r0   r   c              #   ór  K  — |                      ||¬¦  «        }|D ]š}t          |t          ¦  «        rƒ|                     dg ¦  «        }|rk|d         }t          |t          ¦  «        rN|                     dd¦  «        }	|                     d¦  «        }
|r|                     |	| j        |
¬¦  «         |	V — Œ›dS )	a^  
        Args:
            prompt: The prompt to use for generation.
            model: The model used for generation.
            stop: Optional list of stop words to use when generating.
            generate_config: Optional dictionary for the configuration used for
                generation.

        Yields:
            A string token.
        r4   r5   r   r6   r2   Úlogprobs)r<   ÚverboseÚ	log_probsN)r:   Ú
isinstanceÚdictr8   Úon_llm_new_tokenrA   )r   r3   r+   r-   r0   Ústreaming_responseÚchunkr5   Úchoicer<   rB   s              r"   r9   zXinference._stream_generate®   sç   è è € ð$ #Ÿ^š^Ø¨?ð ,ñ 
ô 
Ðð (ð 	$ð 	$ˆEÝ˜%¥Ñ&Ô&ð $ØŸ)š) I¨rÑ2Ô2�Øð 	$Ø$ QœZ�FÝ! &­$Ñ/Ô/ð $Ø &§
¢
¨6°2Ñ 6Ô 6˜Ø$*§J¢J¨zÑ$:Ô$:˜	Ø&ð Ø'×8Ò8Ø&+°T´\ÈYð 9ñ ô ð ð $˜˜˜øð	$ð 	$r(   )NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú__annotations__r	   Ústrr   r   Úpropertyr'   r   r*   r   r   r>   r
   r   r9   Ú__classcell__)r!   s   @r"   r   r      sì  ø€ € € € € € ð@ð @ðD €K€K�KØ˜”ÐÐÑØ&Ø˜Œ}ÐÐÑØ#Ø�s˜C�x”.Ð Ð Ñ Ø:ð %)Ø#'ð0ð 0à˜S”Mð0ð ˜C”=ð0ð ð	0ð 0ð 0ð 0ð 0ð 0ð@ ð˜3ð ð ð ñ „Xðð ð
 W¨S°#¨XÔ%6ð 
ð 
ð 
ñ „Xð
ð %)Ø:>ð	(4ð (4àð(4ð �t˜C”yÔ!ð(4ð Ð6Ô7ð	(4ð
 ð(4ð 
ð(4ð (4ð (4ð (4ð\ ;?Ø>Bð!$ð !$àÐKÔLð!$ð ð!$ð Ð6Ô7ð	!$ð
 "Ð":Ô;ð!$ð 
�3˜˜d�?Ô	#ð!$ð !$ð !$ð !$ð !$ð !$ð !$ð !$r(   r   N)Útypingr   r   r   r   r   r   r	   r
   Úlangchain_core.callbacksr   Ú#langchain_core.language_models.llmsr   r   r   r   Úxinference.model.llm.corer   r   r   r(   r"   ú<module>rU      sÖ   ðØ VÐ VÐ VÐ VÐ VÐ VÐ VÐ VÐ VÐ VÐ VÐ VÐ VÐ VÐ VÐ VÐ VÐ VÐ VÐ Và =Ð =Ð =Ð =Ð =Ð =Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3àð AØTÐTÐTÐTÐTÐTÐTÐTØ@Ð@Ð@Ð@Ð@Ð@ðD$ð D$ð D$ð D$ð D$�ñ D$ô D$ð D$ð D$ð D$r(   