이 가이드는 Cerebras chat models 시작하기에 대한 간단한 개요를 제공합니다. 모든 ChatCerebras 기능 및 구성에 대한 자세한 문서는 API reference를 참조하세요. Cerebras에서는 세계에서 가장 크고 빠른 AI 프로세서인 Wafer-Scale Engine-3 (WSE-3)를 개발했습니다. WSE-3로 구동되는 Cerebras CS-3 시스템은 비교할 수 없는 성능과 확장성으로 생성형 AI 학습 및 추론의 표준을 설정하는 새로운 클래스의 AI 슈퍼컴퓨터를 나타냅니다. Cerebras를 추론 제공자로 사용하면 다음을 수행할 수 있습니다:
  • AI 추론 워크로드에 대한 전례 없는 속도 달성
  • 높은 처리량으로 상업적 구축
  • 원활한 클러스터링 기술로 AI 워크로드를 손쉽게 확장
우리의 CS-3 시스템은 빠르고 쉽게 클러스터링되어 세계에서 가장 큰 AI 슈퍼컴퓨터를 만들 수 있으며, 가장 큰 모델을 배치하고 실행하는 것을 간단하게 만듭니다. 주요 기업, 연구 기관 및 정부는 이미 Cerebras 솔루션을 사용하여 독점 모델을 개발하고 인기 있는 오픈 소스 모델을 학습하고 있습니다. Cerebras의 힘을 경험하고 싶으신가요? 더 많은 리소스를 보려면 웹사이트를 확인하고 Cerebras Cloud 또는 온프레미스 배포를 통해 우리 기술에 액세스하는 옵션을 탐색하세요! Cerebras Cloud에 대한 자세한 내용은 cloud.cerebras.ai를 방문하세요. API reference는 inference-docs.cerebras.ai에서 확인할 수 있습니다.

Overview

Integration details

ClassPackageLocalSerializableJS supportDownloadsVersion
ChatCerebraslangchain-cerebrasbetaPyPI - DownloadsPyPI - Version

Model features

Tool callingStructured outputJSON modeImage inputAudio inputVideo inputToken-level streamingNative asyncToken usageLogprobs

Setup

pip install langchain-cerebras

Credentials

cloud.cerebras.ai에서 API Key를 받아 환경 변수에 추가하세요:
export CEREBRAS_API_KEY="your-api-key-here"
import getpass
import os

if "CEREBRAS_API_KEY" not in os.environ:
    os.environ["CEREBRAS_API_KEY"] = getpass.getpass("Enter your Cerebras API key: ")
Enter your Cerebras API key:  ········
모델 호출의 자동 추적을 활성화하려면 LangSmith API key를 설정하세요:
os.environ["LANGSMITH_API_KEY"] = getpass.getpass("Enter your LangSmith API key: ")
os.environ["LANGSMITH_TRACING"] = "true"

Installation

LangChain Cerebras integration은 langchain-cerebras 패키지에 있습니다:
pip install -qU langchain-cerebras

Instantiation

이제 모델 객체를 인스턴스화하고 chat completion을 생성할 수 있습니다:
from langchain_cerebras import ChatCerebras

llm = ChatCerebras(
    model="llama-3.3-70b",
    # other params...
)

Invocation

messages = [
    (
        "system",
        "You are a helpful assistant that translates English to French. Translate the user sentence.",
    ),
    ("human", "I love programming."),
]
ai_msg = llm.invoke(messages)
ai_msg
AIMessage(content='Je adore le programmation.', response_metadata={'token_usage': {'completion_tokens': 7, 'prompt_tokens': 35, 'total_tokens': 42}, 'model_name': 'llama3-8b-8192', 'system_fingerprint': 'fp_be27ec77ff', 'finish_reason': 'stop'}, id='run-e5d66faf-019c-4ac6-9265-71093b13202d-0', usage_metadata={'input_tokens': 35, 'output_tokens': 7, 'total_tokens': 42})

Streaming

from langchain_cerebras import ChatCerebras
from langchain_core.prompts import ChatPromptTemplate

llm = ChatCerebras(
    model="llama-3.3-70b",
    # other params...
)

system = "You are an expert on animals who must answer questions in a manner that a 5 year old can understand."
human = "I want to learn more about this animal: {animal}"
prompt = ChatPromptTemplate.from_messages([("system", system), ("human", human)])

chain = prompt | llm

for chunk in chain.stream({"animal": "Lion"}):
    print(chunk.content, end="", flush=True)
