ChatGroq 통합
ChatGroq 통합
LangChain JavaScript로 ChatGroq 채팅 모델과 통합하는 방법을 안내할게요.
출처: 문서
본문
Groq는 LPU™ AI 추론 기술로 구동되는 빠른 AI 추론을 제공해요.
사용 가능한 모델 목록은 Groq 모델 문서를 참고하세요.
이 페이지는 Groq 채팅 모델을 시작하는 데 도움을 줘요. 모든 ChatGroq 기능과 구성에 대한 자세한 문서는 API 레퍼런스를 참고하세요.
개요
통합 세부 정보
| 클래스 | 패키지 | Serializable | PY 지원 | Downloads | Version |
|---|---|---|---|---|---|
ChatGroq |
@langchain/groq |
❌ | ✅ |
모델 기능
아래 표 헤더의 링크에서 특정 기능을 사용하는 방법에 대한 가이드를 확인할 수 있어요.
| Tool calling | Structured output | Image input | Audio input | Video input | Token-level streaming | Token usage | Logprobs |
|---|---|---|---|---|---|---|---|
| ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ |
설정
ChatGroq 모델에 접근하려면 Groq 계정을 만들고 API 키를 받은 뒤 @langchain/groq 통합 패키지를 설치해야 해요.
자격 증명
Groq API를 사용하려면 Groq 콘솔에서 API 키를 생성하세요. 그런 다음 터미널에서 API 키를 환경 변수로 설정할 수 있어요:
export GROQ_API_KEY="your-api-key"
모델 호출의 자동 추적(tracing)을 원한다면 아래 주석을 해제해 LangSmith API 키를 설정할 수도 있어요:
# export LANGSMITH_TRACING="true"
# export LANGSMITH_API_KEY="your-api-key"
설치
LangChain ChatGroq 통합은 @langchain/groq 패키지에 있어요:
yarn add @langchain/groq @langchain/core
pnpm add @langchain/groq @langchain/core
인스턴스 생성
이제 모델 객체를 생성하고 채팅 완성을 생성할 수 있어요:
import { ChatGroq } from "@langchain/groq"
const llm = new ChatGroq({
model: "openai/gpt-oss-120b",
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 {
"content": "I enjoy programming. (The French translation is: \"J'aime programmer.\")\n\nNote: I chose to translate \"I love programming\" as \"J'aime programmer\" instead of \"Je suis amoureux de programmer\" because the latter has a romantic connotation that is not present in the original English sentence.",
"additional_kwargs": {},
"response_metadata": {
"tokenUsage": {
"completionTokens": 73,
"promptTokens": 31,
"totalTokens": 104
},
"finish_reason": "stop"
},
"tool_calls": [],
"invalid_tool_calls": []
}
console.log(aiMsg.content)
I enjoy programming. (The French translation is: "J'aime programmer.")
Note: I chose to translate "I love programming" as "J'aime programmer" instead of "Je suis amoureux de programmer" because the latter has a romantic connotation that is not present in the original English sentence.
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 * 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: '{\n"result": 6\n}',
aiBindMsg: '{\n"result": 6\n}'
}
API 레퍼런스
모든 ChatGroq 기능과 구성에 대한 자세한 문서는 API 레퍼런스를 참고하세요.
더 알아보기
- 이 문서를 MCP로 연결하면 Claude, VSCode 등에서 실시간 답변을 받을 수 있어요.
- GitHub에서 이 페이지 편집하기 또는 이슈 제출하기.