[docs]classBanana(LLM):"""Banana large language models. To use, you should have the ``banana-dev`` python package installed, and the environment variable ``BANANA_API_KEY`` set with your API key. This is the team API key available in the Banana dashboard. Any parameters that are valid to be passed to the call can be passed in, even if not explicitly saved on this class. Example: .. code-block:: python from langchain_community.llms import Banana banana = Banana(model_key="", model_url_slug="") """model_key:str="""""model key to use"""model_url_slug:str="""""model endpoint to use"""model_kwargs:Dict[str,Any]=Field(default_factory=dict)"""Holds any model parameters valid for `create` call not explicitly specified."""banana_api_key:Optional[SecretStr]=Field(default_factory=secret_from_env("BANANA_API_KEY",default=None))model_config=ConfigDict(extra="forbid",)@model_validator(mode="before")@classmethoddefbuild_extra(cls,values:Dict[str,Any])->Any:"""Build extra kwargs from additional params that were passed in."""all_required_field_names=set(list(cls.model_fields.keys()))extra=values.get("model_kwargs",{})forfield_nameinlist(values):iffield_namenotinall_required_field_names:iffield_nameinextra:raiseValueError(f"Found {field_name} supplied twice.")logger.warning(f"""{field_name} was transferred to model_kwargs. Please confirm that {field_name} is what you intended.""")extra[field_name]=values.pop(field_name)values["model_kwargs"]=extrareturnvalues@propertydef_identifying_params(self)->Mapping[str,Any]:"""Get the identifying parameters."""return{**{"model_key":self.model_key},**{"model_url_slug":self.model_url_slug},**{"model_kwargs":self.model_kwargs},}@propertydef_llm_type(self)->str:"""Return type of llm."""return"bananadev"def_call(self,prompt:str,stop:Optional[List[str]]=None,run_manager:Optional[CallbackManagerForLLMRun]=None,**kwargs:Any,)->str:"""Call to Banana endpoint."""try:frombanana_devimportClientexceptImportError:raiseImportError("Could not import banana-dev python package. ""Please install it with `pip install banana-dev`.")params=self.model_kwargsor{}params={**params,**kwargs}api_key=cast(SecretStr,self.banana_api_key)model_key=self.model_keymodel_url_slug=self.model_url_slugmodel_inputs={# a json specific to your model."prompt":prompt,**params,}model=Client(# Found in main dashboardapi_key=api_key.get_secret_value(),# Both found in model details pagemodel_key=model_key,url=f"https://{model_url_slug}.run.banana.dev",)response,meta=model.call("/",model_inputs)try:text=response["outputs"]except(KeyError,TypeError):raiseValueError("Response should be of schema: {'outputs': 'text'}.""\nTo fix this:""\n- fork the source repo of the Banana model""\n- modify app.py to return the above schema""\n- deploy that as a custom repo")ifstopisnotNone:# I believe this is required since the stop tokens# are not enforced by the model parameterstext=enforce_stop_tokens(text,stop)returntext