2023-06-20 19:57:39 +08:00
2023-05-14 07:57:23 +08:00
2023-06-20 19:02:32 +08:00
2023-06-20 19:57:39 +08:00
2023-05-16 02:56:25 +08:00
2023-06-18 12:42:59 +08:00
2023-06-07 14:25:04 +08:00
2023-06-07 14:44:48 +08:00
2023-06-18 12:55:11 +08:00
img
2023-06-07 15:30:33 +08:00
2023-06-07 14:25:04 +08:00
2023-06-06 15:55:56 +08:00

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"`
}

會話:

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"`
}

數據集:

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

標籤:

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"`
}

模型:

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"`
}

圖像:

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"`
}
# 上傳圖片示例
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"`
}

參數:

type Param struct {
    // 字段不固定
}

賬戶:

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"`
}

服務器:

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"`
}

列表模型:

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
ai 繪圖服務端(快速重構)
Readme 318 KiB
Languages
Go 94.6%
Shell 5.4%