Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
OurBuilding Ambient Agents with LangGraph course is now available on LangChain Academy!
Open In ColabOpen on GitHub

SparkLLM Chat

SparkLLM chat models API by iFlyTek. For more information, seeiFlyTek Open Platform.

Basic use

"""For basic init and call"""
from langchain_community.chat_modelsimport ChatSparkLLM
from langchain_core.messagesimport HumanMessage

chat= ChatSparkLLM(
spark_app_id="<app_id>", spark_api_key="<api_key>", spark_api_secret="<api_secret>"
)
message= HumanMessage(content="Hello")
chat([message])
API Reference:ChatSparkLLM |HumanMessage
AIMessage(content='Hello! How can I help you today?')
  • Get SparkLLM's app_id, api_key and api_secret fromiFlyTek SparkLLM API Console (for more info, seeiFlyTek SparkLLM Intro ), then set environment variablesIFLYTEK_SPARK_APP_ID,IFLYTEK_SPARK_API_KEY andIFLYTEK_SPARK_API_SECRET or pass parameters when creatingChatSparkLLM as the demo above.

For ChatSparkLLM with Streaming

chat= ChatSparkLLM(
spark_app_id="<app_id>",
spark_api_key="<api_key>",
spark_api_secret="<api_secret>",
streaming=True,
)
for chunkin chat.stream("Hello!"):
print(chunk.content, end="")
Hello! How can I help you today?

For v2

"""For basic init and call"""
from langchain_community.chat_modelsimport ChatSparkLLM
from langchain_core.messagesimport HumanMessage

chat= ChatSparkLLM(
spark_app_id="<app_id>",
spark_api_key="<api_key>",
spark_api_secret="<api_secret>",
spark_api_url="wss://spark-api.xf-yun.com/v2.1/chat",
spark_llm_domain="generalv2",
)
message= HumanMessage(content="Hello")
chat([message])
API Reference:ChatSparkLLM |HumanMessage

Related


[8]ページ先頭

©2009-2025 Movatter.jp