ChatCerebras 통합
ChatCerebras 통합
LangChain JavaScript로 ChatCerebras 채팅 모델과 통합하는 방법을 안내할게요.
출처: 문서
본문
Cerebras는 속도에 중점을 두고 오픈소스 모델을 서비스하는 모델 제공자예요. Wafer-Scale Engine-3 (WSE-3)로 구동되는 Cerebras CS-3 시스템은 탁월한 성능과 확장성으로 생성형 AI 학습과 추론의 기준을 세우는 새로운 종류의 AI 슈퍼컴퓨터를 대표해요.
Cerebras를 추론 제공자로 사용하면 다음과 같은 이점이 있어요:
- AI 추론 워크로드에서 전례 없는 속도를 달성
- 높은 처리량으로 상업적으로 구축
- 원활한 클러스터링 기술로 AI 워크로드를 쉽게 확장
CS-3 시스템은 세계 최대의 AI 슈퍼컴퓨터를 만들기 위해 빠르고 쉽게 클러스터링될 수 있어서, 대규모 모델을 배치하고 실행하는 것이 간단해져요. 선도적인 기업, 연구 기관, 정부는 이미 Cerebras 솔루션을 사용해 독점 모델을 개발하고 인기 있는 오픈소스 모델을 학습하고 있어요.
이 문서는 ChatCerebras 채팅 모델을 시작하는 데 도움을 줘요. 모든 ChatCerebras 기능과 구성에 대한 자세한 문서는 API 레퍼런스를 참고하세요.
개요
통합 세부 정보
| 클래스 | 패키지 | Serializable | PY 지원 | Downloads | Version |
|---|---|---|---|---|---|
ChatCerebras |
@langchain/cerebras |
❌ | ✅ |
모델 기능
아래 표 헤더의 링크에서 특정 기능을 사용하는 방법에 대한 가이드를 확인할 수 있어요.
| Tool calling | Structured output | Image input | Audio input | Video input | Token-level streaming | Token usage | Logprobs |
|---|---|---|---|---|---|---|---|
| ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ |
설정
ChatCerebras 모델에 접근하려면 Cerebras 계정을 만들고 API 키를 받은 뒤 @langchain/cerebras 통합 패키지를 설치해야 해요.
자격 증명
cloud.cerebras.ai에서 API 키를 받아 환경 변수에 추가하세요:
export CEREBRAS_API_KEY="your-api-key"
모델 호출의 자동 추적(tracing)을 원한다면 아래 주석을 해제해 LangSmith API 키를 설정할 수도 있어요:
# export LANGSMITH_TRACING="true"
# export LANGSMITH_API_KEY="your-api-key"
설치
LangChain ChatCerebras 통합은 @langchain/cerebras 패키지에 있어요:
yarn add @langchain/cerebras @langchain/core
pnpm add @langchain/cerebras @langchain/core
인스턴스 생성
이제 모델 객체를 생성하고 채팅 완성을 생성할 수 있어요:
import { ChatCerebras } from "@langchain/cerebras"
const llm = new ChatCerebras({
model: "llama-3.3-70b",
temperature: 0,
maxTokens: undefined,
maxRetries: 2,
// other params...
})
호출
const aiMsg = await llm.invoke([
{
role: "system",
content: "You are a helpful assistant that translates English to French. Translate the user sentence.",
},
{ role: "user", content: "I love programming." },
])
aiMsg
AIMessage {
"id": "run-17c7d62d-67ac-4677-b33a-18298fc85e35",
"content": "J'adore la programmation.",
"additional_kwargs": {},
"response_metadata": {
"id": "chatcmpl-2d1e2de5-4239-46fb-af2a-6200d89d7dde",
"created": 1735785598,
"model": "llama-3.3-70b",
"system_fingerprint": "fp_2e2a2a083c",
"object": "chat.completion",
"time_info": {
"queue_time": 0.00009063,
"prompt_time": 0.002163031,
"completion_time": 0.012339628,
"total_time": 0.01640915870666504,
"created": 1735785598
}
},
"tool_calls": [],
"invalid_tool_calls": [],
"usage_metadata": {
"input_tokens": 55,
"output_tokens": 9,
"total_tokens": 64
}
}
console.log(aiMsg.content)
J'adore la programmation.
JSON 호출
const messages = [
{
role: "system",
content: "You are a math tutor that handles math exercises and makes output in json in format { result: number }.",
},
{ role: "user", content: "2 + 2" },
];
const aiInvokeMsg = await llm.invoke(messages, { response_format: { type: "json_object" } });
// if you want not to pass response_format in every invoke, you can bind it to the instance
const llmWithResponseFormat = llm.bind({ response_format: { type: "json_object" } });
const aiBindMsg = await llmWithResponseFormat.invoke(messages);
// they are the same
console.log({ aiInvokeMsgContent: aiInvokeMsg.content, aiBindMsg: aiBindMsg.content });
{ aiInvokeMsgContent: '{"result":4}', aiBindMsg: '{"result":4}' }
API 레퍼런스
모든 ChatCerebras 기능과 구성에 대한 자세한 문서는 API 레퍼런스를 참고하세요.
더 알아보기
- 이 문서를 MCP로 연결하면 Claude, VSCode 등에서 실시간 답변을 받을 수 있어요.
- GitHub에서 이 페이지 편집하기 또는 이슈 제출하기.