Skip to content

kingxzq/ModelStandardization

Repository files navigation

ModelStandardization

轻量级 OpenAI API 格式标准化代理 / Lightweight OpenAI API Format Standardization Proxy

中文文档 English Docs Release License


选择语言 / Choose Language

🇨🇳 中文

完整中文文档,包含原理介绍、使用方法、部署指南等

中文文档

🇺🇸 English

Full English documentation with principles, usage, deployment guide, etc.

English Docs

简介 / Introduction

ModelStandardization 是一个轻量级的 Rust 代理服务器,用于将内网部署的非标准 OpenAI 兼容模型 API 转换为标准 OpenAI API 格式。

ModelStandardization is a lightweight Rust proxy server that converts non-standard OpenAI-compatible model APIs deployed in private networks into standard OpenAI API format.

解决的问题 / Problem Statement

中文:企业内网部署的大模型接口通常是类 OpenAI 格式,但会返回多余的非标准字段,导致 Dify、Open WebUI 等标准客户端无法正确接入。

English: LLM interfaces deployed in enterprise private networks typically return extra non-standard fields, causing standard clients like Dify and Open WebUI to fail when integrating.


快速开始 / Quick Start

1. 下载 / Download

GitHub Releases 下载二进制文件。

Download from GitHub Releases.

2. 配置 / Configure

创建 config.toml

[server]
listen_address = "0.0.0.0"
listen_port = 8819

[upstream]
base_url = "http://your-model-server:8000"
api_key = "sk-xxx"  # optional
timeout = 300

[response]
strip_fields = [
    "system_fingerprint",
    "service_tier",
    "usage.completion_tokens_details",
    "usage.prompt_tokens_details",
]

[request]
strip_fields = []

3. 启动 / Run

chmod +x model-standardization
./model-standardization

4. 验证 / Verify

curl http://localhost:8819/health
# {"ok":true,"service":"model-standardization"}

工作原理 / How It Works

┌─────────────────────────────────────────────────────────────────────────────┐
│                    客户端 / Client (Dify / Open WebUI / LangChain)          │
│                                    │                                        │
│                                    │ 标准 OpenAI 请求 / Standard Request    │
│                                    ▼                                        │
│  ┌───────────────────────────────────────────────────────────────────────┐  │
│  │                      ModelStandardization                             │  │
│  │                                                                       │  │
│  │   ┌─────────────┐    ┌─────────────┐    ┌─────────────┐              │  │
│  │   │  接收请求    │───▶│  字段剥离    │───▶│  转发上游    │              │  │
│  │   └─────────────┘    └─────────────┘    └─────────────┘              │  │
│  │                                  │                                    │  │
│  │                                  ▼                                    │  │
│  │   ┌─────────────┐    ┌─────────────┐    ┌─────────────┐              │  │
│  │   │  响应返回    │◀───│  字段剥离    │◀───│  接收响应    │              │  │
│  │   └─────────────┘    └─────────────┘    └─────────────┘              │  │
│  │                                                                       │  │
│  └───────────────────────────────────────────────────────────────────────┘  │
│                                    │                                        │
│                                    │ 非标准请求/响应 / Non-standard          │
│                                    ▼                                        │
│                    内网大模型 / Private LLM Service                          │
└─────────────────────────────────────────────────────────────────────────────┘

功能特性 / Features

功能 / Feature 说明 / Description
✅ 字段剥离 / Field Stripping 支持从请求和响应中剥离任意配置的字段
✅ 嵌套路径 / Nested Paths 支持点分隔的嵌套字段路径(如 usage.prompt_tokens_details
✅ 流式支持 / Streaming 完整支持 SSE 流式响应的字段剥离
✅ 透明代理 / Transparent 对客户端完全透明,无需修改客户端代码
🚀 高性能 / High Performance 基于 Rust + Tokio,低内存占用,延迟 < 1ms
📦 轻量级 / Lightweight 二进制文件仅约 3.8MB,完全静态链接

支持的端点 / API Endpoints

端点 / Endpoint 方法 / Method 说明 / Description
/v1/chat/completions POST 聊天补全 / Chat completions
/chat/completions POST 同上(无版本前缀)/ Same (no prefix)
/v1/models GET 模型列表 / Model list
/models GET 同上(无版本前缀)/ Same (no prefix)
/health GET 健康检查 / Health check

部署 / Deployment

systemd(推荐 / Recommended)

sudo vim /etc/systemd/system/model-standardization.service
sudo systemctl enable --now model-standardization

Docker

docker build -t model-standardization .
docker run -d -p 8819:8819 model-standardization

Docker Compose

docker compose up -d

详细文档 / Full Documentation

📖 完整文档请访问 / For full documentation visit:

中文文档      English Docs


许可证 / License

MIT License © kingxzq

About

非标准模型输出标准化转化为Open AI格式代理,用于接入第三方工具,轻量化部署,适配linux全平台,不需要额外安装依赖

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors