# QianfanLLMEndpoint

> **Class** in `langchain_community`

📖 [View in docs](https://reference.langchain.com/python/langchain-community/llms/baidu_qianfan_endpoint/QianfanLLMEndpoint)

Baidu Qianfan completion model integration.

## Signature

```python
QianfanLLMEndpoint()
```

## Description

**Setup:**

Install ``qianfan`` and set environment variables ``QIANFAN_AK``, ``QIANFAN_SK``.

.. code-block:: bash

    pip install qianfan
    export QIANFAN_AK="your-api-key"
    export QIANFAN_SK="your-secret_key"

Key init args — completion params:
    model: str
        Name of Qianfan model to use.
    temperature: Optional[float]
        Sampling temperature.
    endpoint: Optional[str]
        Endpoint of the Qianfan LLM
    top_p: Optional[float]
        What probability mass to use.

Key init args — client params:
    timeout: Optional[int]
        Timeout for requests.
    api_key: Optional[str]
        Qianfan API KEY. If not passed in will be read from env var QIANFAN_AK.
    secret_key: Optional[str]
        Qianfan SECRET KEY. If not passed in will be read from env var QIANFAN_SK.

See full list of supported init args and their descriptions in the params section.

**Instantiate:**

.. code-block:: python

from langchain_community.llms import QianfanLLMEndpoint

llm = QianfanLLMEndpoint(
    model="ERNIE-3.5-8K",
    # api_key="...",
    # secret_key="...",
    # other params...
)

**Invoke:**

.. code-block:: python

    input_text = "用50个字左右阐述，生命的意义在于"
    llm.invoke(input_text)

.. code-block:: python

    '生命的意义在于体验、成长、爱与被爱、贡献与传承，以及对未知的勇敢探索与自我超越。'

**Stream:**

.. code-block:: python

    for chunk in llm.stream(input_text):
        print(chunk)

.. code-block:: python

    生命的意义 | 在于不断探索 | 与成长 | ，实现 | 自我价值，| 给予爱 | 并接受 | 爱， | 在经历 | 中感悟 | ，让 | 短暂的存在 | 绽放出无限 | 的光彩 | 与温暖 | 。

.. code-block:: python

    stream = llm.stream(input_text)
    full = next(stream)
    for chunk in stream:
        full += chunk
    full

.. code-block::

    '生命的意义在于探索、成长、爱与被爱、贡献价值、体验世界之美，以及在有限的时间里追求内心的平和与幸福。'

**Async:**

.. code-block:: python

    await llm.ainvoke(input_text)

    # stream:
    # async for chunk in llm.astream(input_text):
    #    print(chunk)

    # batch:
    # await llm.abatch([input_text])

.. code-block:: python

    '生命的意义在于探索、成长、爱与被爱、贡献社会，在有限的时间里追寻无限的可能，实现自我价值，让生活充满色彩与意义。'

## Extends

- `LLM`

## Properties

- `init_kwargs`
- `model_kwargs`
- `client`
- `qianfan_ak`
- `qianfan_sk`
- `streaming`
- `model`
- `endpoint`
- `request_timeout`
- `top_p`
- `temperature`
- `penalty_score`

## Methods

- [`validate_environment()`](https://reference.langchain.com/python/langchain-community/llms/baidu_qianfan_endpoint/QianfanLLMEndpoint/validate_environment)

---

[View source on GitHub](https://github.com/langchain-ai/langchain-community/blob/4b280287bd55b99b44db2dd849f02d66c89534d5/libs/community/langchain_community/llms/baidu_qianfan_endpoint.py#L25)