Source code for langchain.llms.gradient_ai
from typing import Any, Dict, List, Mapping, Optional, Union
import aiohttp
import requests
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, root_validator
from langchain.utils import get_from_dict_or_env
[docs]class GradientLLM(LLM):
    """Gradient.ai LLM Endpoints.
    GradientLLM is a class to interact with LLMs on gradient.ai
    To use, set the environment variable ``GRADIENT_ACCESS_TOKEN`` with your
    API token and ``GRADIENT_WORKSPACE_ID`` for your gradient workspace,
    or alternatively provide them as keywords to the constructor of this class.
    Example:
        .. code-block:: python
            from langchain.llms.gradientai_endpoint import GradientAIEndpoint
            GradientLLM(
                model_id="cad6644_base_ml_model",
                model_kwargs={
                    "max_generated_token_count": 200,
                    "temperature": 0.75,
                    "top_p": 0.95,
                    "top_k": 20,
                    "stop": [],
                },
                gradient_workspace_id="12345614fc0_workspace",
                gradient_access_token="gradientai-access_token",
            )
    """
    model_id: str
    "Underlying gradient.ai model id (base or fine-tuned)."
    gradient_workspace_id: Optional[str] = None
    "Underlying gradient.ai workspace_id."
    gradient_access_token: Optional[str] = None
    """gradient.ai API Token, which can be generated by going to