[docs]classBaseten(LLM):"""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:strdeployment:strinput:Dict[str,Any]=Field(default_factory=dict)model_kwargs:Dict[str,Any]=Field(default_factory=dict)@propertydef_identifying_params(self)->Mapping[str,Any]:"""Get the identifying parameters."""return{**{"model_kwargs":self.model_kwargs},}@propertydef_llm_type(self)->str:"""Return type of model."""return"baseten"def_call(self,prompt:str,stop:Optional[List[str]]=None,run_manager:Optional[CallbackManagerForLLMRun]=None,**kwargs:Any,)->str:baseten_api_key=os.environ["BASETEN_API_KEY"]model_id=self.modelifself.deployment=="production":model_url=f"https://model-{model_id}.api.baseten.co/production/predict"elifself.deployment=="development":model_url=f"https://model-{model_id}.api.baseten.co/development/predict"else:# try specific deployment IDmodel_url=f"https://model-{model_id}.api.baseten.co/deployment/{self.deployment}/predict"response=requests.post(model_url,headers={"Authorization":f"Api-Key {baseten_api_key}"},json={"prompt":prompt,**kwargs},)returnresponse.json()