mirror of
https://github.com/hwchase17/langchain.git
synced 2026-06-09 10:17:00 +00:00
https://docs.x.ai/docs/guides/structured-outputs Interface appears identical to OpenAI's. ```python from langchain.chat_models import init_chat_model from pydantic import BaseModel class Joke(BaseModel): setup: str punchline: str llm = init_chat_model("xai:grok-2").with_structured_output( Joke, method="json_schema" ) llm.invoke("Tell me a joke about cats.") ```
langchain-xai
This package contains the LangChain integrations for xAI through their APIs.
Installation and Setup
- Install the LangChain partner package
pip install -U langchain-xai
- Get your xAI api key from the xAI Dashboard and set it as an environment variable (
XAI_API_KEY)
Chat Completions
This package contains the ChatXAI class, which is the recommended way to interface with xAI chat models.