Skip to content

Comments

feat: 支持 GLM 系列模型(智谱 AI)作为推理后端#221

Open
hanzhcn wants to merge 2 commits intoConway-Research:mainfrom
hanzhcn:feat/glm-model-support
Open

feat: 支持 GLM 系列模型(智谱 AI)作为推理后端#221
hanzhcn wants to merge 2 commits intoConway-Research:mainfrom
hanzhcn:feat/glm-model-support

Conversation

@hanzhcn
Copy link
Contributor

@hanzhcn hanzhcn commented Feb 24, 2026

概述

本 PR 添加了对智谱 AI GLM 系列模型(如 GLM-5)作为推理后端的支持,使 Conway Automaton 能够使用国产大模型运行。

背景

智谱 AI 的 GLM 系列是中国领先的国产大语言模型,具有以下优势:

  • 成本效益:相比 OpenAI GPT-4,GLM-5 的 API 成本显著更低
  • 本地化合规:数据不出境,满足中国市场的合规需求
  • 中文优化:对中文语境和任务有更好的理解能力
  • 稳定可用:通过 GLM Coding Plan 提供稳定的企业级 API 服务

技术变更

1. 新增配置项 (src/types.ts)

/** Custom OpenAI API base URL (e.g., for GLM Coding Plan: https://open.bigmodel.cn/api/coding/paas/v4) */
openaiApiBaseUrl?: string;

2. 推理客户端适配 (src/conway/inference.ts)

模型识别:自动检测 GLM 模型并路由到 OpenAI 兼容后端

// GLM models (智谱): glm-* - 使用 OpenAI 兼容 API
if (keys.openaiApiKey && /^glm/i.test(model)) return "openai";

API 端点适配:GLM Coding Plan 使用 /chat/completions 而非标准 OpenAI 的 /v1/chat/completions

// GLM Coding Plan uses /chat/completions instead of /v1/chat/completions
const isGlmApi =
  params.apiUrl.includes("bigmodel.cn") ||
  params.apiUrl.includes("/v4") ||
  params.apiUrl.includes("/paas");
const endpoint = isGlmApi ? "/chat/completions" : "/v1/chat/completions";

自定义 API URL 支持

const openAiLikeApiUrl =
  backend === "openai"
    ? options.openaiApiBaseUrl || "https://api.openai.com"
    : ...

3. 上下文温度修复 (src/agent/context.ts)

GLM-5 要求 temperature 在开区间 (0, 1) 内,不能为 0:

temperature: 0.1, // GLM-5 requires temperature > 0

使用方法

automaton.json 中配置:

{
  "openaiApiKey": "your-glm-api-key",
  "openaiApiBaseUrl": "https://open.bigmodel.cn/api/coding/paas/v4",
  "inferenceModel": "glm-5"
}

测试

已在生产环境验证:

  • ✅ GLM-5 推理正常工作
  • ✅ 工具调用(function calling)正常
  • ✅ 上下文管理正常
  • ✅ 心跳任务正常执行

兼容性

  • 完全向后兼容,不影响现有用户
  • 仅在使用 openaiApiBaseUrl 配置时启用新功能
  • 对标准 OpenAI API 行为无影响

相关链接

添加对智谱 AI GLM 系列模型(如 GLM-5)的支持,使 Conway Automaton
能够使用国产大模型运行。

主要变更:
- types.ts: 新增 openaiApiBaseUrl 配置项
- inference.ts: GLM 模型自动检测和 API 端点适配
  - 自动识别 glm-* 模型并路由到 OpenAI 兼容后端
  - 适配 GLM Coding Plan 的 /chat/completions 端点
- index.ts: 传递 openaiApiBaseUrl 到推理客户端
- context.ts: 修复 temperature=0 问题(GLM-5 要求 >0)

使用方法:
在 automaton.json 中配置:
{
  "openaiApiKey": "your-glm-api-key",
  "openaiApiBaseUrl": "https://open.bigmodel.cn/api/coding/paas/v4",
  "inferenceModel": "glm-5"
}
问题:PR Conway-Research#221 缺少模型注册表修改,导致 GLM-5 不在 STATIC_MODEL_BASELINE 中
解决:添加 GLM-5 到模型基线和 DEFAULT_ROUTING_MATRIX
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants