Skip to content

Commit b0670fe

Browse files
committed
Update readme.md to remove outdated API request examples and add tutorial link
1 parent 05e3bf0 commit b0670fe

File tree

5 files changed

+144
-166
lines changed

5 files changed

+144
-166
lines changed

.dockerignore

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Git
2+
.git
3+
.gitignore
4+
5+
# IDE
6+
.idea
7+
.vscode
8+
*.swp
9+
*.swo
10+
11+
# Build artifacts
12+
*.exe
13+
puter2api
14+
15+
# Database files
16+
*.db
17+
*.db-journal
18+
19+
# Documentation
20+
*.md
21+
LICENSE
22+
23+
# CI/CD
24+
.gitlab-ci.yml
25+
.github
26+
27+
# Docker
28+
Dockerfile
29+
.dockerignore
30+
docker-compose*.yml

.github/workflows/docker-build.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
tags:
9+
- 'v*'
10+
pull_request:
11+
branches:
12+
- main
13+
- master
14+
workflow_dispatch:
15+
16+
env:
17+
DOCKER_IMAGE: leokun123/puter2api
18+
19+
jobs:
20+
build:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout code
24+
uses: actions/checkout@v4
25+
26+
- name: Set up QEMU
27+
uses: docker/setup-qemu-action@v3
28+
29+
- name: Set up Docker Buildx
30+
uses: docker/setup-buildx-action@v3
31+
32+
- name: Login to Docker Hub
33+
if: github.event_name != 'pull_request'
34+
uses: docker/login-action@v3
35+
with:
36+
username: leokun123
37+
password: ${{ secrets.DOCKER_HUB_TOKEN }}
38+
39+
- name: Extract metadata
40+
id: meta
41+
uses: docker/metadata-action@v5
42+
with:
43+
images: ${{ env.DOCKER_IMAGE }}
44+
tags: |
45+
type=ref,event=branch
46+
type=ref,event=pr
47+
type=semver,pattern={{version}}
48+
type=semver,pattern={{major}}.{{minor}}
49+
type=raw,value=latest,enable={{is_default_branch}}
50+
type=sha,prefix=
51+
52+
- name: Build and push
53+
uses: docker/build-push-action@v5
54+
with:
55+
context: .
56+
platforms: linux/amd64,linux/arm64
57+
push: ${{ github.event_name != 'pull_request' }}
58+
tags: ${{ steps.meta.outputs.tags }}
59+
labels: ${{ steps.meta.outputs.labels }}
60+
cache-from: type=gha
61+
cache-to: type=gha,mode=max

2025-11-27-01-44-09.png

835 KB
Loading

Dockerfile

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Build stage
2+
FROM --platform=$BUILDPLATFORM golang:1.21-alpine AS builder
3+
4+
# Install build dependencies
5+
RUN apk add --no-cache gcc musl-dev
6+
7+
WORKDIR /app
8+
9+
# Copy go mod files
10+
COPY go.mod go.sum ./
11+
RUN go mod download
12+
13+
# Copy source code
14+
COPY . .
15+
16+
# Build arguments for cross-compilation
17+
ARG TARGETOS
18+
ARG TARGETARCH
19+
20+
# Build the application
21+
RUN CGO_ENABLED=1 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="-s -w" -o puter2api .
22+
23+
# Runtime stage
24+
FROM alpine:latest
25+
26+
# Install runtime dependencies
27+
RUN apk add --no-cache ca-certificates tzdata
28+
29+
WORKDIR /app
30+
31+
# Copy binary from builder
32+
COPY --from=builder /app/puter2api .
33+
34+
# Create data directory
35+
RUN mkdir -p /data
36+
37+
# Environment variables
38+
ENV PORT=8081
39+
ENV DB_PATH=/data/puter2api.db
40+
ENV GIN_MODE=release
41+
42+
# Expose port
43+
EXPOSE 8081
44+
45+
# Health check
46+
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
47+
CMD wget --no-verbose --tries=1 --spider http://localhost:8081/ || exit 1
48+
49+
# Run the application
50+
CMD ["./puter2api"]

readme.md

