Skip to content

The agent engineering platform.

docstrings for `LLMs` (#7976)

Leonid Ganeline0613ed5b955b
diff --git a/langchain/llms/__init__.py b/langchain/llms/__init__.py
index 1782a34cc7..f8c8fea525 100644
--- a/langchain/llms/__init__.py
+++ b/langchain/llms/__init__.py
@@ -1,4 +1,4 @@
-"""Wrappers on top of large language models APIs."""
+"""Access to the large language model APIs and services."""
from typing import Dict, Type
from langchain.llms.ai21 import AI21
diff --git a/langchain/llms/ai21.py b/langchain/llms/ai21.py
index ae02e38fe7..5d2562a6af 100644
--- a/langchain/llms/ai21.py
+++ b/langchain/llms/ai21.py
@@ -1,4 +1,3 @@
-"""Wrapper around AI21 APIs."""
from typing import Any, Dict, List, Optional
import requests
@@ -21,7 +20,7 @@ class AI21PenaltyData(BaseModel):
class AI21(LLM):
- """Wrapper around AI21 large language models.
+ """AI21 large language models.
To use, you should have the environment variable ``AI21_API_KEY``
set with your API key.
diff --git a/langchain/llms/aleph_alpha.py b/langchain/llms/aleph_alpha.py
index b006ca95f5..cd4aec1682 100644
--- a/langchain/llms/aleph_alpha.py
+++ b/langchain/llms/aleph_alpha.py
@@ -1,4 +1,3 @@
-"""Wrapper around Aleph Alpha APIs."""
from typing import Any, Dict, List, Optional, Sequence
from pydantic import Extra, root_validator
@@ -10,7 +9,7 @@ from langchain.utils import get_from_dict_or_env
class AlephAlpha(LLM):
- """Wrapper around Aleph Alpha large language models.
+ """Aleph Alpha large language models.
To use, you should have the ``aleph_alpha_client`` python package installed, and the
environment variable ``ALEPH_ALPHA_API_KEY`` set with your API key, or pass
diff --git a/langchain/llms/amazon_api_gateway.py b/langchain/llms/amazon_api_gateway.py
index 72b269dcba..1ba81c1189 100644
--- a/langchain/llms/amazon_api_gateway.py
+++ b/langchain/llms/amazon_api_gateway.py
@@ -9,8 +9,10 @@ from langchain.llms.utils import enforce_stop_tokens
class ContentHandlerAmazonAPIGateway:
- """Adapter class to prepare the inputs from Langchain to a format
- that LLM model expects. Also, provides helper function to extract
+ """Adapter to prepare the inputs from Langchain to a format
+ that LLM model expects.
+
+ It also provides helper function to extract
the generated text from the model response."""
@classmethod
@@ -25,7 +27,7 @@ class ContentHandlerAmazonAPIGateway:
class AmazonAPIGateway(LLM):
- """Wrapper around custom Amazon API Gateway"""
+ """Amazon API Gateway to access LLM models hosted on AWS."""
api_url: str
"""API Gateway URL"""
diff --git a/langchain/llms/anthropic.py b/langchain/llms/anthropic.py
index 5523eec78b..a9d564fee4 100644
--- a/langchain/llms/anthropic.py
+++ b/langchain/llms/anthropic.py
@@ -1,4 +1,3 @@
-"""Wrapper around Anthropic APIs."""
import re
import warnings
from typing import Any, Callable, Dict, Generator, List, Mapping, Optional
@@ -117,7 +116,7 @@ class _AnthropicCommon(BaseModel):
class Anthropic(LLM, _AnthropicCommon):
- r"""Wrapper around Anthropic's large language models.
+ """Anthropic large language models.
To use, you should have the ``anthropic`` python package installed, and the
environment variable ``ANTHROPIC_API_KEY`` set with your API key, or pass
diff --git a/langchain/llms/anyscale.py b/langchain/llms/anyscale.py
index 307efd1e84..5a440b97d4 100644
--- a/langchain/llms/anyscale.py
+++ b/langchain/llms/anyscale.py
@@ -1,4 +1,3 @@
-"""Wrapper around Anyscale"""
from typing import Any, Dict, List, Mapping, Optional
import requests
@@ -11,7 +10,8 @@ from langchain.utils import get_from_dict_or_env
class Anyscale(LLM):
- """Wrapper around Anyscale Services.
+ """Anyscale Service models.
+
To use, you should have the environment variable ``ANYSCALE_SERVICE_URL``,
``ANYSCALE_SERVICE_ROUTE`` and ``ANYSCALE_SERVICE_TOKEN`` set with your Anyscale
Service, or pass it as a named parameter to the constructor.
diff --git a/langchain/llms/aviary.py b/langchain/llms/aviary.py
index ba3c373072..9f9c0937d0 100644
--- a/langchain/llms/aviary.py
+++ b/langchain/llms/aviary.py
@@ -1,4 +1,3 @@
-"""Wrapper around Aviary"""
import dataclasses
import os
from typing import Any, Dict, List, Mapping, Optional, Union, cast
@@ -77,14 +76,14 @@ def get_completions(
class Aviary(LLM):
- """Allow you to use an Aviary.
+ """Aviary hosted models.
Aviary is a backend for hosted models. You can
find out more about aviary at
http://github.com/ray-project/aviary
To get a list of the models supported on an
- aviary, follow the instructions on the web site to
+ aviary, follow the instructions on the website to
install the aviary CLI and then use:
`aviary models`
diff --git a/langchain/llms/azureml_endpoint.py b/langchain/llms/azureml_endpoint.py
index c520d6455f..20a34613f6 100644
--- a/langchain/llms/azureml_endpoint.py
+++ b/langchain/llms/azureml_endpoint.py
@@ -1,4 +1,3 @@
-"""Wrapper around AzureML Managed Online Endpoint API."""
import json
import urllib.request
from abc import abstractmethod
@@ -12,7 +11,7 @@ from langchain.utils import get_from_dict_or_env
class AzureMLEndpointClient(object):
- """Wrapper around AzureML Managed Online Endpoint Client."""
+ """AzureML Managed Endpoint client."""
def __init__(
self, endpoint_url: str, endpoint_api_key: str, deployment_name: str
@@ -43,8 +42,8 @@ class AzureMLEndpointClient(object):
class ContentFormatterBase:
- """A handler class to transform request and response of
- AzureML endpoint to match with required schema.
+ """Transform request and response of AzureML endpoint to match with
+ required schema.
"""
"""
@@ -134,7 +133,7 @@ class DollyContentFormatter(ContentFormatterBase):
class AzureMLOnlineEndpoint(LLM, BaseModel):
- """Wrapper around Azure ML Hosted models using Managed Online Endpoints.
+ """Azure ML Online Endpoint models.
Example:
.. code-block:: python
diff --git a/langchain/llms/bananadev.py b/langchain/llms/bananadev.py
index 32722de1aa..76dcb7b8af 100644
--- a/langchain/llms/bananadev.py
+++ b/langchain/llms/bananadev.py
@@ -1,4 +1,3 @@
-"""Wrapper around Banana API."""
import logging
from typing import Any, Dict, List, Mapping, Optional
@@ -13,7 +12,7 @@ logger = logging.getLogger(__name__)
class Banana(LLM):
- """Wrapper around Banana large language models.
+ """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.
diff --git a/langchain/llms/base.py b/langchain/llms/base.py
index b11712f61e..91deb9c794 100644
--- a/langchain/llms/base.py
+++ b/langchain/llms/base.py
@@ -116,7 +116,9 @@ def update_cache(
class BaseLLM(BaseLanguageModel, ABC):
- """LLM wrapper should take in a prompt and return a string."""
+ """Base LLM abstract interface.
+
+ It should take in a prompt and return a string."""
cache: Optional[bool] = None
verbose: bool = Field(default_factory=_get_verbosity)
@@ -560,7 +562,7 @@ class BaseLLM(BaseLanguageModel, ABC):
class LLM(BaseLLM):
- """LLM class that expect subclasses to implement a simpler call method.
+ """Base LLM abstract class.
The purpose of this class is to expose a simpler interface for working
with LLMs, rather than expect the user to implement the full _generate method.
diff --git a/langchain/llms/baseten.py b/langchain/llms/baseten.py
index a5a314c437..d7d768d5ec 100644
--- a/langchain/llms/baseten.py
+++ b/langchain/llms/baseten.py
@@ -1,4 +1,3 @@
-"""Wrapper around Baseten deployed model API."""
import logging
from typing import Any, Dict, List, Mapping, Optional
@@ -11,7 +10,7 @@ logger = logging.getLogger(__name__)
class Baseten(LLM):
- """Use your Baseten models in Langchain
+ """Baseten models.
To use, you should have the ``baseten`` python package installed,
and run ``baseten.login()`` with your Baseten API key.
@@ -60,7 +59,7 @@ class Baseten(LLM):
try:
import baseten
except ImportError as exc:
- raise ValueError(
+ raise ImportError(
"Could not import Baseten Python package. "
"Please install it with `pip install baseten`."
) from exc
diff --git a/langchain/llms/beam.py b/langchain/llms/beam.py
index 3f6dc1bc48..47bc017dad 100644
--- a/langchain/llms/beam.py
+++ b/langchain/llms/beam.py
@@ -1,4 +1,3 @@
-"""Wrapper around Beam API."""
import base64
import json
import logging
@@ -21,12 +20,12 @@ DEFAULT_SLEEP_TIME = 4
class Beam(LLM):
- """Wrapper around Beam API for gpt2 large language model.
+ """Beam API for gpt2 large language model.
To use, you should have the ``beam-sdk`` python package installed,
and the environment variable ``BEAM_CLIENT_ID`` set with your client id
and ``BEAM_CLIENT_SECRET`` set with your client secret. Information on how
- to get these is available here: https://docs.beam.cloud/account/api-keys.
+ to get this is available here: https://docs.beam.cloud/account/api-keys.
The wrapper can then be called as follows, where the name, cpu, memory, gpu,
python version, and python packages can be updated accordingly. Once deployed,
diff --git a/langchain/llms/bedrock.py b/langchain/llms/bedrock.py
index f923e0e5a3..481de7f568 100644
--- a/langchain/llms/bedrock.py
+++ b/langchain/llms/bedrock.py
@@ -10,7 +10,9 @@ from langchain.llms.utils import enforce_stop_tokens
class LLMInputOutputAdapter:
"""Adapter class to prepare the inputs from Langchain to a format
- that LLM model expects. Also, provides helper function to extract
+ that LLM model expects.
+
+ It also provides helper function to extract
the generated text from the model response."""
@classmethod
@@ -47,7 +49,7 @@ class LLMInputOutputAdapter:
class Bedrock(LLM):
- """LLM provider to invoke Bedrock models.
+ """Bedrock models.
To authenticate, the AWS client uses the following methods to
automatically load credentials:
diff --git a/langchain/llms/cerebriumai.py b/langchain/llms/cerebriumai.py
index b48edd2ab2..02db1cf33e 100644
--- a/langchain/llms/cerebriumai.py
+++ b/langchain/llms/cerebriumai.py
@@ -1,4 +1,3 @@
-"""Wrapper around CerebriumAI API."""
import logging
from typing import Any, Dict, List, Mapping, Optional
@@ -13,7 +12,7 @@ logger = logging.getLogger(__name__)
class CerebriumAI(LLM):
- """Wrapper around CerebriumAI large language models.
+ """CerebriumAI large language models.
To use, you should have the ``cerebrium`` python package installed, and the
environment variable ``CEREBRIUMAI_API_KEY`` set with your API key.
diff --git a/langchain/llms/chatglm.py b/langchain/llms/chatglm.py
index 2ee3c01f0c..a186f3716c 100644
--- a/langchain/llms/chatglm.py
+++ b/langchain/llms/chatglm.py
@@ -8,7 +8,7 @@ from langchain.llms.utils import enforce_stop_tokens
class ChatGLM(LLM):
- """Wrapper around ChatGLM's LLM inference service.
+ """ChatGLM LLM service.
Example:
.. code-block:: python
diff --git a/langchain/llms/clarifai.py b/langchain/llms/clarifai.py
index c9b059d452..2eead83592 100644
--- a/langchain/llms/clarifai.py
+++ b/langchain/llms/clarifai.py
@@ -1,4 +1,3 @@
-"""Wrapper around Clarifai's APIs."""
import logging
from typing import Any, Dict, List, Optional
@@ -13,7 +12,7 @@ logger = logging.getLogger(__name__)
class Clarifai(LLM):
- """Wrapper around Clarifai's large language models.
+ """Clarifai large language models.
To use, you should have an account on the Clarifai platform,
the ``clarifai`` python package installed, and the
diff --git a/langchain/llms/cohere.py b/langchain/llms/cohere.py
index 7fd181fe3f..2e37697990 100644
--- a/langchain/llms/cohere.py
+++ b/langchain/llms/cohere.py
@@ -1,4 +1,3 @@
-"""Wrapper around Cohere APIs."""
from __future__ import annotations
import logging
@@ -49,7 +48,7 @@ def completion_with_retry(llm: Cohere, **kwargs: Any) -> Any:
class Cohere(LLM):
- """Wrapper around Cohere large language models.
+ """Cohere large language models.
To use, you should have the ``cohere`` python package installed, and the
environment variable ``COHERE_API_KEY`` set with your API key, or pass
diff --git a/langchain/llms/ctransformers.py b/langchain/llms/ctransformers.py
index 7d310109fc..86c657f618 100644
--- a/langchain/llms/ctransformers.py
+++ b/langchain/llms/ctransformers.py
@@ -1,4 +1,3 @@
-"""Wrapper around the C Transformers library."""
from functools import partial
from typing import Any, Dict, List, Optional, Sequence
@@ -12,7 +11,7 @@ from langchain.llms.base import LLM
class CTransformers(LLM):
- """Wrapper around the C Transformers LLM interface.
+ """C Transformers LLM models.
To use, you should have the ``ctransformers`` python package installed.
See https://github.com/marella/ctransformers
diff --git a/langchain/llms/databricks.py b/langchain/llms/databricks.py
index 2992a30cb6..6ed2a6fa7d 100644
--- a/langchain/llms/databricks.py
+++ b/langchain/llms/databricks.py
@@ -130,7 +130,8 @@ def get_default_api_token() -> str:
class Databricks(LLM):
- """LLM wrapper around a Databricks serving endpoint or a cluster driver proxy app.
+ """Databricks serving endpoint or a cluster driver proxy app for LLM.
+
It supports two endpoint types:
* **Serving endpoint** (recommended for both production and development).
diff --git a/langchain/llms/deepinfra.py b/langchain/llms/deepinfra.py
index 0cf5768e4b..533c236284 100644
--- a/langchain/llms/deepinfra.py
+++ b/langchain/llms/deepinfra.py
@@ -1,4 +1,3 @@
-"""Wrapper around DeepInfra APIs."""
from typing import Any, Dict, List, Mapping, Optional
import requests
@@ -13,7 +12,7 @@ DEFAULT_MODEL_ID = "google/flan-t5-xl"
class DeepInfra(LLM):
- """Wrapper around DeepInfra deployed models.
+ """DeepInfra models.
To use, you should have the ``requests`` python package installed, and the
environment variable ``DEEPINFRA_API_TOKEN`` set with your API token, or pass
diff --git a/langchain/llms/fake.py b/langchain/llms/fake.py
index 3d61a951bb..4b139316a4 100644
--- a/langchain/llms/fake.py
+++ b/langchain/llms/fake.py
@@ -1,4 +1,3 @@
-"""Fake LLM wrapper for testing purposes."""
from typing import Any, List, Mapping, Optional
from langchain.callbacks.manager import (
@@ -9,7 +8,7 @@ from langchain.llms.base import LLM
class FakeListLLM(LLM):
- """Fake LLM wrapper for testing purposes."""
+ """Fake LLM for testing purposes."""
responses: List
i: int = 0
diff --git a/langchain/llms/forefrontai.py b/langchain/llms/forefrontai.py
index 16a0ac48d4..b6c70d5c43 100644
--- a/langchain/llms/forefrontai.py
+++ b/langchain/llms/forefrontai.py
@@ -1,4 +1,3 @@
-"""Wrapper around ForefrontAI APIs."""
from typing import Any, Dict, List, Mapping, Optional
import requests
@@ -11,7 +10,7 @@ from langchain.utils import get_from_dict_or_env
class ForefrontAI(LLM):
- """Wrapper around ForefrontAI large language models.
+ """ForefrontAI large language models.
To use, you should have the environment variable ``FOREFRONTAI_API_KEY``
set with your API key.
diff --git a/langchain/llms/google_palm.py b/langchain/llms/google_palm.py
index f8e1ab7a91..4b95c06369 100644
--- a/langchain/llms/google_palm.py
+++ b/langchain/llms/google_palm.py
@@ -1,4 +1,3 @@
-"""Wrapper around Google's PaLM Text APIs."""
from __future__ import annotations
import logging
@@ -77,6 +76,8 @@ def _strip_erroneous_leading_spaces(text: str) -> str:
class GooglePalm(BaseLLM, BaseModel):
+ """Google PaLM models."""
+
client: Any #: :meta private:
google_api_key: Optional[str]
model_name: str = "models/text-bison-001"
diff --git a/langchain/llms/gooseai.py b/langchain/llms/gooseai.py
index 81f795d6ee..cde043ce22 100644
--- a/langchain/llms/gooseai.py
+++ b/langchain/llms/gooseai.py
@@ -1,4 +1,3 @@
-"""Wrapper around GooseAI API."""
import logging
from typing import Any, Dict, List, Mapping, Optional
@@ -12,7 +11,7 @@ logger = logging.getLogger(__name__)
class GooseAI(LLM):
- """Wrapper around OpenAI large language models.
+ """GooseAI large language models.
To use, you should have the ``openai`` python package installed, and the
environment variable ``GOOSEAI_API_KEY`` set with your API key.
diff --git a/langchain/llms/gpt4all.py b/langchain/llms/gpt4all.py
index 24a994b55a..c88374c1c0 100644
--- a/langchain/llms/gpt4all.py
+++ b/langchain/llms/gpt4all.py
@@ -1,4 +1,3 @@
-"""Wrapper for the GPT4All model."""
from functools import partial
from typing import Any, Dict, List, Mapping, Optional, Set
@@ -10,7 +9,7 @@ from langchain.llms.utils import enforce_stop_tokens
class GPT4All(LLM):
- r"""Wrapper around GPT4All language models.
+ """GPT4All language models.
To use, you should have the ``gpt4all`` python package installed, the
pre-trained model file, and the model's config information.
diff --git a/langchain/llms/huggingface_endpoint.py b/langchain/llms/huggingface_endpoint.py
index 34aa98d4ab..ff38a2025a 100644
--- a/langchain/llms/huggingface_endpoint.py
+++ b/langchain/llms/huggingface_endpoint.py
@@ -1,4 +1,3 @@
-"""Wrapper around HuggingFace APIs."""
from typing import Any, Dict, List, Mapping, Optional
import requests
@@ -13,7 +12,7 @@ VALID_TASKS = ("text2text-generation", "text-generation", "summarization")
class HuggingFaceEndpoint(LLM):
- """Wrapper around HuggingFaceHub Inference Endpoints.
+ """HuggingFace Endpoint models.
To use, you should have the ``huggingface_hub`` python package installed, and the
environment variable ``HUGGINGFACEHUB_API_TOKEN`` set with your API token, or pass
diff --git a/langchain/llms/huggingface_hub.py b/langchain/llms/huggingface_hub.py
index cefa1bcc19..745f0fdccb 100644
--- a/langchain/llms/huggingface_hub.py
+++ b/langchain/llms/huggingface_hub.py
@@ -1,4 +1,3 @@
-"""Wrapper around HuggingFace APIs."""
from typing import Any, Dict, List, Mapping, Optional
from pydantic import Extra, root_validator
@@ -13,7 +12,7 @@ VALID_TASKS = ("text2text-generation", "text-generation", "summarization")
class HuggingFaceHub(LLM):
- """Wrapper around HuggingFaceHub models.
+ """HuggingFaceHub models.
To use, you should have the ``huggingface_hub`` python package installed, and the
environment variable ``HUGGINGFACEHUB_API_TOKEN`` set with your API token, or pass
diff --git a/langchain/llms/huggingface_pipeline.py b/langchain/llms/huggingface_pipeline.py
index 92da6f5fba..ef7d428949 100644
--- a/langchain/llms/huggingface_pipeline.py
+++ b/langchain/llms/huggingface_pipeline.py
@@ -1,4 +1,3 @@
-"""Wrapper around HuggingFace Pipeline APIs."""
import importlib.util
import logging
from typing import Any, List, Mapping, Optional
@@ -17,7 +16,7 @@ logger = logging.getLogger(__name__)
class HuggingFacePipeline(LLM):
- """Wrapper around HuggingFace Pipeline API.
+ """HuggingFace Pipeline API.
To use, you should have the ``transformers`` python package installed.
diff --git a/langchain/llms/huggingface_text_gen_inference.py b/langchain/llms/huggingface_text_gen_inference.py
index 5f33668790..1bd150de65 100644
--- a/langchain/llms/huggingface_text_gen_inference.py
+++ b/langchain/llms/huggingface_text_gen_inference.py
@@ -1,4 +1,3 @@
-"""Wrapper around Huggingface text generation inference API."""
from functools import partial
from typing import Any, Dict, List, Optional
@@ -13,10 +12,9 @@ from langchain.llms.base import LLM
class HuggingFaceTextGenInference(LLM):
"""
- HuggingFace text generation inference API.
+ HuggingFace text generation API.
- This class is a wrapper around the HuggingFace text generation inference API.
- It is used to generate text from a given prompt.
+ It generates text from a given prompt.
Attributes:
- max_new_tokens: The maximum number of tokens to generate.
diff --git a/langchain/llms/human.py b/langchain/llms/human.py
index d585ee8edc..87ce68f152 100644
--- a/langchain/llms/human.py
+++ b/langchain/llms/human.py
@@ -34,7 +34,7 @@ def _collect_user_input(
class HumanInputLLM(LLM):
"""
- A LLM wrapper which returns user input as the response.
+ It returns user input as the response.
"""
input_func: Callable = Field(default_factory=lambda: _collect_user_input)
diff --git a/langchain/llms/koboldai.py b/langchain/llms/koboldai.py
index de7c6db2d3..ac0602794e 100644
--- a/langchain/llms/koboldai.py
+++ b/langchain/llms/koboldai.py
@@ -1,4 +1,3 @@
-"""Wrapper around KoboldAI API."""
import logging
from typing import Any, Dict, List, Optional
@@ -21,8 +20,7 @@ def clean_url(url: str) -> str:
class KoboldApiLLM(LLM):
- """
- A class that acts as a wrapper for the Kobold API language model.
+ """Kobold API language model.
It includes several fields that can be used to control the text generation process.
diff --git a/langchain/llms/llamacpp.py b/langchain/llms/llamacpp.py
index a48ec6b58e..9f849e98c5 100644
--- a/langchain/llms/llamacpp.py
+++ b/langchain/llms/llamacpp.py
@@ -1,4 +1,3 @@
-"""Wrapper around llama.cpp."""
import logging
from typing import Any, Dict, Generator, List, Optional
@@ -11,7 +10,7 @@ logger = logging.getLogger(__name__)
class LlamaCpp(LLM):
- """Wrapper around the llama.cpp model.
+ """llama.cpp model.
To use, you should have the llama-cpp-python library installed, and provide the
path to the Llama model as a named parameter to the constructor.
@@ -136,7 +135,7 @@ class LlamaCpp(LLM):
values["client"] = Llama(model_path, **model_params)
except ImportError:
- raise ModuleNotFoundError(
+ raise ImportError(
"Could not import llama-cpp-python library. "
"Please install the llama-cpp-python library to "
"use this embedding model: pip install llama-cpp-python"
diff --git a/langchain/llms/loading.py b/langchain/llms/loading.py
index 723606bee6..d960390818 100644
--- a/langchain/llms/loading.py
+++ b/langchain/llms/loading.py
@@ -1,4 +1,4 @@
-"""Base interface for loading large language models apis."""
+"""Base interface for loading large language model APIs."""
import json
from pathlib import Path
from typing import Union
diff --git a/langchain/llms/manifest.py b/langchain/llms/manifest.py
index cd04c149ff..71a89ed00f 100644
--- a/langchain/llms/manifest.py
+++ b/langchain/llms/manifest.py
@@ -1,4 +1,3 @@
-"""Wrapper around HazyResearch's Manifest library."""
from typing import Any, Dict, List, Mapping, Optional
from pydantic import Extra, root_validator
@@ -8,7 +7,7 @@ from langchain.llms.base import LLM
class ManifestWrapper(LLM):
- """Wrapper around HazyResearch's Manifest library."""
+ """HazyResearch's Manifest library."""
client: Any #: :meta private:
llm_kwargs: Optional[Dict] = None
@@ -27,7 +26,7 @@ class ManifestWrapper(LLM):
if not isinstance(values["client"], Manifest):
raise ValueError
except ImportError:
- raise ValueError(
+ raise ImportError(
"Could not import manifest python package. "
"Please install it with `pip install manifest-ml`."
)
diff --git a/langchain/llms/mlflow_ai_gateway.py b/langchain/llms/mlflow_ai_gateway.py
index 1cf2b5221d..8ef5909678 100644
--- a/langchain/llms/mlflow_ai_gateway.py
+++ b/langchain/llms/mlflow_ai_gateway.py
@@ -9,13 +9,18 @@ from langchain.llms.base import LLM
class Params(BaseModel, extra=Extra.allow):
+ """Parameters for the MLflow AI Gateway LLM."""
+
temperature: float = 0.0
candidate_count: int = 1
+ """The number of candidates to return."""
stop: Optional[List[str]] = None
max_tokens: Optional[int] = None
class MlflowAIGateway(LLM):
+ """The MLflow AI Gateway models."""
+
route: str
gateway_uri: Optional[str] = None
params: Optional[Params] = None
diff --git a/langchain/llms/modal.py b/langchain/llms/modal.py
index 3f8aba97e3..bf03947bc5 100644
--- a/langchain/llms/modal.py
+++ b/langchain/llms/modal.py
@@ -1,4 +1,3 @@
-"""Wrapper around Modal API."""
import logging
from typing import Any, Dict, List, Mapping, Optional
@@ -13,7 +12,7 @@ logger = logging.getLogger(__name__)
class Modal(LLM):
- """Wrapper around Modal large language models.
+ """Modal large language models.
To use, you should have the ``modal-client`` python package installed.
diff --git a/langchain/llms/mosaicml.py b/langchain/llms/mosaicml.py
index de14f744ea..226b5c3b8b 100644
--- a/langchain/llms/mosaicml.py
+++ b/langchain/llms/mosaicml.py
@@ -1,4 +1,3 @@
-"""Wrapper around MosaicML APIs."""
from typing import Any, Dict, List, Mapping, Optional
import requests
@@ -28,7 +27,7 @@ PROMPT_FOR_GENERATION_FORMAT = """{intro}
class MosaicML(LLM):
- """Wrapper around MosaicML's LLM inference service.
+ """MosaicML LLM service.
To use, you should have the
environment variable ``MOSAICML_API_TOKEN`` set with your API token, or pass
diff --git a/langchain/llms/nlpcloud.py b/langchain/llms/nlpcloud.py
index aa2a62df1a..7c1b0c0acb 100644
--- a/langchain/llms/nlpcloud.py
+++ b/langchain/llms/nlpcloud.py
@@ -1,4 +1,3 @@
-"""Wrapper around NLPCloud APIs."""
from typing import Any, Dict, List, Mapping, Optional
from pydantic import Extra, root_validator
@@ -9,7 +8,7 @@ from langchain.utils import get_from_dict_or_env
class NLPCloud(LLM):
- """Wrapper around NLPCloud large language models.
+ """NLPCloud large language models.
To use, you should have the ``nlpcloud`` python package installed, and the
environment variable ``NLPCLOUD_API_KEY`` set with your API key.
diff --git a/langchain/llms/octoai_endpoint.py b/langchain/llms/octoai_endpoint.py
index d9e9076a0f..46c88d51ac 100644
--- a/langchain/llms/octoai_endpoint.py
+++ b/langchain/llms/octoai_endpoint.py
@@ -1,4 +1,3 @@
-"""Wrapper around OctoAI APIs."""
from typing import Any, Dict, List, Mapping, Optional
from pydantic import Extra, root_validator
@@ -10,7 +9,7 @@ from langchain.utils import get_from_dict_or_env
class OctoAIEndpoint(LLM):
- """Wrapper around OctoAI Inference Endpoints.
+ """OctoAI LLM Endpoints.
OctoAIEndpoint is a class to interact with OctoAI
Compute Service large language model endpoints.
diff --git a/langchain/llms/openai.py b/langchain/llms/openai.py
index dcdb2738a7..d86bab2141 100644
--- a/langchain/llms/openai.py
+++ b/langchain/llms/openai.py
@@ -1,4 +1,3 @@
-"""Wrapper around OpenAI APIs."""
from __future__ import annotations
import logging
@@ -105,7 +104,7 @@ async def acompletion_with_retry(
class BaseOpenAI(BaseLLM):
- """Wrapper around OpenAI large language models."""
+ """Base OpenAI large language model class."""
@property
def lc_secrets(self) -> Dict[str, str]:
@@ -579,7 +578,7 @@ class BaseOpenAI(BaseLLM):
class OpenAI(BaseOpenAI):
- """Wrapper around OpenAI large language models.
+ """OpenAI large language models.
To use, you should have the ``openai`` python package installed, and the
environment variable ``OPENAI_API_KEY`` set with your API key.
@@ -600,7 +599,7 @@ class OpenAI(BaseOpenAI):
class AzureOpenAI(BaseOpenAI):
- """Wrapper around Azure-specific OpenAI large language models.
+ """Azure-specific OpenAI large language models.
To use, you should have the ``openai`` python package installed, and the
environment variable ``OPENAI_API_KEY`` set with your API key.
@@ -655,7 +654,7 @@ class AzureOpenAI(BaseOpenAI):
class OpenAIChat(BaseLLM):
- """Wrapper around OpenAI Chat large language models.
+ """OpenAI Chat large language models.
To use, you should have the ``openai`` python package installed, and the
environment variable ``OPENAI_API_KEY`` set with your API key.
diff --git a/langchain/llms/openllm.py b/langchain/llms/openllm.py
index 3b08ded337..62b1dde03f 100644
--- a/langchain/llms/openllm.py
+++ b/langchain/llms/openllm.py
@@ -1,4 +1,3 @@
-"""Wrapper around OpenLLM APIs."""
from __future__ import annotations
import copy
@@ -46,7 +45,7 @@ logger = logging.getLogger(__name__)
class OpenLLM(LLM):
- """Wrapper for accessing OpenLLM, supporting both in-process model
+ """OpenLLM, supporting both in-process model
instance and remote OpenLLM servers.
To use, you should have the openllm library installed:
diff --git a/langchain/llms/openlm.py b/langchain/llms/openlm.py
index 451558194d..c77badaa3a 100644
--- a/langchain/llms/openlm.py
+++ b/langchain/llms/openlm.py
@@ -6,6 +6,8 @@ from langchain.llms.openai import BaseOpenAI
class OpenLM(BaseOpenAI):
+ """OpenLM models."""
+
@property
def _invocation_params(self) -> Dict[str, Any]:
return {**{"model": self.model_name}, **super()._invocation_params}
@@ -17,7 +19,7 @@ class OpenLM(BaseOpenAI):
values["client"] = openlm.Completion
except ImportError:
- raise ValueError(
+ raise ImportError(
"Could not import openlm python package. "
"Please install it with `pip install openlm`."
)
diff --git a/langchain/llms/petals.py b/langchain/llms/petals.py
index 84620b9e78..413437dc08 100644
--- a/langchain/llms/petals.py
+++ b/langchain/llms/petals.py
@@ -1,4 +1,3 @@
-"""Wrapper around Petals API."""
import logging
from typing import Any, Dict, List, Mapping, Optional
@@ -13,7 +12,7 @@ logger = logging.getLogger(__name__)
class Petals(LLM):
- """Wrapper around Petals Bloom models.
+ """Petals Bloom models.
To use, you should have the ``petals`` python package installed, and the
environment variable ``HUGGINGFACE_API_KEY`` set with your API key.
diff --git a/langchain/llms/pipelineai.py b/langchain/llms/pipelineai.py
index 67321c0ee5..b145cc4947 100644
--- a/langchain/llms/pipelineai.py
+++ b/langchain/llms/pipelineai.py
@@ -1,4 +1,3 @@
-"""Wrapper around Pipeline Cloud API."""
import logging
from typing import Any, Dict, List, Mapping, Optional
@@ -13,7 +12,7 @@ logger = logging.getLogger(__name__)
class PipelineAI(LLM, BaseModel):
- """Wrapper around PipelineAI large language models.
+ """PipelineAI large language models.
To use, you should have the ``pipeline-ai`` python package installed,
and the environment variable ``PIPELINE_API_KEY`` set with your API key.
diff --git a/langchain/llms/predictionguard.py b/langchain/llms/predictionguard.py
index b024a30fda..f91541508f 100644
--- a/langchain/llms/predictionguard.py
+++ b/langchain/llms/predictionguard.py
@@ -1,4 +1,3 @@
-"""Wrapper around Prediction Guard APIs."""
import logging
from typing import Any, Dict, List, Optional
@@ -13,7 +12,8 @@ logger = logging.getLogger(__name__)
class PredictionGuard(LLM):
- """Wrapper around Prediction Guard large language models.
+ """Prediction Guard large language models.
+
To use, you should have the ``predictionguard`` python package installed, and the
environment variable ``PREDICTIONGUARD_TOKEN`` set with your access token, or pass
it as a named parameter to the constructor. To use Prediction Guard's API along
diff --git a/langchain/llms/promptlayer_openai.py b/langchain/llms/promptlayer_openai.py
index 93176f2382..4e1089cc06 100644
--- a/langchain/llms/promptlayer_openai.py
+++ b/langchain/llms/promptlayer_openai.py
@@ -1,4 +1,3 @@
-"""PromptLayer wrapper."""
import datetime
from typing import Any, List, Optional
@@ -11,7 +10,7 @@ from langchain.schema import LLMResult
class PromptLayerOpenAI(OpenAI):
- """Wrapper around OpenAI large language models.
+ """PromptLayer OpenAI large language models.
To use, you should have the ``openai`` and ``promptlayer`` python
package installed, and the environment variable ``OPENAI_API_KEY``
diff --git a/langchain/llms/replicate.py b/langchain/llms/replicate.py
index d542022f22..9cc975ae92 100644
--- a/langchain/llms/replicate.py
+++ b/langchain/llms/replicate.py
@@ -1,4 +1,3 @@
-"""Wrapper around Replicate API."""
import logging
from typing import Any, Dict, List, Mapping, Optional
@@ -12,7 +11,7 @@ logger = logging.getLogger(__name__)
class Replicate(LLM):
- """Wrapper around Replicate models.
+ """Replicate models.
To use, you should have the ``replicate`` python package installed,
and the environment variable ``REPLICATE_API_TOKEN`` set with your API token.
diff --git a/langchain/llms/rwkv.py b/langchain/llms/rwkv.py
index b4d38244f7..6b717d4a12 100644
--- a/langchain/llms/rwkv.py
+++ b/langchain/llms/rwkv.py
@@ -1,4 +1,4 @@
-"""Wrapper for the RWKV model.
+"""RWKV models.
Based on https://github.com/saharNooby/rwkv.cpp/blob/master/rwkv/chat_with_bot.py
https://github.com/BlinkDL/ChatRWKV/blob/main/v2/chat.py
@@ -13,7 +13,7 @@ from langchain.llms.utils import enforce_stop_tokens
class RWKV(LLM, BaseModel):
- r"""Wrapper around RWKV language models.
+ """RWKV language models.
To use, you should have the ``rwkv`` python package installed, the
pre-trained model file, and the model's config information.
diff --git a/langchain/llms/sagemaker_endpoint.py b/langchain/llms/sagemaker_endpoint.py
index 91ac69d0eb..1e28435684 100644
--- a/langchain/llms/sagemaker_endpoint.py
+++ b/langchain/llms/sagemaker_endpoint.py
@@ -1,4 +1,4 @@
-"""Wrapper around Sagemaker InvokeEndpoint API."""
+"""Sagemaker InvokeEndpoint API."""
from abc import abstractmethod
from typing import Any, Dict, Generic, List, Mapping, Optional, TypeVar, Union
@@ -14,8 +14,9 @@ OUTPUT_TYPE = TypeVar("OUTPUT_TYPE", bound=Union[str, List[List[float]]])
class ContentHandlerBase(Generic[INPUT_TYPE, OUTPUT_TYPE]):
"""A handler class to transform input from LLM to a
- format that SageMaker endpoint expects. Similarly,
- the class also handles transforming output from the
+ format that SageMaker endpoint expects.
+
+ Similarly, the class handles transforming output from the
SageMaker endpoint to a format that LLM class expects.
"""
@@ -62,7 +63,7 @@ class LLMContentHandler(ContentHandlerBase[str, str]):
class SagemakerEndpoint(LLM):
- """Wrapper around custom Sagemaker Inference Endpoints.
+ """Sagemaker Inference Endpoint models.
To use, you must supply the endpoint name from your deployed
Sagemaker model & the region where it is deployed.
diff --git a/langchain/llms/self_hosted.py b/langchain/llms/self_hosted.py
index 0eaf8ec0a8..42d45c9c54 100644
--- a/langchain/llms/self_hosted.py
+++ b/langchain/llms/self_hosted.py
@@ -1,4 +1,3 @@
-"""Run model inference on self-hosted remote hardware."""
import importlib.util
import logging
import pickle
@@ -63,7 +62,7 @@ def _send_pipeline_to_device(pipeline: Any, device: int) -> Any:
class SelfHostedPipeline(LLM):
- """Run model inference on self-hosted remote hardware.
+ """Model inference on self-hosted remote hardware.
Supported hardware includes auto-launched instances on AWS, GCP, Azure,
and Lambda, as well as servers specified
diff --git a/langchain/llms/self_hosted_hugging_face.py b/langchain/llms/self_hosted_hugging_face.py
index e88d3fb935..2e55aaf1d2 100644
--- a/langchain/llms/self_hosted_hugging_face.py
+++ b/langchain/llms/self_hosted_hugging_face.py
@@ -1,4 +1,3 @@
-"""Wrapper around HuggingFace Pipeline API to run on self-hosted remote hardware."""
import importlib.util
import logging
from typing import Any, Callable, List, Mapping, Optional
@@ -112,7 +111,7 @@ def _load_transformer(
class SelfHostedHuggingFaceLLM(SelfHostedPipeline):
- """Wrapper around HuggingFace Pipeline API to run on self-hosted remote hardware.
+ """HuggingFace Pipeline API to run on self-hosted remote hardware.
Supported hardware includes auto-launched instances on AWS, GCP, Azure,
and Lambda, as well as servers specified
diff --git a/langchain/llms/stochasticai.py b/langchain/llms/stochasticai.py
index 3d1060b05e..391d9e8c40 100644
--- a/langchain/llms/stochasticai.py
+++ b/langchain/llms/stochasticai.py
@@ -1,4 +1,3 @@
-"""Wrapper around StochasticAI APIs."""
import logging
import time
from typing import Any, Dict, List, Mapping, Optional
@@ -15,7 +14,7 @@ logger = logging.getLogger(__name__)
class StochasticAI(LLM):
- """Wrapper around StochasticAI large language models.
+ """StochasticAI large language models.
To use, you should have the environment variable ``STOCHASTICAI_API_KEY``
set with your API key.
diff --git a/langchain/llms/textgen.py b/langchain/llms/textgen.py
index 7d428f0e28..4e4880b82a 100644
--- a/langchain/llms/textgen.py
+++ b/langchain/llms/textgen.py
@@ -1,4 +1,3 @@
-"""Wrapper around text-generation-webui."""
import logging
from typing import Any, Dict, List, Optional
@@ -12,7 +11,7 @@ logger = logging.getLogger(__name__)
class TextGen(LLM):
- """Wrapper around the text-generation-webui model.
+ """text-generation-webui models.
To use, you should have the text-generation-webui installed, a model loaded,
and --api added as a command-line option.
diff --git a/langchain/llms/tongyi.py b/langchain/llms/tongyi.py
index 39d407d274..7753213aea 100644
--- a/langchain/llms/tongyi.py
+++ b/langchain/llms/tongyi.py
@@ -1,4 +1,3 @@
-"""Wrapper around Cohere APIs."""
from __future__ import annotations
import logging
@@ -89,7 +88,7 @@ def stream_generate_with_retry(llm: Tongyi, **kwargs: Any) -> Any:
class Tongyi(LLM):
- """Wrapper around Tongyi Qwen large language models.
+ """Tongyi Qwen large language models.
To use, you should have the ``dashscope`` python package installed, and the
environment variable ``DASHSCOPE_API_KEY`` set with your API key, or pass
diff --git a/langchain/llms/utils.py b/langchain/llms/utils.py
index a42fd130ee..32fdb52eb3 100644
--- a/langchain/llms/utils.py
+++ b/langchain/llms/utils.py
@@ -1,4 +1,4 @@
-"""Common utility functions for working with LLM APIs."""
+"""Common utility functions for LLM APIs."""
import re
from typing import List
diff --git a/langchain/llms/vertexai.py b/langchain/llms/vertexai.py
index 312b3ae44b..da85f79edb 100644
--- a/langchain/llms/vertexai.py
+++ b/langchain/llms/vertexai.py
@@ -1,4 +1,3 @@
-"""Wrapper around Google VertexAI models."""
from __future__ import annotations
import asyncio
@@ -142,7 +141,7 @@ class _VertexAICommon(BaseModel):
class VertexAI(_VertexAICommon, LLM):
- """Wrapper around Google Vertex AI large language models."""
+ """Google Vertex AI large language models."""
model_name: str = "text-bison"
"The name of the Vertex AI large language model."
diff --git a/langchain/llms/writer.py b/langchain/llms/writer.py
index 1767d8b432..546d09b04c 100644
--- a/langchain/llms/writer.py
+++ b/langchain/llms/writer.py
@@ -1,4 +1,3 @@
-"""Wrapper around Writer APIs."""
from typing import Any, Dict, List, Mapping, Optional
import requests
@@ -11,7 +10,7 @@ from langchain.utils import get_from_dict_or_env
class Writer(LLM):
- """Wrapper around Writer large language models.
+ """Writer large language models.
To use, you should have the environment variable ``WRITER_API_KEY`` and
``WRITER_ORG_ID`` set with your API key and organization ID respectively.