§
    æ˜ºhç  ã                   óF   — d Z ddlmZmZmZ ddlmZ  G d„ de¦  «        ZdS )z+Wrapper around Xinference embedding models.é    )ÚAnyÚListÚOptional)Ú
Embeddingsc                   óÔ   ‡ — e Zd ZU dZeed<   ee         ed<   	 ee         ed<   	 	 ddee         dee         fˆ fd„Zde	e         de	e	e
                  fd	„Zd
ede	e
         fd„Zˆ xZS )ÚXinferenceEmbeddingsa  Xinference embedding models.

    To use, you should have the xinference library installed:

    .. code-block:: bash

        pip install xinference

    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 Embedding with LangChain.

    Example:

    .. code-block:: python

        from langchain_community.embeddings import XinferenceEmbeddings

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

    ÚclientÚ
server_urlÚ	model_uidNc                 ó  •— 	 ddl m} n"# t          $ r}t          d¦  «        |‚d }~ww xY wt          ¦   «                              ¦   «          |€t          d¦  «        ‚|€t          d¦  «        ‚|| _        || _         ||¦  «        | _        d S )Nr   )ÚRESTfulClientz`Could not import RESTfulClient from xinference. Please install it with `pip install xinference`.zPlease provide server URLzPlease provide the model UID)	Úxinference.clientr   ÚImportErrorÚsuperÚ__init__Ú
ValueErrorr
   r   r	   )Úselfr
   r   r   ÚeÚ	__class__s        €úq/var/www/html/services/rag-service/venv/lib/python3.11/site-packages/langchain_community/embeddings/xinference.pyr   zXinferenceEmbeddings.__init__F   s½   ø€ ð	Ø7Ð7Ð7Ð7Ð7Ð7Ð7øÝð 	ð 	ð 	Ýð2ñô ð ðøøøøð	øøøõ 	‰Œ×ÒÑÔÐàÐÝÐ8Ñ9Ô9Ð9àÐÝÐ;Ñ<Ô<Ð<à$ˆŒà"ˆŒà#�m JÑ/Ô/ˆŒˆˆs   ƒ
 Š
)”$¤)ÚtextsÚreturnc                 óv   ‡— | j                              | j        ¦  «        Šˆfd„|D ¦   «         }d„ |D ¦   «         S )zµEmbed a list of documents using Xinference.
        Args:
            texts: The list of texts to embed.
        Returns:
            List of embeddings, one for each text.
        c                 ó^   •— g | ])}‰                      |¦  «        d          d         d         ‘Œ*S )Údatar   Ú	embedding)Úcreate_embedding)Ú.0ÚtextÚmodels     €r   ú
<listcomp>z8XinferenceEmbeddings.embed_documents.<locals>.<listcomp>i   sC   ø€ ð 
ð 
ð 
ØEIˆE×"Ò" 4Ñ(Ô(¨Ô0°Ô3°KÔ@ð
ð 
ð 
ó    c                 óR   — g | ]$}t          t          t          |¦  «        ¦  «        ‘Œ%S © )ÚlistÚmapÚfloat)r   r   s     r   r!   z8XinferenceEmbeddings.embed_documents.<locals>.<listcomp>l   s(   € Ð8Ð8Ð8¨••S� ‘]”]Ñ#Ô#Ð8Ð8Ð8r"   )r	   Ú	get_modelr   )r   r   Ú
embeddingsr    s      @r   Úembed_documentsz$XinferenceEmbeddings.embed_documents_   sZ   ø€ ð ”×%Ò% d¤nÑ5Ô5ˆð
ð 
ð 
ð 
ØMRð
ñ 
ô 
ˆ
ð 9Ð8¨ZÐ8Ñ8Ô8Ð8r"   r   c                 óÖ   — | j                              | j        ¦  «        }|                     |¦  «        }|d         d         d         }t	          t          t          |¦  «        ¦  «        S )zžEmbed a query of documents using Xinference.
        Args:
            text: The text to embed.
        Returns:
            Embeddings for the text.
        r   r   r   )r	   r(   r   r   r%   r&   r'   )r   r   r    Úembedding_resr   s        r   Úembed_queryz XinferenceEmbeddings.embed_queryn   sZ   € ð ”×%Ò% d¤nÑ5Ô5ˆà×.Ò.¨tÑ4Ô4ˆà! &Ô)¨!Ô,¨[Ô9ˆ	å•C�˜yÑ)Ô)Ñ*Ô*Ð*r"   )NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú__annotations__r   Ústrr   r   r'   r*   r-   Ú__classcell__)r   s   @r   r   r      sô   ø€ € € € € € ð5ð 5ðn €K€K�KØ˜”ÐÐÑØ&Ø˜Œ}ÐÐÑØ#ð LPð0ð 0Ø" 3œ-ð0Ø;CÀC¼=ð0ð 0ð 0ð 0ð 0ð 0ð29 T¨#¤Yð 9°4¸¸U¼Ô3Dð 9ð 9ð 9ð 9ð+ ð +¨¨U¬ð +ð +ð +ð +ð +ð +ð +ð +r"   r   N)r1   Útypingr   r   r   Úlangchain_core.embeddingsr   r   r$   r"   r   ú<module>r7      sy   ðØ 1Ð 1Ø &Ð &Ð &Ð &Ð &Ð &Ð &Ð &Ð &Ð &à 0Ð 0Ð 0Ð 0Ð 0Ð 0ðu+ð u+ð u+ð u+ð u+˜:ñ u+ô u+ð u+ð u+ð u+r"   