§
    šŠtjg$  ã                   óÀ   — d dl mZ d dlmZmZmZmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZmZ d dlmZ  G d„ d	ee¦  «        Z G d
„ de¦  «        Z G d„ de
¦  «        ZdS )é    )ÚEnum)ÚAnyÚIteratorÚListÚOptional)ÚCallbackManagerForLLMRun)ÚLLM)ÚGenerationChunk)Ú	BaseModelÚ
ConfigDict)Úenforce_stop_tokensc                   ó   — e Zd ZdZdZdZdS )ÚDevicez,The device to use for inference, cuda or cpuÚcudaÚcpuN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   © ó    úd/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/langchain_community/llms/titan_takeoff.pyr   r      s   € € € € € Ø6Ð6à€DØ
€C€C€Cr   r   c                   óœ   — e Zd ZU dZ ed¬¦  «        Zeed<   	 ej	        Z
eed<   	 dZeed<   	 dZee         ed	<   	 d
Zeed<   	 dZeed<   dS )ÚReaderConfigzAConfiguration for the reader to be deployed in Titan Takeoff API.r   )Úprotected_namespacesÚ
model_nameÚdeviceÚprimaryÚconsumer_groupNÚtensor_paralleli   Úmax_seq_lengthé   Úmax_batch_size)r   r   r   r   r   Úmodel_configÚstrÚ__annotations__r   r   r   r   r    r   Úintr!   r#   r   r   r   r   r      s¡   € € € € € € ØKÐKà�:Øðñ ô €Lð €O€O�OØ&à”[€FˆFÐ Ð Ñ Ø6à#€N�CÐ#Ð#Ñ#Ø5à%)€O�X˜c”]Ð)Ð)Ñ)ØIà€N�CÐÐÑØKà€N�CÐÐÑØ@Ð@r   r   c                   óV  ‡ — e Zd ZU dZdZeed<   	 dZeed<   	 dZ	eed<   	 dZ
eed	<   	 d
Zeed<   	 ddddg fdededed	edee         f
ˆ fd„Zedefd„¦   «         Z	 	 ddedeee                  dee         dedef
d„Z	 	 ddedeee                  dee         dedee         f
d„Zˆ xZS )ÚTitanTakeoffa¬  Titan Takeoff API LLMs.

    Titan Takeoff is a wrapper to interface with Takeoff Inference API for
    generative text to text language models.

    You can use this wrapper to send requests to a generative language model
    and to deploy readers with Takeoff.

    Examples:
        This is an example how to deploy a generative language model and send
        requests.

        .. code-block:: python
            # Import the TitanTakeoff class from community package
            import time
            from langchain_community.llms import TitanTakeoff

            # Specify the embedding reader you'd like to deploy
            reader_1 = {
                "model_name": "TheBloke/Llama-2-7b-Chat-AWQ",
                "device": "cuda",
                "tensor_parallel": 1,
                "consumer_group": "llama"
            }

            # For every reader you pass into models arg Takeoff will spin
            # up a reader according to the specs you provide. If you don't
            # specify the arg no models are spun up and it assumes you have
            # already done this separately.
            llm = TitanTakeoff(models=[reader_1])

            # Wait for the reader to be deployed, time needed depends on the
            # model size and your internet speed
            time.sleep(60)

            # Returns the query, ie a List[float], sent to `llama` consumer group
            # where we just spun up the Llama 7B model
            print(embed.invoke(
                "Where can I see football?", consumer_group="llama"
            ))

            # You can also send generation parameters to the model, any of the
            # following can be passed in as kwargs:
            # https://docs.titanml.co/docs/next/apis/Takeoff%20inference_REST_API/generate#request
            # for instance:
            print(embed.invoke(
                "Where can I see football?", consumer_group="llama", max_new_tokens=100
            ))
    zhttp://localhostÚbase_urli¸  Úporti¹  Ú	mgmt_portFÚ	streamingNÚclientÚmodelsc                 ó  •— t          ¦   «                              ||||¬¦  «         	 ddlm} n# t          $ r t	          d¦  «        ‚w xY w || j        | j        | j        ¬¦  «        | _        |D ]}| j         	                    |¦  «         ŒdS )a�  Initialize the Titan Takeoff language wrapper.

        Args:
            base_url (str, optional): The base URL where the Takeoff
                Inference Server is listening. Defaults to `http://localhost`.
            port (int, optional): What port is Takeoff Inference API
                listening on. Defaults to 3000.
            mgmt_port (int, optional): What port is Takeoff Management API
                listening on. Defaults to 3001.
            streaming (bool, optional): Whether you want to by default use the
                generate_stream endpoint over generate to stream responses.
                Defaults to False. In reality, this is not significantly different
                as the streamed response is buffered and returned similar to the
                non-streamed response, but the run manager is applied per token
                generated.
            models (List[ReaderConfig], optional): Any readers you'd like to
                spin up on. Defaults to [].

        Raises:
            ImportError: If you haven't installed takeoff-client, you will
            get an ImportError. To remedy run `pip install 'takeoff-client==0.4.0'`
        )r*   r+   r,   r-   r   )ÚTakeoffClientzjtakeoff-client is required for TitanTakeoff. Please install it with `pip install 'takeoff-client>=0.4.0'`.)r+   r,   N)
