跳至主要內容

SparkLLM

SparkLLM 是由 iFLYTEK 獨立開發的大規模認知模型。它透過學習大量的文字、程式碼和圖像,擁有跨領域知識和語言理解能力。它可以根據自然對話來理解和執行任務。

先決條件

  • iFlyTek SparkLLM API Console取得 SparkLLM 的 app_id、api_key 和 api_secret(更多資訊,請參閱iFlyTek SparkLLM Intro),然後設定環境變數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 參考資料: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?

此頁面是否有幫助?