Skip to content

Commit 56e3193

Browse files
committed
Add project source with cleaned up comments - OpenAI-compatible API bridge for QoderWork (Go port) - Modules: auth, bridge, models, store, transform, admin - Unified comment style across all source files - Docker support, GitHub Actions release workflow
1 parent 1ff4a70 commit 56e3193

22 files changed

Lines changed: 5624 additions & 0 deletions

‎.github/workflows/release.yml‎

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: write
11+
packages: write
12+
13+
jobs:
14+
# --- Build binaries for Windows / macOS / Linux (amd64 + arm64) ---
15+
build-binaries:
16+
name: Build ${{ matrix.os }}-${{ matrix.arch }}
17+
runs-on: ubuntu-latest
18+
strategy:
19+
matrix:
20+
include:
21+
- os: linux
22+
arch: amd64
23+
goos: linux
24+
goarch: amd64
25+
ext: ""
26+
- os: linux
27+
arch: arm64
28+
goos: linux
29+
goarch: arm64
30+
ext: ""
31+
- os: windows
32+
arch: amd64
33+
goos: windows
34+
goarch: amd64
35+
ext: ".exe"
36+
- os: windows
37+
arch: arm64
38+
goos: windows
39+
goarch: arm64
40+
ext: ".exe"
41+
- os: darwin
42+
arch: amd64
43+
goos: darwin
44+
goarch: amd64
45+
ext: ""
46+
- os: darwin
47+
arch: arm64
48+
goos: darwin
49+
goarch: arm64
50+
ext: ""
51+
52+
steps:
53+
- name: Checkout
54+
uses: actions/checkout@v4
55+
56+
- name: Setup Go
57+
uses: actions/setup-go@v5
58+
with:
59+
go-version: '1.22'
60+
61+
- name: Build binary
62+
env:
63+
CGO_ENABLED: '0'
64+
GOOS: ${{ matrix.goos }}
65+
GOARCH: ${{ matrix.goarch }}
66+
run: |
67+
mkdir -p dist
68+
go build -trimpath -ldflags="-s -w" -o dist/qoder2api-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.ext }} .
69+
cp baseprompt.json dist/
70+
71+
- name: Create archive
72+
run: |
73+
cd dist
74+
if [ "${{ matrix.os }}" = "windows" ]; then
75+
zip -r qoder2api-${{ matrix.os }}-${{ matrix.arch }}.zip qoder2api-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.ext }} baseprompt.json
76+
else
77+
tar -czf qoder2api-${{ matrix.os }}-${{ matrix.arch }}.tar.gz qoder2api-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.ext }} baseprompt.json
78+
fi
79+
80+
- name: Upload artifact
81+
uses: actions/upload-artifact@v4
82+
with:
83+
name: qoder2api-${{ matrix.os }}-${{ matrix.arch }}
84+
path: dist/qoder2api-${{ matrix.os }}-${{ matrix.arch }}.*
85+
86+
# --- Build and push Docker image ---
87+
build-docker:
88+
name: Build Docker image
89+
runs-on: ubuntu-latest
90+
steps:
91+
- name: Checkout
92+
uses: actions/checkout@v4
93+
94+
- name: Set up QEMU
95+
uses: docker/setup-qemu-action@v3
96+
97+
- name: Set up Docker Buildx
98+
uses: docker/setup-buildx-action@v3
99+
100+
- name: Docker meta
101+
id: meta
102+
uses: docker/metadata-action@v5
103+
with:
104+
images: |
105+
ghcr.io/${{ github.repository }}
106+
tags: |
107+
type=ref,event=tag
108+
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
109+
type=sha
110+
111+
- name: Login to GHCR
112+
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
113+
uses: docker/login-action@v3
114+
with:
115+
registry: ghcr.io
116+
username: ${{ github.actor }}
117+
password: ${{ secrets.GITHUB_TOKEN }}
118+
119+
- name: Build and push
120+
uses: docker/build-push-action@v6
121+
with:
122+
context: .
123+
platforms: linux/amd64,linux/arm64
124+
push: ${{ startsWith(github.ref, 'refs/tags/v') }}
125+
tags: ${{ steps.meta.outputs.tags }}
126+
labels: ${{ steps.meta.outputs.labels }}
127+
cache-from: type=gha
128+
cache-to: type=gha,mode=max
129+
130+
# --- Create GitHub Release ---
131+
release:
132+
name: Create Release
133+
runs-on: ubuntu-latest
134+
needs: [build-binaries]
135+
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
136+
steps:
137+
- name: Checkout
138+
uses: actions/checkout@v4
139+
140+
- name: Download all artifacts
141+
uses: actions/download-artifact@v4
142+
with:
143+
path: artifacts
144+
merge-multiple: true
145+
146+
- name: List artifacts
147+
run: ls -la artifacts/
148+
149+
- name: Create release
150+
uses: softprops/action-gh-release@v2
151+
with:
152+
tag_name: ${{ github.ref_name }}
153+
name: Release ${{ github.ref_name }}
154+
generate_release_notes: true
155+
files: artifacts/*
156+
draft: false
157+
prerelease: ${{ contains(github.ref_name, 'rc') || contains(github.ref_name, 'beta') || contains(github.ref_name, 'alpha') }}

‎.gitignore‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Binaries
2+
*.exe
3+
dist/
4+
5+
# Data files (runtime generated)
6+
data.json
7+
8+
# OS files
9+
.DS_Store
10+
Thumbs.db

‎Dockerfile‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM golang:1.22-alpine AS builder
2+
3+
WORKDIR /build
4+
COPY go.mod go.sum ./
5+
RUN go mod download
6+
COPY . .
7+
RUN CGO_ENABLED=0 go build -o qoder2api .
8+
9+
FROM alpine:3.20
10+
RUN apk add --no-cache ca-certificates
11+
WORKDIR /app
12+
COPY --from=builder /build/qoder2api .
13+
COPY baseprompt.json .
14+
ENV QODER_HOST=0.0.0.0 \
15+
QODER_PORT=18080
16+
EXPOSE 18080
17+
CMD ["./qoder2api"]

‎README.md‎

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
# Qoder-2API-Go
2+
3+
> Qoder2API 的 Go 语言实现 —— 将 Qoder AI 服务桥接为 OpenAI 兼容 API。
4+
5+
本项目参考 [fengyinxia/qoder2api: QoderWork -> OpenAI compatible API bridge (dynamic model loading, pure Python)](https://github.com/fengyinxia/qoder2api) ,将原有 Python 代码完整重写为 Go,保留了全部核心功能,同时提升了性能与部署便利性。
6+
7+
## 功能特性
8+
9+
- **OpenAI API 兼容** —— 支持 `/v1/chat/completions` 和 `/v1/models` 端点,可无缝替换 OpenAI API
10+
- **流式响应** —— 支持 SSE 流式输出
11+
- **多模态支持** —— 支持图片输入
12+
- **Tool Calls** —— 支持函数调用
13+
- **模型动态加载** —— 自动从网关获取可用模型列表
14+
- **Web 管理面板** —— 浅色白绿配色中文界面,支持密码登录、API 密钥管理、PAT 配置、模型查看
15+
- **单文件部署** —— 编译为单一二进制文件,零外部依赖
16+
17+
## 支持的模型
18+
19+
| 显示名称 | 内部 Key | 视觉 |
20+
|---------|----------|------|
21+
| Qwen3.8-Max-Preview | qmodel_preview | 支持 |
22+
| Qwen3.7-Max | qmodel_latest | 支持 |
23+
| Qwen3.7-Plus | qmodel | 支持 |
24+
| Qwen3.6-Flash | q36fmodel | 支持 |
25+
| DeepSeek-V4-Pro | dmodel | 支持 |
26+
| DeepSeek-V4-Flash | dfmodel | 支持 |
27+
| GLM-5.2 | gm51model | 支持 |
28+
| Kimi-K2.7-Code | kmodel | 支持 |
29+
| MiniMax-M2.7 | mmodel | 不支持 |
30+
31+
> 以上为内置默认列表,实际可用模型以网关动态返回为准。
32+
33+
## 快速开始
34+
35+
### 方式一:直接运行
36+
37+
```bash
38+
# 编译
39+
go build -o qoder2api .
40+
41+
# 运行(默认监听 0.0.0.0:18080)
42+
./qoder2api
43+
```
44+
45+
### 方式二:Docker 部署
46+
47+
```bash
48+
# 使用 docker-compose
49+
docker-compose up -d
50+
51+
# 或手动构建
52+
docker build -t qoder2api .
53+
docker run -d -p 18080:18080 -v qoder2api-data:/app/data qoder2api
54+
```
55+
56+
### 方式三:下载预编译二进制
57+
58+
前往 [Releases](https://github.com/EchoPing07/Qoder-2API-Go/releases) 下载对应平台的二进制文件,直接运行即可。
59+
60+
## 配置
61+
62+
### 环境变量
63+
64+
| 变量名 | 默认值 | 说明 |
65+
|-------|--------|------|
66+
| `QODER_HOST` | `0.0.0.0` | 监听地址 |
67+
| `QODER_PORT` | `18080` | 监听端口 |
68+
| `QODER_DATA_PATH` | `data.json` | 数据文件路径 |
69+
| `QODER_ADMIN_PASSWORD` | `password` | 管理面板密码(覆盖 data.json 中的值) |
70+
| `QODER_SIGNATURE_SECRET` | 内置值 | 请求签名密钥 |
71+
72+
### 配置文件 (data.json)
73+
74+
首次运行时自动生成,也可通过 Web 管理面板修改:
75+
76+
```json
77+
{
78+
"host": "0.0.0.0",
79+
"port": 18080,
80+
"pat": "pt-xxxxxxxx",
81+
"password": "password",
82+
"api_keys": [
83+
{
84+
"id": "xxxxxxxx",
85+
"key": "sk-xxxxxxxxxxxxxxxx",
86+
"note": "备注",
87+
"created_at": 1234567890
88+
}
89+
]
90+
}
91+
```
92+
93+
## 使用方法
94+
95+
### 1. 配置 PAT
96+
97+
启动服务后访问 `http://localhost:18080/admin`,输入默认密码 `password` 登录,在「令牌」标签页中填入你的 Qoder PAT。
98+
99+
### 2. 创建 API 密钥
100+
101+
在「API 密钥」标签页中创建密钥(可自定义或自动生成),客户端使用此密钥调用 API。
102+
103+
### 3. 调用 API
104+
105+
```bash
106+
curl http://localhost:18080/v1/chat/completions \
107+
-H "Authorization: Bearer sk-xxxxxxxxxxxxxxxx" \
108+
-H "Content-Type: application/json" \
109+
-d '{
110+
"model": "Qwen3.7-Max",
111+
"messages": [{"role": "user", "content": "你好"}],
112+
"stream": true
113+
}'
114+
```
115+
116+
### 4. 获取模型列表
117+
118+
```bash
119+
curl http://localhost:18080/v1/models \
120+
-H "Authorization: Bearer sk-xxxxxxxxxxxxxxxx"
121+
```
122+
123+
## API 端点
124+
125+
| 端点 | 方法 | 说明 |
126+
|------|------|------|
127+
| `/v1/chat/completions` | POST | 聊天补全(兼容 OpenAI 格式) |
128+
| `/v1/models` | GET | 获取模型列表 |
129+
| `/admin` | GET | Web 管理面板 |
130+
| `/admin/api/login` | POST | 管理面板登录 |
131+
| `/admin/api/keys` | GET/POST/DELETE | API 密钥管理 |
132+
| `/admin/api/pat` | GET/POST | PAT 令牌管理 |
133+
| `/admin/api/models` | GET | 获取模型列表 |
134+
| `/admin/api/config` | GET/POST | 服务器配置 |
135+
| `/admin/api/password` | POST | 修改管理密码 |
136+
137+
## 项目结构
138+
139+
```
140+
Qoder-2API-Go/
141+
├── main.go # 程序入口
142+
├── auth/ # 认证模块
143+
├── bridge/ # API 桥接模块
144+
├── models/ # 模型管理
145+
├── store/ # 数据持久化
146+
├── transform/ # 数据转换
147+
├── admin/ # Web 管理面板
148+
├── baseprompt.json # Qoder 请求模板
149+
├── Dockerfile # Docker 构建文件
150+
├── docker-compose.yaml # Docker Compose 配置
151+
└── .github/workflows/ # GitHub Actions 自动构建
152+
```
153+
154+
## 技术栈
155+
156+
- **语言**:Go 1.22+
157+
- **依赖**:仅使用 `github.com/google/uuid`,其余全部标准库
158+
- **加密**:RSA + AES 混合加密、MD5 签名、自定义 Base64 编码
159+
- **HTTP**:标准库 `net/http`,SSE 流式响应
160+
- **存储**:JSON 文件持久化,线程安全读写
161+
162+
## 开发
163+
164+
```bash
165+
# 克隆仓库
166+
git clone https://github.com/EchoPing07/Qoder-2API-Go.git
167+
cd Qoder-2API-Go
168+
169+
# 运行测试
170+
go test ./...
171+
172+
# 构建
173+
go build -o qoder2api .
174+
175+
# 构建(跨平台)
176+
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o qoder2api-linux-arm64 .
177+
```
178+
179+
## 许可证
180+
181+
本项目基于 [MIT License](./LICENSE) 开源。
182+
183+
## 免责声明
184+
185+
本项目仅供学习和研究目的使用。
186+
187+
1. **本项目不隶属于 Qoder 或其关联公司**,Qoder 是其各自所有者的商标。本项目不对任何官方服务提供保证或支持。
188+
2. **仅供学习交流使用**,不得用于任何商业用途或非法用途。使用者应遵守所在地区的法律法规。
189+
3. **本项目不对任何因使用或滥用本项目而导致的直接或间接损失负责**,包括但不限于数据丢失、服务中断、账号封禁等情况。
190+
4. **使用者需自行承担使用本项目的所有风险**,项目维护者不对本项目的正确性、完整性、可靠性或适用性作任何明示或暗示的保证。
191+
5. **请勿将本项目用于绕付费、绕限制、大规模爬取或其他可能损害服务提供方利益的行为**。请尊重服务提供方的条款和条件。
192+
6. 如果本项目的任何内容侵犯了您的权益,请及时联系项目维护者,我们将积极配合处理。
193+
194+
使用本项目即表示您已阅读并同意以上免责声明。如果您不同意,请立即停止使用并删除本项目。

0 commit comments

Comments
 (0)