ÚsuperÚ__init__Útakeoff_clientr1   ÚImportErrorr*   r+   r,   r.   Úcreate_reader)	Úselfr*   r+   r,   r-   r/   r1   ÚmodelÚ	__class__s	           €r   r3   zTitanTakeoff.__init__o   s×   ø€ õ< 	‰Œ×ÒØ D°IÈð 	ñ 	
ô 	
ð 	
ð	Ø4Ð4Ð4Ð4Ð4Ð4Ð4øÝð 	ð 	ð 	ÝðPñô ð ð	øøøð
 $�mØŒM ¤	°T´^ð
ñ 
ô 
ˆŒð ð 	-ð 	-ˆEØŒK×%Ò% eÑ,Ô,Ð,Ð,ð	-ð 	-s	   ¨/ ¯A	Úreturnc                 ó   — dS )zReturn type of llm.Útitan_takeoffr   )r7   s    r   Ú	_llm_typezTitanTakeoff._llm_type�   s	   € ð ˆr   ÚpromptÚstopÚrun_managerÚkwargsc                 óÀ   — | j         r)d}|                      |||¬¦  «        D ]}||j        z  }Œ|S  | j        j        |fi |¤Ž}|d         }|�t          ||¦  «        }|S )aµ  Call out to Titan Takeoff (Pro) generate endpoint.

        Args:
            prompt: The prompt to pass into the model.
            stop: Optional list of stop words to use when generating.
            run_manager: Optional callback manager to use when streaming.

        Returns:
            The string generated by the model.

        Example:
            .. code-block:: python

                model = TitanTakeoff()

                prompt = "What is the capital of the United Kingdom?"

                # Use of model(prompt), ie `__call__` was deprecated in LangChain 0.1.7,
                # use model.invoke(prompt) instead.
                response = model.invoke(prompt)

        Ú )r>   r?   r@   Útext)r-   Ú_streamrD   r.   Úgenerater   )	r7   r>   r?   r@   rA   Útext_outputÚchunkÚresponserD   s	            r   Ú_callzTitanTakeoff._call¢   s”   € ð: Œ>ð 	ØˆKØŸšØØØ'ð &ñ ô ð *ð *�ð
 ˜uœzÑ)��ØÐà'�4”;Ô'¨Ð9Ð9°&Ð9Ð9ˆØ˜ÔˆàÐÝ& t¨TÑ2Ô2ˆDØˆr   c              +   ó.  K  —  | j         j        |fi |¤Ž}d}|D ]±}||j        z  }d|v r¡|                     d¦  «        rd}t	          |                     dd¦  «        ¦  «        dk    r.|                     dd¦  «        \  }}	|                     d¦  «        }|r3t          |¬¦  «        }
d}|r|                     |
j	        ¬¦  «         |
V — Œ²|rGt          | 
                    dd¦  «        ¬¦  «        }
