Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🤖 Model Gateway

国产大模型统一管理工具 —— 基于 Electron + Express 的桌面应用,提供 OpenAI 兼容 的本地 API 网关,让你用同一套接口调用智谱、DeepSeek 等国产模型。

✨ 特性

  • 🖥️ 桌面 GUI:一键配置 API Key、切换模型、测试连通性
  • 🔌 OpenAI 兼容:暴露 /v1/chat/completions/v1/models,可直接被 LangChain、各类 SDK、Cherry Studio 等客户端使用
  • 🧠 多模型支持:内置智谱 GLM-4、DeepSeek Chat,可扩展
  • 💾 本地持久化:配置保存到本地 config.json,API Key 不出本机
  • 🚀 一键启动:Windows / macOS / Linux 通用启动脚本

📦 安装

需要 Node.js 16+。

npm install

🚀 启动

方式一:一键启动(推荐)

Windows:

start.bat

macOS / Linux:

chmod +x start.sh
./start.sh

脚本会自动在后台启动 API 服务,并打开桌面 GUI。

方式二:分别启动

# 终端 1:启动后端 API 网关
npm run server

# 终端 2:启动桌面 GUI
npm start

🔧 使用

  1. 启动应用后,在 GUI 中为目标模型填入 API Key 并保存
  2. 点击模型卡片上的「选择」将其设为默认模型
  3. 点击「测试」验证连通性
  4. 在你的应用中将 Base URL 指向 http://localhost:3000/v1,即可像调用 OpenAI 一样调用国产模型

API Key 获取

提供商 申请地址
智谱 GLM https://open.bigmodel.cn
DeepSeek https://platform.deepseek.com

🔌 API 接口

服务监听在 http://localhost:3000

OpenAI 兼容接口

# 聊天补全
curl http://localhost:3000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "zhipu-glm-4",
    "messages": [{"role": "user", "content": "你好"}]
  }'

# 模型列表
curl http://localhost:3000/v1/models

请求体里的 model 字段可省略,缺省使用 GUI 中选中的模型。

管理接口

方法 路径 说明
GET /health 健康检查
GET /api/models 获取所有模型配置
POST /api/models/:key 更新指定模型的配置(如 apiKey)
POST /api/select 切换默认模型

📁 项目结构

.
├── main.js          # Electron 主进程
├── server.js        # Express API 网关
├── index.html       # GUI 界面
├── config.json      # 本地配置(运行时生成,已在 .gitignore 中)
├── start.bat        # Windows 启动脚本
├── start.sh         # Unix 启动脚本
└── package.json

➕ 扩展新模型

server.jsgetDefaultConfig() 中新增模型定义,并在 /v1/chat/completions 的 provider 分支里实现对应的请求适配即可。

⚠️ 注意事项

  • config.json 包含明文 API Key,已在 .gitignore,请勿提交到公开仓库
  • 服务默认监听 0.0.0.0:3000,如需仅本地访问可改为 127.0.0.1
  • 当前未做鉴权,不要直接暴露到公网

📄 License

MIT

About

model-gateway

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages