Ë
    µŒj—  ã                   óx   — 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y)é    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y)Ú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                  ¬«      }|j                  «        |j                  «       }d|vrt        d	«      ‚|d   }t        |«      d
k(  rt        d«      ‚|S # t         j                  j
                  $ r. t         j                  j                  d| j                  › d�«      ‚w xY w)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        úr/var/www/html/Fitness-lenito-AI-main/venv/lib/python3.12/site-packages/langchain_community/embeddings/llamafile.pyÚ_embedzLlamafileEmbeddings._embed0   sø   € ð	Ü—}‘}Ø—}‘}�o ZÐ0à"Ð$6ðð ˜tðð ×,Ñ,ô	ˆHð" 	×!Ñ!Ô#à—=‘=“?ˆØ˜hÑ&Üð+óð ð
 ˜[Ñ)ˆ	ô ˆy‹>˜SÒ Üð4óð ð
 Ðøô= ×"Ñ"×2Ñ2ò 	Ü×%Ñ%×5Ñ5ð/Ø/3¯}©}¨o¸Qð@óð ð	ús   ‚4B ÂACÚtextsc                 óX   — g }|D ]"  }|j                  | j                  |«      «       Œ$ |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\   s0   € ð ˆÛˆDØ×!Ñ! $§+¡+¨dÓ"3Õ4ð àÐó    c                 ó$   — | j                  |«      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      sv   … ñð< ,€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      s6   ðÛ ß !ã Ý 0Ý à	ˆ×	Ñ	˜8Ó	$€ôl!˜) Zõ l!r'   