§
    æ˜ºhW  ã                   ó~   — d dl mZmZmZmZmZ d dlmZ d dlm	Z	 d dl
mZmZ d dlmZ d dlmZ  G d„ de	¦  «        Zd	S )
é    )ÚAnyÚDictÚListÚMappingÚOptional)ÚCallbackManagerForLLMRun)ÚLLM)ÚExtraÚroot_validator©Úget_from_dict_or_env)Úenforce_stop_tokensc                   óT  — e Zd ZU dZdZee         ed<   	 dZee	         ed<   	 dZ
ee         ed<   	 dZeed<   	  G d„ d	¦  «        Z ed
¬¦  «        dedefd„¦   «         Zede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S )ÚOctoAIEndpointa¡  OctoAI LLM Endpoints.

    OctoAIEndpoint is a class to interact with OctoAI
     Compute Service large language model endpoints.

    To use, you should have the ``octoai`` python package installed, and the
    environment variable ``OCTOAI_API_TOKEN`` set with your API token, or pass
    it as a named parameter to the constructor.

    Example:
        .. code-block:: python

            from langchain_community.llms.octoai_endpoint  import OctoAIEndpoint
            OctoAIEndpoint(
                octoai_api_token="octoai-api-key",
                endpoint_url="https://mpt-7b-demo-f1kzsig6xes9.octoai.run/generate",
                model_kwargs={
                    "max_new_tokens": 200,
                    "temperature": 0.75,
                    "top_p": 0.95,
                    "repetition_penalty": 1,
                    "seed": None,
                    "stop": [],
                },
            )

            from langchain_community.llms.octoai_endpoint  import OctoAIEndpoint
            OctoAIEndpoint(
                octoai_api_token="octoai-api-key",
                endpoint_url="https://llama-2-7b-chat-demo-kk0powt97tmb.octoai.run/v1/chat/completions",
                model_kwargs={
                    "model": "llama-2-7b-chat",
                    "messages": [
                        {
                            "role": "system",
                            "content": "Below is an instruction that describes a task.
                                Write a response that completes the request."
                        }
                    ],
                    "stream": False,
                    "max_tokens": 256
                }
            )

    NÚendpoint_urlÚmodel_kwargsÚoctoai_api_tokenFÚ	streamingc                   ó    — e Zd ZdZej        ZdS )úOctoAIEndpoint.Configz'Configuration for this pydantic object.N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r
   ÚforbidÚextra© ó    úp/var/www/html/services/rag-service/venv/lib/python3.11/site-packages/langchain_community/llms/octoai_endpoint.pyÚConfigr   F   s   € € € € € Ø5Ð5à”ˆˆˆr   r    T)Úallow_reuseÚvaluesÚreturnc                 óZ   — t          |dd¦  «        }t          |dd¦  «        |d<   ||d<   |S )z?Validate that api key and python package exists in environment.r   ÚOCTOAI_API_TOKENr   ÚENDPOINT_URLr   )Úclsr"   r   s      r   Úvalidate_environmentz#OctoAIEndpoint.validate_environmentK   sL   € õ 0ØÐ&Ð(:ñ
ô 
Ðõ "6Ø�N Nñ"
ô "
ˆˆ~Ñð &6ˆÐ!Ñ"Øˆr   c                 ó2   — | j         pi }i d| j        i¥d|i¥S )zGet the identifying parameters.r   r   )r   r   )ÚselfÚ_model_kwargss     r   Ú_identifying_paramsz"OctoAIEndpoint._identifying_paramsX   s8   € ð Ô)Ð/¨Rˆð
Ø˜tÔ0Ð1ð
à˜}Ð-ð
ð 	
r   c                 ó   — dS )zReturn type of llm.Úoctoai_endpointr   )r*   s    r   Ú	_llm_typezOctoAIEndpoint._llm_typea   s
   € ð !Ð r   ÚpromptÚstopÚrun_managerÚkwargsc                 ó  — | j         pi }	 ddlm} |                     | j        ¬¦  «        }d|v r}|}|d                              d|dœ¦  «         |                     | j        |¦  «        }	|	                     d¦  «        d                              d	¦  «                             d
