240ffdcf7878a26cfb14756e366456497a672624
ai 繪圖
用戶:
type User struct {
ID int `json:"id" gorm:"primary_key"`
Name string `json:"name"`
Email string `json:"email" gorm:"unique;not null"`
Password string `json:"-"`
Slat string `json:"-"`
Admin bool `json:"admin"`
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
}
- GET /api/users 用戶列表
- POST /api/users 創建用戶
{email:'', password:'', name:''}
- GET /api/users 查詢指定用戶
- PATCH /api/users/{id} 修改指定用戶
- DELETE /api/users/{id} 刪除指定用戶
會話:
type Session struct {
ID string `json:"id" gorm:"primary_key"`
IP string `json:"ip"`
UserID int `json:"user_id"`
UserAgent string `json:"user_agent"`
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
}
- GET /api/sessions 會話列表
- POST /api/sessions 登錄賬戶(創建會話)
{email:'', password:''}
- GET /api/sessions/{id} 查詢會話詳情
- PATCH /api/sessions/{id} 修改會話狀態
- DELETE /api/sessions/{id} 註銷登錄(刪除指定會話)
數據集:
type Dataset struct {
ID int `json:"id" gorm:"primary_key"`
Name string `json:"name"`
Info string `json:"info"`
Images ImageList `json:"images"`
UserID int `json:"user_id"`
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
}
type ImageList []string // image URL
- GET /api/datasets 數據集列表
- POST /api/datasets 創建數據集
{images:['https://oss..']}
- GET /api/datasets/{id} 查詢指定數據集
- PATCH /api/datasets/{id} 修改指定數據集
- DELETE /api/datasets/{id} 刪除指定數據集
標籤:
type Tag struct {
ID int `json:"id" gorm:"primary_key"`
Name string `json:"name"`
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
}
- GET /api/tags 標籤列表(全部)
- POST /api/tags 創建標籤
{name:''}
- GET /api/tags/{id} 標籤詳情
- PATCH /api/tags/{id} 修改標籤
- DELETE /api/tags/{id} 刪除標籤
模型:
type Model struct {
ID int `json:"id" gorm:"primary_key"` // 模型ID
Name string `json:"name"` // 模型名稱
Info string `json:"info"` // 模型描述
Type string `json:"type"` // 模型類型(lora|ckp|hyper|ti)
TriggerWords string `json:"trigger_words"` // 觸發詞
BaseModel string `json:"base_model"` // 基礎模型(SD1.5|SD2)
ModelPath string `json:"model_path"` // 模型路徑(實際存放在服務器上的路徑)
Status string `json:"status" default:"initial"` // (initial|ready|waiting|running|success|error)
Progress int `json:"progress"` // (0-100)
Image string `json:"image"` // 封面圖片實際地址
Hash string `json:"hash"` // 模型哈希值
Epochs int `json:"epochs"` // 訓練步數
LearningRate float32 `json:"learning_rate"` // 學習率(0.000005)
Tags TagList `json:"tags"` // 模型標籤(標籤名數組)
UserID int `json:"user_id"` // 模型的所有者
DatasetID int `json:"dataset_id"` // 模型所使用的數據集ID
ServerID string `json:"server_id"` // 模型所在服務器(訓練機或推理機)
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
}
- GET /api/models 模型列表(全部)
- GET /api/models?user_id=xxx 模型列表(指定用戶的)
- GET /api/models?tag=動物 模型列表(指定標籤的)
- GET /api/models?sort=hot 圖片列表(熱門)
- GET /api/models?sort=createdAt 圖片列表(最新)
- GET /api/models?search=布穀鳥 圖片列表(關鍵詞搜索)
- POST /api/models 創建並訓練新模型(dataset_id 爲必填)
- PATCH /api/models/{id} 修改指定模型
- DELETE /api/models/{id} 刪除指定模型
圖像:
type Image struct {
ID int `json:"id" gorm:"primary_key"`
Name string `json:"name"`
Hash string `json:"hash"`
Path string `json:"path"`
Type string `json:"type"`
Size int `json:"size"`
Width int `json:"width"`
Height int `json:"height"`
Prompt string `json:"prompt"`
Format string `json:"format"`
NegativePrompt string `json:"negative_prompt"`
NumInferenceSteps int `json:"num_inference_steps"` // Number of inference steps (minimum: 1; maximum: 500)
GuidanceScale float32 `json:"guidance_scale"` // Scale for classifier-free guidance (minimum: 1; maximum: 20)
Scheduler string `json:"scheduler"` // (DDIM|K_EULER|DPMSolverMultistep|K_EULER_ANCESTRAL|PNDM|KLMS)
Seed int `json:"seed"` // Random seed (minimum: 0; maximum: 2147483647)
FromImage string `json:"from_image"` // Image to start from
UserID int `json:"user_id"`
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
}
- GET /api/images 圖片列表(全部)
- GET /api/images?user_id=xxx 圖片列表(指定用戶的)
- GET /api/images?tag=xxx 圖片列表(指定標籤的)
- POST /api/images 上傳圖片(單張)
- DELETE /api/images/{id} 刪除指定圖像
# 上傳圖片示例
response=$(curl -X POST -H "Content-Type: multipart/form-data" -F "file=@./data/test.jpeg" -b "session_id=$session_id" -s -w "%{http_code}" http://localhost:8080/api/images)
message "$response" "上傳圖片" true
提供webp生成服务
// GET /img/{id}-{version}-{width}-{height}-{fit}.{format}
// @id: 取图片ID
// @version: 取 hash 前 6 位
// @width: 所需宽度 1x 2x 3x 倍图直接输入尺寸
// @height: 所需高度 1x 2x 3x 倍图直接输入尺寸
// @fit: 裁切方式 cover contain fill auto
任務:
type Task struct {
ID int `json:"id" gorm:"primary_key"`
Name string `json:"name"`
Type string `json:"type"` // 任務類型(訓練|推理)
Status string `json:"status"` // (initial|ready|waiting|running|success|error)
Progress int `json:"progress"` // (0-100)
UserID int `json:"user_id"`
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
}
- GET /api/tasks 任務列表(全部任務)
- POST /api/tasks 創建任務
參數:
type Param struct {
// 字段不固定
}
- GET /api/params 參數列表(全部參數)
- GET /api/params/model 模型參數
賬戶:
type Account struct {
ID int `json:"id"`
Name string `json:"name"`
Email string `json:"email"`
Admin bool `json:"admin"`
SessionID string `json:"session_id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
- GET /api/account 當前賬戶信息
- GET /api/account 當前賬戶信息
服務器:
type Server struct {
ID int `json:"id" gorm:"primary_key"`
Name string `json:"name"`
Type string `json:"type"` // (訓練|推理)
IP string `json:"ip"`
Port int `json:"port"`
Status string `json:"status"` // (異常|初始化|閒置|就緒|工作中|關閉中)
UserName string `json:"username"`
Password string `json:"password"`
Models []map[string]interface{} `json:"models" gorm:"-"` // 數據庫不必保存
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
}
- GET /api/servers 服務器列表
列表模型:
type ListView struct {
Page int `json:"page"` // 当前页码
PageSize int `json:"page_size"` // 分頁大小
Total int `json:"total"` // 數據總量
Next bool `json:"next"` // 可否翻頁
List []interface{} `json:"list"` // 數據列表
}
列表接口-請求方式
Method | URL | Info |
---|---|---|
GET | /api/{name} | 分頁:顺序查询 |
GET | /api/{name}?page=1&pageSize=20 | 分頁:页码和數量 |
GET | /api/{name}?user_id=1234 | 篩選:按用戶 |
GET | /api/{name}?tag=xxx | 篩選:按標籤 |
GET | /api/{name}?public=true | 篩選:公開狀態(true |
POST | /api/{name} | 篩選:創建新對象 |
- 選取條件有多個的,以逗號分隔(並集)
- 過濾條件有多個的,複寫query(交集)
詳情接口-請求方式:
Method | URL | Info |
---|---|---|
GET | /api/{name}/{item_id} | 獲取對象詳情 |
PATCH | /api/{name}/{item_id} | 修改對象字段 |
DELETE | /api/{name}/{item_id} | 刪除對象 |
WS | /api/{name}/{item_id} | Websocket 連接對象 |
- GET查詢以外的操作都必須在headers中攜帶token驗證身份權限
- GET查詢私有模型也必須登錄, 否則不會被展示
Description
Languages
Go
94.6%
Shell
5.4%