Source code for langchain.llms.edenai
"""Wrapper around EdenAI's Generation API."""
import logging
from typing import Any, Dict, List, Literal, Optional
from aiohttp import ClientSession
from langchain.callbacks.manager import (
    AsyncCallbackManagerForLLMRun,
    CallbackManagerForLLMRun,
)
from langchain.llms.base import LLM
from langchain.llms.utils import enforce_stop_tokens
from langchain.pydantic_v1 import Extra, Field, root_validator
from langchain.utilities.requests import Requests
from langchain.utils import get_from_dict_or_env
logger = logging.getLogger(__name__)
[docs]class EdenAI(LLM):
    """Wrapper around edenai models.
    To use, you should have
    the environment variable ``EDENAI_API_KEY`` set with your API token.
    You can find your token here: https://app.edenai.run/admin/account/settings
    `feature` and `subfeature` are required, but any other model parameters can also be
    passed in with the format params={model_param: value, ...}
    for api reference check edenai documentation: http://docs.edenai.co.
    """
    base_url: str = "https://api.edenai.run/v2"
    edenai_api_key: Optional[str] = None
    feature: Literal["text", "image"] = "text"
    """Which generative feature to use, use text by default"""
    subfeature: Literal["generation"] = "generation"
    """Subfeature of above feature, use generation by default"""
    provider: str
    """Generative provider to use (eg: openai,stabilityai,cohere,google etc.)"""
    model: Optional[str] = None
    """