|r|                     |
j	        ¬¦  «         |
V — d	S d	S )
a²  Call out to Titan Takeoff (Pro) stream endpoint.

        Args:
            prompt: The prompt to pass into the model.
            stop: Optional list of stop words to use when generating.
            run_manager: Optional callback manager to use when streaming.

        Yields:
            A dictionary like object containing a string token.

        Example:
            .. code-block:: python

                model = TitanTakeoff()

                prompt = "What is the capital of the United Kingdom?"
                response = model.stream(prompt)

                # OR

                model = TitanTakeoff(streaming=True)

                response = model.invoke(prompt)

        rC   zdata:é   é   ú
)rD   )Útokenz</s>N)r.   Úgenerate_streamÚdataÚ
startswithÚlenÚsplitÚrstripr
   Úon_llm_new_tokenrD   Úreplace)r7   r>   r?   r@   rA   rI   ÚbufferrD   ÚcontentÚ_rH   s              r   rE   zTitanTakeoff._streamÐ   s]  è è € ð@ /�4”;Ô.¨vÐ@Ð@¸Ð@Ð@ˆØˆØð 	 ð 	 ˆDØ�d”iÑˆFØ˜&Ð Ð à×$Ò$ WÑ-Ô-ð  Ø�FÝ�v—|’| G¨QÑ/Ô/Ñ0Ô0°AÒ5Ð5Ø!'§¢¨g°qÑ!9Ô!9‘J�G˜QØ$Ÿ^š^¨DÑ1Ô1�Fàð  Ý+°Ð8Ñ8Ô8�EØ�FØ"ð GØ#×4Ò4¸5¼:Ð4ÑFÔFÐFØ�K�K�Køð ð 	Ý#¨¯ª¸ÀÑ)CÔ)CÐDÑDÔDˆEØð ?Ø×,Ò,°5´:Ð,Ñ>Ô>Ð>ØˆKˆKˆKˆKˆKð		ð 	r   )NN)r   r   r   r   r*   r%   r&   r+   r'   r,   r-   Úboolr.   r   r   r   r3   Úpropertyr=   r   r   rJ   r   r
   rE   Ú__classcell__)r9   s   @r   r)   r)   -   sä  ø€ € € € € € ð0ð 0ðd '€HˆcÐ&Ð&Ñ&ØWà€Dˆ#ÐÐÑØEà€IˆsÐÐÑØPà€IˆtÐÐÑØ8à€FˆCÐÐÑØEð +ØØØØ%'ð,-ð ,-àð,-ð ð,-ð ð	,-ð
 ð,-ð �\Ô"ð,-ð ,-ð ,-ð ,-ð ,-ð ,-ð\ ð˜3ð ð ð ñ „Xðð %)Ø:>ð	,ð ,àð,ð �t˜C”yÔ!ð,ð Ð6Ô7ð	,ð
 ð,ð 
ð,ð ,ð ,ð ,ðb %)Ø:>ð	8ð 8àð8ð �t˜C”yÔ!ð8ð Ð6Ô7ð	8ð
 ð8ð 
�/Ô	"ð8ð 8ð 8ð 8ð 8ð 8ð 8ð 8r   r)   N)Úenumr   Útypingr   r   r   r   Úlangchain_core.callbacksr   Ú#langchain_core.language_models.llmsr	   Úlangchain_core.outputsr
   Úpydanticr   r   Úlangchain_community.llms.utilsr   r%   r   r   r)   r   r   r   ú<module>re      s7  ðØ Ð Ð Ð Ð Ð Ø 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0à =Ð =Ð =Ð =Ð =Ð =Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3Ø 2Ð 2Ð 2Ð 2Ð 2Ð 2Ø *Ð *Ð *Ð *Ð *Ð *Ð *Ð *à >Ð >Ð >Ð >Ð >Ð >ðð ð ð ð ˆS�$ñ ô ð ðAð Að Að Að A�9ñ Aô Að Að4[ð [ð [ð [ð [�3ñ [ô [ð [ð [ð [r   