
    Ng                     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 )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_uidNc                 L   	 ddl m} n:# t          $ r- 	 ddlm} n"# t          $ r}t          d          |d }~ww xY wY nw xY wt	                                                       |t          d          |t          d          || _        || _         ||          | _	        d S )Nr   )RESTfulClientzCould 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        e/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/embeddings/xinference.pyr   zXinferenceEmbeddings.__init__R   s    		7777777 	 	 	;;;;;;;   !Y   <;	 	8999;<<<$"#mJ//s)   
 
AA
;6;A Atextsreturnc                 v    | j                             | j                  fd|D             }d |D             S )zEmbed 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>x   sC     
 
 
EIE""4((03K@
 
 
    c                 R    g | ]$}t          t          t          |                    %S  )listmapfloat)r   r   s     r   r"   z8XinferenceEmbeddings.embed_documents.<locals>.<listcomp>{   s(    888S]]##888r#   )r	   	get_modelr   )r   r   
embeddingsr!   s      @r   embed_documentsz$XinferenceEmbeddings.embed_documentsn   sZ     %%dn55
 
 
 
MR
 
 

 98Z8888r#   r    c                     | j                             | j                  }|                    |          }|d         d         d         }t	          t          t          |                    S )zEmbed 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_query}   sZ     %%dn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         A AF KKK&}# LP0 0"3-0;CC=0 0 0 0 0 089T#Y 94U3D 9 9 9 9+ +U + + + + + + + +r#   r   N)r2   typingr   r   r   langchain_core.embeddingsr   r   r%   r#   r   <module>r8      sy    1 1 & & & & & & & & & & 0 0 0 0 0 0C+ C+ C+ C+ C+: C+ C+ C+ C+ C+r#   