Skip to main content
iFlyTek의 SparkLLM chat models API입니다. 자세한 내용은 iFlyTek Open Platform을 참조하세요.

기본 사용법

"""For basic init and call"""
from langchain_community.chat_models import ChatSparkLLM
from langchain.messages import HumanMessage

chat = ChatSparkLLM(
    spark_app_id="<app_id>", spark_api_key="<api_key>", spark_api_secret="<api_secret>"
)
message = HumanMessage(content="Hello")
chat([message])
AIMessage(content='Hello! How can I help you today?')
  • SparkLLM의 app_id, api_key 및 api_secret은 iFlyTek SparkLLM API Console에서 발급받을 수 있습니다 (자세한 내용은 iFlyTek SparkLLM Intro 참조). 발급받은 후 환경 변수 IFLYTEK_SPARK_APP_ID, IFLYTEK_SPARK_API_KEY, IFLYTEK_SPARK_API_SECRET을 설정하거나 위 예제처럼 ChatSparkLLM 생성 시 파라미터로 전달하세요.

ChatSparkLLM 스트리밍 사용

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

v2 사용

"""For basic init and call"""
from langchain_community.chat_models import ChatSparkLLM
from langchain.messages import 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])

Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.
I