§
    šŠtj©  ã            
       óŒ   — d dl mZmZmZ d dlmZ d dlmZ d dlm	Z	 dedededeee
                  fd	„Z G d
„ de	e¦  «        ZdS )é    )ÚAnyÚCallableÚList)Ú
Embeddings)Ú
ConfigDict)ÚSelfHostedPipelineÚpipelineÚargsÚkwargsÚreturnc                 ó   —  | |i |¤ŽS )z©Inference function to send to the remote hardware.

    Accepts a sentence_transformer model_id and
    returns a list of embeddings for each document in the batch.
    © )r	   r
   r   s      úh/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/langchain_community/embeddings/self_hosted.pyÚ_embed_documentsr   	   s   € ð ˆ8�TÐ$˜VÐ$Ð$Ð$ó    c                   óœ   — e Zd ZU dZeZeed<   	 dZe	ed<   	  e
d¬¦  «        Zdee         deee                  fd	„Zd
edee         fd„ZdS )ÚSelfHostedEmbeddingsa„  Custom embedding models on self-hosted remote hardware.

    Supported hardware includes auto-launched instances on AWS, GCP, Azure,
    and Lambda, as well as servers specified
    by IP address and SSH credentials (such as on-prem, or another
    cloud like Paperspace, Coreweave, etc.).

    To use, you should have the ``runhouse`` python package installed.

    Example using a model load function:
        .. code-block:: python

            from langchain_community.embeddings import SelfHostedEmbeddings
            from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
            import runhouse as rh

            gpu = rh.cluster(name="rh-a10x", instance_type="A100:1")
            def get_pipeline():
                model_id = "facebook/bart-large"
                tokenizer = AutoTokenizer.from_pretrained(model_id)
                model = AutoModelForCausalLM.from_pretrained(model_id)
                return pipeline("feature-extraction", model=model, tokenizer=tokenizer)
            embeddings = SelfHostedEmbeddings(
                model_load_fn=get_pipeline,
                hardware=gpu
                model_reqs=["./", "torch", "transformers"],
            )
    Example passing in a pipeline path:
        .. code-block:: python

            from langchain_community.embeddings import SelfHostedHFEmbeddings
            import runhouse as rh
            from transformers import pipeline

            gpu = rh.cluster(name="rh-a10x", instance_type="A100:1")
            pipeline = pipeline(model="bert-base-uncased", task="feature-extraction")
            rh.blob(pickle.dumps(pipeline),
                path="models/pipeline.pkl").save().to(gpu, path="models")
            embeddings = SelfHostedHFEmbeddings.from_pipeline(
                pipeline="models/pipeline.pkl",
                hardware=gpu,
                model_reqs=["./", "torch", "transformers"],
            )
    Úinference_fnNÚinference_kwargsÚforbid)ÚextraÚtextsr   c                 óÊ   — t          t          d„ |¦  «        ¦  «        }|                      | j        |¦  «        }t	          |t           ¦  «        s|                     ¦   «         S |S )zÊCompute doc embeddings using a HuggingFace transformer model.

        Args:
            texts: The list of texts to embed.s

        Returns:
            List of embeddings, one for each text.
        c                 ó.   — |                       dd¦  «        S )Nú
ú )Úreplace)Úxs    r   ú<lambda>z6SelfHostedEmbeddings.embed_documents.<locals>.<lambda>R   s   €  1§9¢9¨T°3Ñ#7Ô#7€ r   )ÚlistÚmapÚclientÚpipeline_refÚ
isinstanceÚtolist)Úselfr   Ú
embeddingss      r   Úembed_documentsz$SelfHostedEmbeddings.embed_documentsI   s_   € õ •SÐ7Ð7¸Ñ?Ô?Ñ@Ô@ˆØ—[’[ Ô!2°EÑ:Ô:ˆ
Ý˜*¥dÑ+Ô+ð 	'Ø×$Ò$Ñ&Ô&Ð&ØÐr   Útextc                 óº   — |                      dd¦  «        }|                      | j        |¦  «        }t          |t          ¦  «        s|                     ¦   «         S |S )z³Compute query embeddings using a HuggingFace transformer model.

        Args:
            text: The text to embed.

        Returns:
            Embeddings for the text.
        r   r   )r   r"   r#   r$   r    r%   )r&   r)   r'   s      r   Úembed_queryz SelfHostedEmbeddings.embed_queryX   sW   € ð �|Š|˜D #Ñ&Ô&ˆØ—[’[ Ô!2°DÑ9Ô9ˆ
Ý˜*¥dÑ+Ô+ð 	'Ø×$Ò$Ñ&Ô&Ð&ØÐr   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   Ú__annotations__r   r   r   Úmodel_configr   ÚstrÚfloatr(   r+   r   r   r   r   r      s¸   € € € € € € ð+ð +ðZ .€L�(Ð-Ð-Ñ-ØNØ Ð�cÐ Ð Ñ Ø?à�:Øðñ ô €Lð T¨#¤Yð °4¸¸U¼Ô3Dð ð ð ð ð ð ¨¨U¬ð ð ð ð ð ð r   r   N)Útypingr   r   r   Úlangchain_core.embeddingsr   Úpydanticr   Ú$langchain_community.llms.self_hostedr   r3   r   r   r   r   r   ú<module>r8      sÓ   ðØ &Ð &Ð &Ð &Ð &Ð &Ð &Ð &Ð &Ð &à 0Ð 0Ð 0Ð 0Ð 0Ð 0Ø Ð Ð Ð Ð Ð à CÐ CÐ CÐ CÐ CÐ Cð%˜sð %¨3ð %¸#ð %À$ÀtÈEÄ{ÔBSð %ð %ð %ð %ðSð Sð Sð Sð SÐ-¨zñ Sô Sð Sð Sð Sr   