Ë
    µŒjõ  ã                   ó>   — d Z ddlmZmZmZ ddlmZ  G d„ de«      Zy)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 )ÚXinferenceEmbeddingsaq  Xinference embedding models.

    To use, you should have the xinference library installed:

    .. code-block:: bash

        pip install xinference

    If you're simply using the services provided by Xinference, you can utilize the xinference_client package:

    .. code-block:: bash

        pip install xinference_client

    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

        If you're simply using the services provided by Xinference, you can utilize the xinference_client package:

        .. code-block:: bash

            pip install xinference_client

        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_uidc                 ó  •— 	 ddl m} t        ‰| �  «        |€t        d«      ‚|€t        d«      ‚|| _        || _         ||«      | _	        y # t        $ r( 	 ddlm} n# t        $ r}t        d«      |‚d }~ww xY wY Œtw xY w)Nr   )ÚRESTfulClientzƒCould not import RESTfulClient from xinference. Please install it with `pip install xinference` or `pip install xinference_client`.zPlease provide server URLzPlease provide the model UID)
Úxinference.clientr   ÚImportErrorÚxinference_clientÚsuperÚ__init__Ú
ValueErrorr
   r   r	   )Úselfr
   r   r   ÚeÚ	__class__s        €ús/var/www/html/Fitness-lenito-AI-main/venv/lib/python3.12/site-packages/langchain_community/embeddings/xinference.pyr   zXinferenceEmbeddings.__init__R   sœ   ø€ ð		Ý7ô 	‰ÑÔàÐÜÐ8Ó9Ð9àÐÜÐ;Ó<Ð<à$ˆŒà"ˆŒá# JÓ/ˆ�øô+ ò 	ðÞ;øÜò Ü!ðYóð ðûðúñ <ð	ús5   ƒA Á	A>ÁAÁA>Á	A8Á'A3Á3A8Á8A>Á=A>ÚtextsÚreturnc           	      óü   — | j                   j                  | j                  «      }|D �cg c]  }|j                  |«      d   d   d   ‘Œ }}|D �cg c]  }t	        t        t        |«      «      ‘Œ c}S c c}w c c}w )zµEmbed a list of documents using Xinference.
        Args:
            texts: The list of texts to embed.
        Returns:
            List of embeddings, one for each text.
        Údatar   Ú	embedding©r	   Ú	get_modelr   Úcreate_embeddingÚlistÚmapÚfloat)r   r   ÚmodelÚtextÚ
embeddingsr   s         r   Úembed_documentsz$XinferenceEmbeddings.embed_documentsn   s‚   € ð —‘×%Ñ% d§n¡nÓ5ˆñ NSó
ÙMRÀTˆE×"Ñ" 4Ó(¨Ñ0°Ñ3°KÓ@ÈUð 	ð 
ñ .8Ó8©Z¨””Sœ “]Õ#¨ZÑ8Ð8ùò
ùò 9s   ª!A4Á A9r$   c                 ó¶   — | j                   j                  | 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#   Úembedding_resr   s        r   Úembed_queryz XinferenceEmbeddings.embed_query}   sR   € ð —‘×%Ñ% d§n¡nÓ5ˆà×.Ñ.¨tÓ4ˆà! &Ñ)¨!Ñ,¨[Ñ9ˆ	ä”Cœ˜yÓ)Ó*Ð*ó    )NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú__annotations__r   Ústrr   r   r"   r&   r)   Ú__classcell__)r   s   @r   r   r      s†   ø… ñAðF ƒKØ˜‘ÓØ&Ø˜‰}ÓØ#ð LPñ0Ø" 3™-ð0Ø;CÀC¹=õ0ð89 T¨#¡Yð 9°4¸¸U¹Ñ3Dó 9ð+ ð +¨¨U©÷ +r*   r   N)r.   Útypingr   r   r   Úlangchain_core.embeddingsr   r   © r*   r   Ú<module>r5      s   ðÙ 1ç &Ñ &å 0ôC+˜:õ C+r*   