OH BOY! Let me tell you all about LIONS!

Lions are the kings of the jungle! They're really big and have beautiful, fluffy manes around their necks. The mane is like a big, golden crown!

Lions live in groups called prides. A pride is like a big family, and the lionesses (that's what we call the female lions) take care of the babies. The lionesses are like the mommies, and they teach the babies how to hunt and play.

Lions are very good at hunting. They work together to catch their food, like zebras and antelopes. They're super fast and can run really, really fast!

But lions are also very sleepy. They like to take long naps in the sun, and they can sleep for up to 20 hours a day! Can you imagine sleeping that much?

Lions are also very loud. They roar really loudly to talk to each other. It's like they're saying, "ROAR! I'm the king of the jungle!"

And guess what? Lions are very social. They like to play and cuddle with each other. They're like big, furry teddy bears!

So, that's lions! Aren't they just the coolest?

Async

from langchain_cerebras import ChatCerebras
from langchain_core.prompts import ChatPromptTemplate

llm = ChatCerebras(
    model="llama-3.3-70b",
    # other params...
)

prompt = ChatPromptTemplate.from_messages(
    [
        (
            "human",
            "Let's play a game of opposites. What's the opposite of {topic}? Just give me the answer with no extra input.",
        )
    ]
)
chain = prompt | llm
await chain.ainvoke({"topic": "fire"})
AIMessage(content='Ice', response_metadata={'token_usage': {'completion_tokens': 2, 'prompt_tokens': 36, 'total_tokens': 38}, 'model_name': 'llama3-8b-8192', 'system_fingerprint': 'fp_be27ec77ff', 'finish_reason': 'stop'}, id='run-7434bdde-1bec-44cf-827b-8d978071dfe8-0', usage_metadata={'input_tokens': 36, 'output_tokens': 2, 'total_tokens': 38})

Async Streaming

from langchain_cerebras import ChatCerebras
from langchain_core.prompts import ChatPromptTemplate

llm = ChatCerebras(
    model="llama-3.3-70b",
    # other params...
)

prompt = ChatPromptTemplate.from_messages(
    [
        (
            "human",
            "Write a long convoluted story about {subject}. I want {num_paragraphs} paragraphs.",
        )
    ]
)
chain = prompt | llm

async for chunk in chain.astream({"num_paragraphs": 3, "subject": "blackholes"}):
    print(chunk.content, end="", flush=True)
In the distant reaches of the cosmos, there existed a peculiar phenomenon known as the "Eclipse of Eternity," a swirling vortex of darkness that had been shrouded in mystery for eons. It was said that this blackhole, born from the cataclysmic collision of two ancient stars, had been slowly devouring the fabric of space-time itself, warping the very essence of reality. As the celestial bodies of the galaxy danced around it, they began to notice a strange, almost imperceptible distortion in the fabric of space, as if the blackhole's gravitational pull was exerting an influence on the very course of events itself.

As the centuries passed, astronomers from across the galaxy became increasingly fascinated by the Eclipse of Eternity, pouring over ancient texts and scouring the cosmos for any hint of its secrets. One such scholar, a brilliant and reclusive astrophysicist named Dr. Elara Vex, became obsessed with unraveling the mysteries of the blackhole. She spent years pouring over ancient texts, deciphering cryptic messages and hidden codes that hinted at the existence of a long-lost civilization that had once thrived in the heart of the blackhole itself. According to legend, this ancient civilization had possessed knowledge of the cosmos that was beyond human comprehension, and had used their mastery of the universe to create the Eclipse of Eternity as a gateway to other dimensions.

As Dr. Vex delved deeper into her research, she began to experience strange and vivid dreams, visions that seemed to transport her to the very heart of the blackhole itself. In these dreams, she saw ancient beings, their faces twisted in agony as they were consumed by the void. She saw stars and galaxies, their light warped and distorted by the blackhole's gravitational pull. And she saw the Eclipse of Eternity itself, its swirling vortex of darkness pulsing with an otherworldly energy that seemed to be calling to her. As the dreams grew more vivid and more frequent, Dr. Vex became convinced that she was being drawn into the heart of the blackhole, and that the secrets of the universe lay waiting for her on the other side.

API reference

모든 ChatCerebras 기능 및 구성에 대한 자세한 문서는 API reference를 참조하세요: python.langchain.com/api_reference/cerebras/chat_models/langchain_cerebras.chat_models.ChatCerebras.html#
Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.
I