§
    šŠtj—  ã                   ó|   — d dl Z d dlmZmZ d dlZd dlmZ d dlmZ  e j	        e
¦  «        Z G d„ dee¦  «        ZdS )é    N)ÚListÚOptional)Ú
Embeddings)Ú	BaseModelc                   ó¬   — e Zd ZU dZdZeed<   	 dZee	         ed<   	 dede
e         fd„Zd	e
e         de
e
e                  fd
„Zdede
e         fd„ZdS )ÚLlamafileEmbeddingsaä  Llamafile lets you distribute and run large language models with a
    single file.

    To get started, see: https://github.com/Mozilla-Ocho/llamafile

    To use this class, you will need to first:

    1. Download a llamafile.
    2. Make the downloaded file executable: `chmod +x path/to/model.llamafile`
    3. Start the llamafile in server mode with embeddings enabled:

        `./path/to/model.llamafile --server --nobrowser --embedding`

    Example:
        .. code-block:: python

            from langchain_community.embeddings import LlamafileEmbeddings
            embedder = LlamafileEmbeddings()
            doc_embeddings = embedder.embed_documents(
                [
                    "Alpha is the first letter of the Greek alphabet",
                    "Beta is the second letter of the Greek alphabet",
                ]
            )
            query_embedding = embedder.embed_query(
                "What is the second letter of the Greek alphabet"
            )

    zhttp://localhost:8080Úbase_urlNÚrequest_timeoutÚtextÚreturnc                 ó¦  — 	 t          j        | j        › d�ddid|i| j        ¬¦  «        }n@# t           j        j        $ r) t           j                             d| j        › d�¦  «        ‚w xY w|                     ¦   «          |                     ¦   «         }d|vrt          d	¦  «        ‚|d         }t          |¦  «        d
k    rt          d¦  «        ‚|S )Nz
/embeddingzContent-Typezapplication/jsonÚcontent)ÚurlÚheadersÚjsonÚtimeoutzTCould not connect to Llamafile server. Please make sure that a server is running at ú.Ú	embeddingzPUnexpected output from /embedding endpoint, output dict missing 'embedding' key.g        z^Embedding sums to 0, did you start the llamafile server with the `--embedding` option enabled?)ÚrequestsÚpostr	   r
   Ú
exceptionsÚConnectionErrorÚraise_for_statusr   ÚKeyErrorÚsumÚ
ValueError)Úselfr   ÚresponseÚcontentsr   s        úf/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/langchain_community/embeddings/llamafile.pyÚ_embedzLlamafileEmbeddings._embed0   s(  € ð	Ý”}Ø”}Ð0Ð0Ð0à"Ð$6ðð ˜tðð Ô,ð	ñ 	ô 	ˆHˆHøõ Ô"Ô2ð 	ð 	ð 	ÝÔ%×5Ò5ð@Ø/3¬}ð@ð @ð @ñô ð ð	øøøð 	×!Ò!Ñ#Ô#Ð#à—=’=‘?”?ˆØ˜hÐ&Ð&Ýð+ñô ð ð
 ˜[Ô)ˆ	õ ˆy‰>Œ>˜SÒ Ð Ýð4ñô ð ð
 Ðs	   ‚), ¬=A)Útextsc                 ód   — g }|D ]*}|                      |                      |¦  «        ¦  «         Œ+|S )a6  Embed documents using a llamafile server running at `self.base_url`.
        llamafile server should be started in a separate process before invoking
        this method.

        Args:
            texts: The list of texts to embed.

        Returns:
            List of embeddings, one for each text.
        )Úappendr!   )r   r"   Údoc_embeddingsr   s       r    Úembed_documentsz#LlamafileEmbeddings.embed_documents\   sA   € ð ˆØð 	5ð 	5ˆDØ×!Ò! $§+¢+¨dÑ"3Ô"3Ñ4Ô4Ð4Ð4ØÐó    c                 ó,   — |                       |¦  «        S )a  Embed a query using a llamafile server running at `self.base_url`.
        llamafile server should be started in a separate process before invoking
        this method.

        Args:
            text: The text to embed.

        Returns:
            Embeddings for the text.
        )r!   )r   r   s     r    Úembed_queryzLlamafileEmbeddings.embed_queryl   s   € ð �{Š{˜4Ñ Ô Ð r'   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r	   ÚstrÚ__annotations__r
   r   Úintr   Úfloatr!   r&   r)   © r'   r    r   r      sÈ   € € € € € € ðð ð< ,€HˆcÐ+Ð+Ñ+Ø;à%)€O�X˜c”]Ð)Ð)Ñ)Ø%ð*˜3ð * 4¨¤;ð *ð *ð *ð *ðX T¨#¤Yð °4¸¸U¼Ô3Dð ð ð ð ð ! ð !¨¨U¬ð !ð !ð !ð !ð !ð !r'   r   )ÚloggingÚtypingr   r   r   Úlangchain_core.embeddingsr   Úpydanticr   Ú	getLoggerr*   Úloggerr   r2   r'   r    ú<module>r9      s¥   ðØ €€€Ø !Ð !Ð !Ð !Ð !Ð !Ð !Ð !à €€€Ø 0Ð 0Ð 0Ð 0Ð 0Ð 0Ø Ð Ð Ð Ð Ð à	ˆÔ	˜8Ñ	$Ô	$€ðl!ð l!ð l!ð l!ð l!˜) Zñ l!ô l!ð l!ð l!ð l!r'   