Source code for langchain.llms.baidu_qianfan_endpoint
from __future__ import annotations
import logging
from typing import (
    Any,
    AsyncIterator,
    Dict,
    Iterator,
    List,
    Optional,
)
from langchain.callbacks.manager import (
    AsyncCallbackManagerForLLMRun,
    CallbackManagerForLLMRun,
)
from langchain.llms.base import LLM
from langchain.pydantic_v1 import Field, root_validator
from langchain.schema.output import GenerationChunk
from langchain.utils import get_from_dict_or_env
logger = logging.getLogger(__name__)
[docs]class QianfanLLMEndpoint(LLM):
    """Baidu Qianfan hosted open source or customized models.
    To use, you should have the ``qianfan`` python package installed, and
    the environment variable ``qianfan_ak`` and ``qianfan_sk`` set with
    your API key and Secret Key.
    ak, sk are required parameters which you could get from
    https://cloud.baidu.com/product/wenxinworkshop
    Example:
        .. code-block:: python
            from langchain.llms import QianfanLLMEndpoint
            qianfan_model = QianfanLLMEndpoint(model="ERNIE-Bot",
                endpoint="your_endpoint", qianfan_ak="your_ak", qianfan_sk="your_sk")
    """
    model_kwargs: Dict[str, Any] = Field(default_factory=dict)
    client: Any
    qianfan_ak: Optional[str] = None
    qianfan_sk: Optional[str] = None
    streaming: Optional[bool] = False
    """Whether to stream the results or not."""
    model: str = "ERNIE-Bot-turbo"
    """Model name.