Source code for langchain.llms.aviary
"""Wrapper around Aviary"""
from typing import Any, Dict, List, Mapping, Optional
import requests
from pydantic import Extra, Field, root_validator
from langchain.callbacks.manager import CallbackManagerForLLMRun
from langchain.llms.base import LLM
from langchain.llms.utils import enforce_stop_tokens
from langchain.utils import get_from_dict_or_env
TIMEOUT = 60
[docs]class Aviary(LLM):
    """Allow you to use an Aviary.
    Aviary is a backend for hosted models. You can
    find out more about aviary at
    http://github.com/ray-project/aviary
    Has no dependencies, since it connects to backend
    directly.
    To get a list of the models supported on an
    aviary, follow the instructions on the web site to
    install the aviary CLI and then use:
    `aviary models`
    You must at least specify the environment
    variable or parameter AVIARY_URL.
    You may optionally specify the environment variable
    or parameter AVIARY_TOKEN.
    Example:
        .. code-block:: python
            from langchain.llms import Aviary
            light = Aviary(aviary_url='AVIARY_URL',
                            model='amazon/LightGPT')
            result = light.predict('How do you make fried rice?')
    """
    model: str
    aviary_url: str
    aviary_token: str = Field("", exclude=True)
    class Config:
        """Configuration for this pydantic object."""
        extra = Extra.forbid
    @root_validator(pre=True)
    def validate_environment(cls, values: Dict) -> Dict:
        """Validate that api key and python package exists in environment."""
rtdocs_stable/api.python.langchain.com/en/stable/_modules/langchain/llms/aviary.html