
    7|hf                     n    d dl mZmZ d dlmZmZmZ d dlmZm	Z	 d dl
mZ d dlmZ dZdZ G d d	e      Zy
)    )AnyDict)convert_to_secret_strget_from_dict_or_envpre_init)Field	SecretStr)
BaseOpenAI)is_openai_v1zhttps://text.octoai.run/v1/zcodellama-7b-instructc                        e Zd ZU dZ	  ee      Zeed<    e e	d            Z
e	ed<    ee      Zeed<   edefd       Zedeeef   f fd	       Zedefd
       Zededefd       Z xZS )OctoAIEndpointa  OctoAI LLM Endpoints - OpenAI compatible.

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

    To use, you should have 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

            llm = OctoAIEndpoint(
                model="llama-2-13b-chat-fp16",
                max_tokens=200,
                presence_penalty=0,
                temperature=0.1,
                top_p=0.9,
            )

    defaultoctoai_api_base octoai_api_token
model_namereturnc                      y)NF )clss    g/var/www/html/test/engine/venv/lib/python3.12/site-packages/langchain_community/llms/octoai_endpoint.pyis_lc_serializablez!OctoAIEndpoint.is_lc_serializable*   s        c                     d| j                   i| j                  }t               s6|j                  | j                  j                         | j                  d       i |t        |    S )z,Get the parameters used to invoke the model.model)api_keyapi_base)	r   _default_paramsr   updater   get_secret_valuer   super_invocation_params)selfparams	__class__s     r   r#   z!OctoAIEndpoint._invocation_params.   sm    
 T__"
"""
 ~MM#44EEG $ 4 4 8&7EG677r   c                      y)zReturn type of llm.octoai_endpointr   )r$   s    r   	_llm_typezOctoAIEndpoint._llm_type@   s     !r   valuesc                 P   t        |ddt              |d<   t        t        |dd            |d<   t        |ddt              |d<   	 dd	l}t               rz|d   j                         |d   d
}|j                  d      s |j                  di |j                  |d<   |j                  d      sM |j                  di |j                  |d<   n-|d   |d<   |d   j                         |d<   |j                  |d<   d|d   v rt        d      |S # t        $ r t        d      w xY w)z?Validate that api key and python package exists in environment.r   OCTOAI_API_BASEr   r   OCTOAI_API_TOKENr   
MODEL_NAMEr   N)r   base_urlclientasync_clientopenai_api_baseopenai_api_keyzTCould not import openai python package. Please install it with `pip install openai`.endpoint_urlmodel_kwargsz<`endpoint_url` was deprecated, please use `octoai_api_base`.r   )r   DEFAULT_BASE_URLr   DEFAULT_MODELopenair   r!   getOpenAIcompletionsAsyncOpenAI
CompletionImportError
ValueError)r   r*   r8   client_paramss       r   validate_environmentz#OctoAIEndpoint.validate_environmentE   sq    %9$	%
 ! &; );=OP&
!"  4!	 
|	~%&89JJL &'8 9! zz(+'4v}}'E}'E'Q'QF8$zz.1-?V-?-? .'.!k >* -33D,E()+12D+E+V+V+X'(#)#4#4x  VN33N    	? 	s   B5D D%)__name__
__module____qualname____doc__r   r6   r   str__annotations__r	   r   r7   r   classmethodboolr   propertyr   r   r#   r)   r   rA   __classcell__)r&   s   @r   r   r      s    . 3 )9:OS:"'	"">i>M2J24   8DcN 8 8" !3 ! ! /$ /4 / /r   r   N)typingr   r   langchain_core.utilsr   r   r   pydanticr   r	   langchain_community.llms.openair
    langchain_community.utils.openair   r6   r7   r   r   r   r   <module>rQ      s0     V V % 6 90 'hZ hr   