From f782958a4442fdaa4d9ce2d2fc2ca9e5470e47ad Mon Sep 17 00:00:00 2001 From: handsomezhuzhu <2658601135@qq.com> Date: Fri, 16 Jan 2026 22:50:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20Docker=20CI=20=E5=B7=A5?= =?UTF-8?q?=E4=BD=9C=E6=B5=81=E5=92=8C=20README=20=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/docker-publish.yml | 47 +++++++++++ README.md | 118 +++++++++++++++++++++++++++ 2 files changed, 165 insertions(+) create mode 100644 .github/workflows/docker-publish.yml create mode 100644 README.md diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..47851dd --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,47 @@ +name: Docker Image CI + +on: + push: + branches: [ "main", "master" ] + tags: [ 'v*' ] + pull_request: + branches: [ "main", "master" ] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' }} + type=ref,event=tag + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/README.md b/README.md new file mode 100644 index 0000000..1c9a18d --- /dev/null +++ b/README.md @@ -0,0 +1,118 @@ +# AI API Proxy + +这是一个轻量级的 API 代理服务,旨在统一和简化对各种 AI 服务 API 的访问。它使用 Go 语言编写,支持 Docker 部署。 + +## 功能特性 + +- **多平台支持**: 代理了众多流行的 AI 和聊天服务 API。 +- **简单路由**: 通过 URL 前缀将请求路由 to 相应的官方 API 端点。 +- **Web 界面**: 提供一个简单的 HTML 首页,列出所有支持的 API 路由。 +- **隐私保护**: 过滤掉某些可能泄露信息的请求头(如 host, referer, cf- 等)。 +- **轻量级**: 基于 Go 语言,编译后体积小,运行资源占用低。 + +## 支持的 API 映射 + +该代理将以下本地路径映射到对应的官方 API 地址: + +| 路由前缀 | 目标 API 地址 | +| :--- | :--- | +| `/discord` | `https://discord.com/api` | +| `/telegram` | `https://api.telegram.org` | +| `/openai` | `https://api.openai.com` | +| `/claude` | `https://api.anthropic.com` | +| `/gemini` | `https://generativelanguage.googleapis.com` | +| `/meta` | `https://www.meta.ai/api` | +| `/groq` | `https://api.groq.com/openai` | +| `/xai` | `https://api.x.ai` | +| `/cohere` | `https://api.cohere.ai` | +| `/huggingface` | `https://api-inference.huggingface.co` | +| `/together` | `https://api.together.xyz` | +| `/novita` | `https://api.novita.ai` | +| `/portkey` | `https://api.portkey.ai` | +| `/fireworks` | `https://api.fireworks.ai` | +| `/openrouter` | `https://openrouter.ai/api` | +| `/cerebras` | `https://api.cerebras.ai` | + +## 快速开始 + +### 使用 Docker Compose (推荐) + +1. 确保已安装 Docker 和 Docker Compose。 +2. 克隆本仓库或下载文件。 +3. 在项目根目录下运行: + +```bash +docker-compose up -d --build +``` + +服务将在 `http://localhost:7890` 启动。 + +### 使用预构建镜像部署 (GitHub Packages) + +如果不想自己构建,可以直接拉取 GitHub Container Registry 上的镜像: + +```bash +# 拉取镜像 +docker pull ghcr.io/handsomezhuzhu/api-proxy:latest + +# 运行容器 +docker run -d -p 7890:7890 --name api-proxy ghcr.io/handsomezhuzhu/api-proxy:latest +``` + +### 使用 Docker + +1. 构建镜像: + +```bash +docker build -t api-proxy . +``` + +2. 运行容器: + +```bash +docker run -d -p 7890:7890 --name api-proxy api-proxy +``` + +### 从源码运行 + +1. 确保已安装 Go 环境 (推荐 1.21+)。 +2. 运行: + +```bash +go run main.go +``` + +或者编译后运行: + +```bash +go build -o api-proxy main.go +./api-proxy +``` + +默认端口为 `7890`。你可以通过命令行参数指定端口: + +```bash +./api-proxy 8080 +``` + +## 使用示例 + +假设你的服务运行在 `http://localhost:7890`。 + +**访问 OpenAI API:** + +你可以将原本发往 `https://api.openai.com/v1/chat/completions` 的请求改为发往: + +`http://localhost:7890/openai/v1/chat/completions` + +**访问 Claude (Anthropic) API:** + +将请求发往: + +`http://localhost:7890/claude/v1/messages` + +## 注意事项 + +- 本项目仅作为 API 请求的转发代理,请确保你拥有对应服务的有效 API Key。 +- 代理会透传你的 Authorization 头(API Key)。 +- 首页 (`/`) 提供了一个简单的状态页面,列出所有可用路由。