Skip to main content
Open In ColabOpen on GitHub

SparkLLM

SparkLLM 是由科大讯飞独立开发的大规模认知模型。 它通过学习大量的文本、代码和图像,具备跨领域的知识和语言理解能力。 它能够理解并基于自然对话执行任务。

先决条件

  • iFlyTek SparkLLM API控制台获取SparkLLM的app_id、api_key和api_secret(更多信息,请参见iFlyTek SparkLLM介绍),然后设置环境变量IFLYTEK_SPARK_APP_IDIFLYTEK_SPARK_API_KEYIFLYTEK_SPARK_API_SECRET或在创建ChatSparkLLM时传递参数,如上所示。

使用 SparkLLM

import os

os.environ["IFLYTEK_SPARK_APP_ID"] = "app_id"
os.environ["IFLYTEK_SPARK_API_KEY"] = "api_key"
os.environ["IFLYTEK_SPARK_API_SECRET"] = "api_secret"
from langchain_community.llms import SparkLLM

# Load the model
llm = SparkLLM()

res = llm.invoke("What's your name?")
print(res)
API Reference:SparkLLM
/Users/liugddx/code/langchain/libs/core/langchain_core/_api/deprecation.py:117: LangChainDeprecationWarning: The function `__call__` was deprecated in LangChain 0.1.7 and will be removed in 0.2.0. Use invoke instead.
warn_deprecated(
``````output
My name is iFLYTEK Spark. How can I assist you today?
res = llm.generate(prompts=["hello!"])
res
LLMResult(generations=[[Generation(text='Hello! How can I assist you today?')]], llm_output=None, run=[RunInfo(run_id=UUID('d8cdcd41-a698-4cbf-a28d-e74f9cd2037b'))])
for res in llm.stream("foo:"):
print(res)
Hello! How can I assist you today?

这个页面有帮助吗?