Skip to content
LangChain4j 文档版本 1.22.0 源快照 21fd1f78 更新于 2026-10-14

ChatGLM

https://github.com/THUDM/ChatGLM-6B

ChatGLM 是由清华大学发布的一款开源双语对话语言模型。

对于 ChatGLM2、ChatGLM3 和 GLM4,它们的 API 与 OpenAI 兼容。你可以使用 langchain4j-zhipu-ai,或使用 langchain4j-open-ai。

Maven 依赖

NOTE

自 1.0.0-alpha1 起,langchain4j-chatglm 已迁移至 langchain4j-community,并更名为 langchain4j-community-chatglm。

在 1.0.0-alpha1 之前:

xml
<dependency>
    <groupId>dev.langchain4j</groupId>
    <artifactId>langchain4j-chatglm</artifactId>
    <version>${previous version here}</version>
</dependency>

1.0.0-alpha1 及更高版本:

xml
<dependency>
    <groupId>dev.langchain4j</groupId>
    <artifactId>langchain4j-community-chatglm</artifactId>
    <version>${latest version here}</version>
</dependency>

或者,你可以使用 BOM 来统一管理依赖:

xml
<dependencyManagement>
    <dependency>
        <groupId>dev.langchain4j</groupId>
        <artifactId>langchain4j-community-bom</artifactId>
        <version>${latest version here}</version>
        <type>pom</type>
        <scope>import</scope>
    </dependency>
</dependencyManagement>

API

你可以用以下代码实例化 ChatGlmChatModel:

java
ChatModel model = ChatGlmChatModel.builder()
        .baseUrl(System.getenv("CHATGLM_BASE_URL"))
        .logRequests(true)
        .logResponses(true)
        .build();

现在你可以像使用普通 ChatModel 一样使用它。

NOTE

ChatGlmChatModel 不支持函数调用(Function Calling)与结构化输出。参见 index

示例

BytesRouter 是社区翻译站点,所有译文仅供参考,一切以官方英文原文为准。