Lines changed: 3 additions & 166 deletions
Original file line numberDiff line numberDiff line change
@@ -1,167 +1,4 @@
1-
```
2-
curl 'https://puter.com/puterai/chat/models' \
3-
-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7' \
4-
-H 'Accept-Language: zh-CN,zh;q=0.9' \
5-
-H 'Cache-Control: no-cache' \
6-
-H 'Connection: keep-alive' \
7-
-b '_clck=trp08g%5E2%5Eg1c%5E0%5E2156; __stripe_mid=1ae8b1e7-34aa-4d9c-a0bc-e00348bd4e36e7b24e; __stripe_sid=937ef572-58cc-46d3-bc2e-dbac15385aa77e545a; puter_auth_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0IjoicyIsInYiOiIwLjAuMCIsInUiOiJaMmZNZ2FzOFJSeXhSS3M3S1FuWnpnPT0iLCJ1dSI6Im02UmZFbkEzU0VpUjk0TVZadnJYZkE9PSIsImlhdCI6MTc2NDE3MTc0OH0.2pC0C8jAvpFiUpOcVza1V7uCnnfVza9kBLX2p5PcFyw; _clsk=1ydouus%5E1764171905602%5E6%5E1%5Ei.clarity.ms%2Fcollect' \
8-
-H 'Pragma: no-cache' \
9-
-H 'Sec-Fetch-Dest: document' \
10-
-H 'Sec-Fetch-Mode: navigate' \
11-
-H 'Sec-Fetch-Site: none' \
12-
-H 'Sec-Fetch-User: ?1' \
13-
-H 'Upgrade-Insecure-Requests: 1' \
14-
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36' \
15-
-H 'sec-ch-ua: "Chromium";v="142", "Google Chrome";v="142", "Not_A Brand";v="99"' \
16-
-H 'sec-ch-ua-mobile: ?0' \
17-
-H 'sec-ch-ua-platform: "macOS"'
18-
```
19-
20-
## 对 Puter.com 的请求
21-
22-
### 1. 获取模型列表
23-
- **URL**: `https://puter.com/puterai/chat/models`
24-
- **方法**: GET
25-
- **响应**:
26-
```json
27-
{
28-
"models": ["model-id-1", "model-id-2", ...]
29-
}
30-
```
31-
32-
### 2. 调用 AI 驱动
33-
- **URL**: `https://api.puter.com/drivers/call`
34-
- **方法**: POST
35-
- **请求头**:
36-
- `Host`: api.puter.com
37-
- `Authorization`: Bearer {JWT_TOKEN}
38-
- `Content-Type`: application/json;charset=UTF-8
39-
- `Origin`: https://docs.puter.com
40-
- `Referer`: https://docs.puter.com/
41-
42-
- **请求体**:
43-
```json
44-
{
45-
"interface": "puter-chat-completion",
46-
"driver": "openai-completion|deepseek|xai|claude|mistral",
47-
"test_mode": false,
48-
"method": "complete",
49-
"args": {
50-
"messages": [...],
51-
"model": "model-name",
52-
"stream": true|false
53-
}
54-
}
55-
```
56-
57-
- **响应** (非流式):
58-
```json
59-
{
60-
"result": {
61-
"message": {
62-
"content": "text" | [{"type": "text", "text": "..."}]
63-
},
64-
"usage": {
65-
"input_tokens": 0,
66-
"output_tokens": 0
67-
}
68-
}
69-
}
70-
```
71-
72-
- **响应** (流式): 每行一个 JSON 对象
73-
```json
74-
{"text": "content"}
75-
```
76-
77-
```json
78-
{"result": {"message": {"content": "text" | [...]}}}
79-
```
80-
81-
## API 端点
82-
83-
### GET /v1/models
84-
获取可用模型列表
85-
86-
**响应格式**:
87-
```json
88-
{
89-
"object": "list",
90-
"data": [
91-
{
92-
"id": "model-id",
93-
"object": "model",
94-
"created": 1234567890,
95-
"owned_by": "openai|deepseek|xai|anthropic|mistral|unknown"
96-
}
97-
]
98-
}
99-
```
100-
101-
### POST /v1/chat/completions
102-
创建聊天补全
103-
104-
**请求头**:
105-
- `Authorization`: Bearer {AUTH_TOKEN}
106-
107-
**请求体**:
108-
```json
109-
{
110-
"model": "model-name",
111-
"messages": [
112-
{"role": "user", "content": "Hello"}
113-
],
114-
"stream": false
115-
}
116-
```
117-
118-
**响应格式** (非流式):
119-
```json
120-
{
121-
"id": "chatcmpl-1234567890",
122-
"object": "chat.completion",
123-
"created": 1234567890,
124-
"model": "model-name",
125-
"choices": [
126-
{
127-
"index": 0,
128-
"message": {
129-
"role": "assistant",
130-
"content": "响应内容"
131-
},
132-
"finish_reason": "stop"
133-
}
134-
],
135-
"usage": {
136-
"prompt_tokens": 10,
137-
"completion_tokens": 20,
138-
"total_tokens": 30
139-
}
140-
}
141-
```
142-
143-
**响应格式** (流式 - SSE):
144-
```
145-
data: {"id":"chatcmpl-xxx","object":"chat.completion.chunk","created":xxx,"model":"xxx","choices":[{"index":0,"delta":{"role":"assistant"},"finish_reason":null}]}
146-
147-
data: {"id":"chatcmpl-xxx","object":"chat.completion.chunk","created":xxx,"model":"xxx","choices":[{"index":0,"delta":{"content":"内容"},"finish_reason":null}]}
148-
149-
data: {"id":"chatcmpl-xxx","object":"chat.completion.chunk","created":xxx,"model":"xxx","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
150-
151-
data: [DONE]
152-
```
153-
154-
## 环境变量
155-
156-
- `JWT_TOKEN`: Puter API 的 JWT 令牌(多个用逗号分隔)
157-
- `AUTH_TOKEN`: 本服务的认证令牌(多个用逗号分隔)
158-
- `PORT`: 服务端口(默认 8001)
159-
160-
## 驱动映射
161-
162-
- `deepseek` → deepseek
163-
- `grok` → xai
164-
- `claude` → claude
165-
- `mistral/codestral` → mistral
166-
- 其他 → openai-completion
1+
# 教程
2+
https://docs.puter.com/playground/ai-chatgpt/
1673

4+
![](2025-11-27-01-44-09.png)

0 commit comments

Comments
 (0)