¦  «        }
n(||dœ}|                     | j        |¦  «        }|d         }
n%# t          $ r}t          d|› �¦  «        |‚d}~ww xY w|�t          |
|¦  «        }
|
S )zÿCall out to OctoAI's inference endpoint.

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

        Returns:
            The string generated by the model.

        r   )Úclient)ÚtokenÚmodelÚmessagesÚuser)ÚroleÚcontentÚchoicesÚmessager;   )ÚinputsÚ
parametersÚgenerated_textz(Error raised by the inference endpoint: N)r   Úoctoair5   ÚClientr   ÚappendÚinferr   ÚgetÚ	ExceptionÚ
ValueErrorr   )r*   r0   r1   r2   r3   r+   r5   Úoctoai_clientÚparameter_payloadÚoutputÚtextÚ	resp_jsonÚes                r   Ú_callzOctoAIEndpoint._callf   sW  € ð" Ô)Ð/¨Rˆð	Tà%Ð%Ð%Ð%Ð%Ð%à"ŸMšM°Ô0E˜MÑFÔFˆMà˜-Ð'Ð'Ø$1Ð!Ø! *Ô-×4Ò4Ø#°Ð7Ð7ñô ð ð '×,Ò,¨TÔ->Ð@QÑRÔR�Ø—z’z )Ñ,Ô,¨QÔ/×3Ò3°IÑ>Ô>×BÒBÀ9ÑMÔM��ð 06À]Ð$SÐ$SÐ!ð *×/Ò/°Ô0AÐCTÑUÔU�	Ø Ð!1Ô2�øøåð 	Tð 	Tð 	TåÐKÈÐKÐKÑLÔLÐRSÐSøøøøð	Tøøøð Ðå& t¨TÑ2Ô2ˆDàˆs   ‹C
C Ã
C8Ã C3Ã3C8)NN)r   r   r   r   r   r   ÚstrÚ__annotations__r   Údictr   r   Úboolr    r   r   r(   Úpropertyr   r   r,   r/   r   r   rN   r   r   r   r   r      s—  € € € € € € ð,ð ,ð\ #'€L�(˜3”-Ð&Ð&Ñ&Øà#'€L�(˜4”.Ð'Ð'Ñ'Ø1à&*Ð�h˜s”mÐ*Ð*Ñ*Øà€IˆtÐÐÑØ?ðð ð ð ð ñ ô ð ð
 €^ Ð%Ñ%Ô%ð
¨$ð 
°4ð 
ð 
ð 
ñ &Ô%ð
ð ð
 W¨S°#¨XÔ%6ð 
ð 
ð 
ñ „Xð
ð ð!˜3ð !ð !ð !ñ „Xð!ð %)Ø:>ð	1ð 1àð1ð �t˜C”yÔ!ð1ð Ð6Ô7ð	1ð
 ð1ð 
ð1ð 1ð 1ð 1ð 1ð 1r   r   N)Útypingr   r   r   r   r   Úlangchain_core.callbacksr   Ú#langchain_core.language_models.llmsr	   Úlangchain_core.pydantic_v1r
   r   Úlangchain_core.utilsr   Úlangchain_community.llms.utilsr   r   r   r   r   ú<module>rZ      sÍ   ðØ 5Ð 5Ð 5Ð 5Ð 5Ð 5Ð 5Ð 5Ð 5Ð 5Ð 5Ð 5Ð 5Ð 5à =Ð =Ð =Ð =Ð =Ð =Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3Ø <Ð <Ð <Ð <Ð <Ð <Ð <Ð <Ø 5Ð 5Ð 5Ð 5Ð 5Ð 5à >Ð >Ð >Ð >Ð >Ð >ðLð Lð Lð Lð L�Sñ Lô Lð Lð Lð Lr   