ChatXAI 통합

ChatXAI 통합

LangChain JavaScript로 ChatXAI 채팅 모델과 통합하는 방법을 안내할게요.

출처: 문서

본문

This page documents Grok models from [xAI](https://docs.x.ai/docs/overview). Do not confuse xAI with [Groq](https://console.groq.com/docs/overview), a separate inference provider. See the [Groq integration](/oss/javascript/integrations/chat/groq).

xAI는 Grok 채팅 모델을 개발해요. 사용 가능한 모델 ID는 xAI 모델 문서를 참고하세요.

이 가이드는 ChatXAI 채팅 모델을 시작하는 데 도움을 줘요. 모든 ChatXAI 기능과 구성에 대한 자세한 문서는 API 레퍼런스를 참고하세요.

개요

통합 세부 정보

클래스 패키지 Serializable PY 지원 Downloads Version
ChatXAI @langchain/xai NPM - Downloads NPM - Version

모델 기능

아래 표 헤더의 링크에서 특정 기능을 사용하는 방법에 대한 가이드를 확인할 수 있어요.

Tool calling Structured output Image input Audio input Video input Token-level streaming Token usage Logprobs

설정

ChatXAI 모델에 접근하려면 xAI 계정을 만들고 API 키를 받은@langchain/xai 통합 패키지를 설치해야 해요.

자격 증명

xAI 웹사이트에서 가입하고 API 키를 생성하세요. XAI_API_KEY 환경 변수를 설정하세요:

export XAI_API_KEY="your-api-key"

모델 호출의 자동 추적(tracing)을 원한다면 아래 주석을 해제해 LangSmith API 키를 설정할 수도 있어요:

# export LANGSMITH_TRACING="true"
# export LANGSMITH_API_KEY="your-api-key"

설치

LangChain ChatXAI 통합은 @langchain/xai 패키지에 있어요:

```bash npm theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}} npm install @langchain/xai @langchain/core ```
yarn add @langchain/xai @langchain/core
pnpm add @langchain/xai @langchain/core

인스턴스 생성

이제 모델 객체를 생성하고 채팅 완성을 생성할 수 있어요:

import { ChatXAI } from "@langchain/xai";

const llm = new ChatXAI({
    model: "grok-3-fast",
    temperature: 0,
    maxTokens: undefined,
    maxRetries: 2,
    // other params...
})

호출

const aiMsg = await llm.invoke([
    [
      "system",
      "You are a helpful assistant that translates English to French. Translate the user sentence.",
    ],
    ["human", "I love programming."],
])
console.log(aiMsg)
AIMessage {
  "id": "71d7e3d8-30dd-472c-8038-b6b283dcee63",
  "content": "J'adore programmer.",
  "additional_kwargs": {},
  "response_metadata": {
    "tokenUsage": {
      "promptTokens": 30,
      "completionTokens": 6,
      "totalTokens": 36
    },
    "finish_reason": "stop",
    "usage": {
      "prompt_tokens": 30,
      "completion_tokens": 6,
      "total_tokens": 36
    },
    "system_fingerprint": "fp_3e3898d4ce"
  },
  "tool_calls": [],
  "invalid_tool_calls": [],
  "usage_metadata": {
    "output_tokens": 6,
    "input_tokens": 30,
    "total_tokens": 36,
    "input_token_details": {},
    "output_token_details": {}
  }
}
console.log(aiMsg.content)
J'adore programmer.

API 레퍼런스

모든 ChatXAI 기능과 구성에 대한 자세한 문서는 API 레퍼런스를 참고하세요.


[Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers. [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/oss/javascript/integrations/chat/xai.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).

더 알아보기