
    Nga                         d dl Z d dlZd dlmZmZmZmZmZ d dlZd dl	m
Z
 d dlmZ d dlmZ  e j        e          Z G d de          ZdS )    N)AnyDictListMappingOptional)CallbackManagerForLLMRun)LLM)Fieldc                      e Zd ZU dZeed<   eed<    ee          Ze	ee
f         ed<    ee          Ze	ee
f         ed<   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 )Basetena  Baseten model

    This module allows using LLMs hosted on Baseten.

    The LLM deployed on Baseten must have the following properties:

    * Must accept input as a dictionary with the key "prompt"
    * May accept other input in the dictionary passed through with kwargs
    * Must return a string with the model output

    To use this module, you must:

    * Export your Baseten API key as the environment variable `BASETEN_API_KEY`
    * Get the model ID for your model from your Baseten dashboard
    * Identify the model deployment ("production" for all model library models)

    These code samples use
    [Mistral 7B Instruct](https://app.baseten.co/explore/mistral_7b_instruct)
    from Baseten's model library.

    Examples:
        .. code-block:: python

            from langchain_community.llms import Baseten
            # Production deployment
            mistral = Baseten(model="MODEL_ID", deployment="production")
            mistral("What is the Mistral wind?")

        .. code-block:: python

            from langchain_community.llms import Baseten
            # Development deployment
            mistral = Baseten(model="MODEL_ID", deployment="development")
            mistral("What is the Mistral wind?")

        .. code-block:: python

            from langchain_community.llms import Baseten
            # Other published deployment
            mistral = Baseten(model="MODEL_ID", deployment="DEPLOYMENT_ID")
            mistral("What is the Mistral wind?")
    model
deployment)default_factoryinputmodel_kwargsreturnc                     i d| j         iS )zGet the identifying parameters.r   )r   selfs    \/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/llms/baseten.py_identifying_paramszBaseten._identifying_params>   s    
t01
 	
    c                     dS )zReturn type of model.baseten r   s    r   	_llm_typezBaseten._llm_typeE   s	     yr   Npromptstoprun_managerkwargsc                     t           j        d         }| j        }| j        dk    rd| d}n | j        dk    rd| d}nd| d| j         d}t	          j        |d	d
| id|i|          }|                                S )NBASETEN_API_KEY
productionzhttps://model-z".api.baseten.co/production/predictdevelopmentz#.api.baseten.co/development/predictz.api.baseten.co/deployment/z/predictAuthorizationzApi-Key r   )headersjson)osenvironr   r   requestspostr'   )	r   r   r   r   r    baseten_api_keymodel_id	model_urlresponses	            r   _callzBaseten._callJ   s     *%67:?l**UUUUII_--VVVVIIgggdogggI=$&B&B&BCF-f-
 
 

 }}r   )NN)__name__
__module____qualname____doc__str__annotations__r
   dictr   r   r   r   propertyr   r   r   r   r   r   r0   r   r   r   r   r      s4        ) )V JJJOOO!E$777E4S>777#(5#>#>#>L$sCx.>>>
WS#X%6 
 
 
 X
 3    X %):>	  tCy! 67	
  
     r   r   )loggingr(   typingr   r   r   r   r   r*   langchain_core.callbacksr   #langchain_core.language_models.llmsr	   pydanticr
   	getLoggerr1   loggerr   r   r   r   <module>r@      s     				 5 5 5 5 5 5 5 5 5 5 5 5 5 5  = = = = = = 3 3 3 3 3 3      		8	$	$Q Q Q Q Qc Q Q Q Q Qr   