Skip to main content
Open In ColabOpen on GitHub

xAI

xAI 提供了一个API来与Grok模型进行交互。

本示例介绍了如何使用LangChain与xAI模型进行交互。

安装

%pip install --upgrade langchain-xai

环境

要使用xAI,您需要创建一个API密钥。API密钥可以作为初始化参数xai_api_key传递,或者设置为环境变量XAI_API_KEY

示例

# Querying chat models with xAI

from langchain_xai import ChatXAI

chat = ChatXAI(
# xai_api_key="YOUR_API_KEY",
model="grok-beta",
)

# stream the response back from the model
for m in chat.stream("Tell me fun things to do in NYC"):
print(m.content, end="", flush=True)

# if you don't want to do streaming, you can use the invoke method
# chat.invoke("Tell me fun things to do in NYC")

这个页面有帮助吗?