a
    bga                     @   sv   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 eZG dd deZdS )    N)AnyDictListMappingOptional)CallbackManagerForLLMRun)LLM)Fieldc                   @   s   e Zd ZU dZeed< eed< eedZe	ee
f ed< eedZe	ee
f ed< eeee
f ddd	Zeedd
dZdeeee  ee e
edd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                 C   s   i d| j iS )zGet the identifying parameters.r   )r   self r   n/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/langchain_community/llms/baseten.py_identifying_params>   s    zBaseten._identifying_paramsc                 C   s   dS )zReturn type of model.Zbasetenr   r   r   r   r   	_llm_typeE   s    zBaseten._llm_typeN)promptstoprun_managerkwargsr   c           	      K   s~   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|d}| S )NZBASETEN_API_KEY
productionzhttps://model-z".api.baseten.co/production/predictZ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   Zbaseten_api_keyZmodel_idZ	model_urlresponser   r   r   _callJ   s    



zBaseten._call)NN)__name__
__module____qualname____doc__str__annotations__r	   dictr   r   r   r   propertyr   r   r   r   r   r   r$   r   r   r   r   r
      s$   
+  
r
   )loggingr   typingr   r   r   r   r   r!   Zlangchain_core.callbacksr   Z#langchain_core.language_models.llmsr   Zpydanticr	   	getLoggerr%   loggerr
   r   r   r   r   <module>   s   
