# SparkLLM

> **Class** in `langchain_community`

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

iFlyTek Spark completion model integration.

## Signature

```python
SparkLLM()
```

## Description

**Setup:**

To use, you should set environment variables ``IFLYTEK_SPARK_APP_ID``,
``IFLYTEK_SPARK_API_KEY`` and ``IFLYTEK_SPARK_API_SECRET``.

.. code-block:: bash

        export IFLYTEK_SPARK_APP_ID="your-app-id"
        export IFLYTEK_SPARK_API_KEY="your-api-key"
        export IFLYTEK_SPARK_API_SECRET="your-api-secret"

Key init args — completion params:
    model: Optional[str]
        Name of IFLYTEK SPARK model to use.
    temperature: Optional[float]
        Sampling temperature.
    top_k: Optional[float]
        What search sampling control to use.
    streaming: Optional[bool]
         Whether to stream the results or not.

Key init args — client params:
    app_id: Optional[str]
        IFLYTEK SPARK API KEY. Automatically inferred from env var `IFLYTEK_SPARK_APP_ID` if not provided.
    api_key: Optional[str]
        IFLYTEK SPARK API KEY. If not passed in will be read from env var IFLYTEK_SPARK_API_KEY.
    api_secret: Optional[str]
        IFLYTEK SPARK API SECRET. If not passed in will be read from env var IFLYTEK_SPARK_API_SECRET.
    api_url: Optional[str]
        Base URL for API requests.
    timeout: Optional[int]
        Timeout for requests.

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

**Instantiate:**

.. code-block:: python

from langchain_community.llms import SparkLLM

llm = SparkLLM(
    app_id="your-app-id",
    api_key="your-api_key",
    api_secret="your-api-secret",
    # model='Spark4.0 Ultra',
    # temperature=...,
    # 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

    生命 | 的意义在于 | 不断探索和 | 实现个人潜能，通过 | 学习 | 、成长和对社会 | 的贡献，追求内心的满足和幸福。

**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

- `client`
- `spark_app_id`
- `spark_api_key`
- `spark_api_secret`
- `spark_api_url`
- `spark_llm_domain`
- `spark_user_id`
- `streaming`
- `request_timeout`
- `temperature`
- `top_k`
- `model_kwargs`

## Methods

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

---

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