2023-04-28 08:05:35 +08:00
sql
2023-04-28 07:28:40 +08:00
2023-04-28 08:05:35 +08:00
2023-04-28 06:32:33 +08:00
2023-04-28 01:04:23 +08:00
2023-04-28 08:05:35 +08:00
2023-04-28 08:05:35 +08:00
2023-04-28 08:05:35 +08:00
uid
2023-04-28 07:13:50 +08:00
2023-04-19 09:29:31 +08:00

ai 繪圖

ai 繪圖服務端(快速重構)

列表接口:

列表接口-請求方式

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查詢私有模型也必須登錄, 否則不會被展示

對象模型:

type ListView struct {
	Code     int           `json:"code"`
	Page     int           `json:"page"`
	PageSize int           `json:"page_size"`
	Total    int           `json:"total"`
	Next     bool          `json:"next"`
	List     []interface{} `json:"list"`
}

type Model struct {
	ID           int    `json:"id"`
	Name         string `json:"name"`
	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"`        // (waiting|running|success|error)
	Progress     int    `json:"progress"`      // (0-100)
	Tags         string `json:"tags"`
	CreatedAt    string `json:"created_at"`
	UpdatedAt    string `json:"updated_at"`
	UserID       int    `json:"user_id"`
}

type Task struct {
	ID        int    `json:"id"`
	Name      string `json:"name"`
	Type      string `json:"type"`     // 任務類型(訓練|推理)
	Status    string `json:"status"`   // (waiting|running|success|error)
	Progress  int    `json:"progress"` // (0-100)
	CreatedAt string `json:"created_at"`
	UpdatedAt string `json:"updated_at"`
	UserID    int    `json:"user_id"`
}

type Image struct {
	ID                int     `json:"id"`
	Name              string  `json:"name"`
	Width             int     `json:"width"`
	Height            int     `json:"height"`
	Prompt            string  `json:"prompt"`
	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
	CreatedAt         string  `json:"created_at"`
	UpdatedAt         string  `json:"updated_at"`
	UserID            int     `json:"user_id"`
}

type Tag struct {
	ID        int    `json:"id"`
	Name      string `json:"name"`
	CreatedAt string `json:"created_at"`
	UpdatedAt string `json:"updated_at"`
}

type User struct {
	ID        int    `json:"id"`
	Name      string `json:"name"`
	Email     string `json:"email"`
	CreatedAt string `json:"created_at"`
	UpdatedAt string `json:"updated_at"`
}
//// TODO
////训练专属模型模块
////创建模型=>前端对图片列表进行编辑=>获取右侧操作栏数据=>开始训练接=>我的数据集(模型列表)
////  創建模型
////      POST    /api/models
//        type:缺少创建模型的类型枚举
////    上传图片
////        缺少oss接口文档
////  训练模型
//        获取右侧操作栏数据(缺少接口)
////  开始训练接口websocket
////      会根据任务id一直返回进度=>(缺少接口)
////  我的数据集列表
////      缺少小图标统计描述,缺少任务id
////      GET     /api/models
////    模型详情
////        GET     /api/models/12345
////        缺少任务id和模型进度
////  工作状态列表接口
//        - 需要补充字段描述
////      GET /api/tasks

// ListView 列表分頁
{
    page: 1,             // 当前页码
    pageSize: 20,        // 分页数
    next: true,          // 是否存在下一页
    list: []             // 列表數據
}

// Image 圖片對象
{
    id: 1234,        // 原图ID
    width: 512,      // 原图宽度
    height: 512,     // 原图高度
    createdAt: '',   // 創建時間
    updatedAt: '',   // 更新時間
    user: {          // 来源用户
        id: 1234,
        user_name: 'LAST',
        createdAt: '',
        updatedAt: '',
    },
    article: {       // 来源文章
        id: 1234,
        title: 'GAMEX',
    }
}

// Task 任務對象
{
    id: 'xxxxx',     // 任務ID
    name: 'xxx',     // 任務名稱
    status: 'xxx',   // 任務狀態(waiting|running|success|error)
    progress: 100,   // 任務進度(0~100)
    type: '',        // 任務類型(train|Inference)
    data: {          // 任務數據
        id: '',      // 模型ID
        ...          // 其它參數
    },
    createdAt: '',   // 創建時間
    updatedAt: '',   // 更新時間
}

圖片列表

GET /api/images

{
    page: 1,             // 当前页码
    pageSize: 20,        // 分页数
    next: true,          // 是否存在下一页
    list: [{
        id: 1234,        // 原图ID
        width: 512,      // 原图宽度
        height: 512,     // 原图高度
        createdAt: '',   // 創建時間
        updatedAt: '',   // 更新時間
        user: {          // 来源用户
            id: 1234,
            user_name: 'LAST',
        },
        article: {       // 来源文章
            id: 1234,
            title: 'GAMEX',
        }
    }]
}

列表视图:(输出控制)

Method URL Info Status
GET /api/images 标准顺序查询 ok
GET /api/images?page=1&pageSize=20 指定页码和指定分页大小 ok
DELETE /api/images/{image_id} 刪除指定圖片

筛选规则:(数据过滤)

Method URL Info Statu
GET /api/images?user=1234 筛选指定某用户发表的图片
GET /api/images?choice=1234 筛选指定精选集下的图片
GET /api/images?like=1234 筛选指定用户点赞的图片
GET /api/images?tag=1234 筛选含有指定标签的图片
GET /api/images?tag=1234,1235 筛选含有多个标签之一的图片(并集)
GET /api/images?tag=1234&tag=1235 筛选含有指定多个标签的图片(交集)
GET /api/images?user=1234&tag=123 筛选指定用户的指定标签图片(交集)
GET /api/images?date=20220214+ 时间范围(之后)
GET /api/images?date=20220214- 时间范围(之前)
GET /api/images?date=2022~2023 时间范围(之间)

排序规则:(权重强化)

Method URL Info Status
GET /api/images?similar=1234 根据指定图片的相似图片(指定图片ID) ok
GET /api/images?sort=date+ 排序规则(相似图片查询时此项无效)
GET /api/images?sort=like 根据用户偏好推荐(指定用户的偏好)
GET /api/images?sort=history 根据浏览记录推荐(指定用户的记录)
GET /api/images?sort=choice 根据精选集推荐(指定精选集ID,取一组权重)
  • 注意, 筛选规则为多条件取交集, 单条件的复数取并集
  • 权重强化属于排序规则而非过滤规则

模型列表

GET /api/models

{
    page: 1,             // 当前页码
    pageSize: 20,        // 分页数
    next: true,          // 是否存在下一页
    list: [{
        id: 'xxxxx',     // 模型ID
        name: 'xxx',     // 模型名稱
        createdAt: '',   // 創建時間
        updatedAt: '',   // 更新時間
    }]
}

篩選規則:(數據過濾)

Method URL Info
GET /api/models?user=1234 僅取指定用戶的(按用戶ID過濾)
GET /api/models?tag=xxx 按標籤分類篩選
GET /api/models?public=true 僅取公開的
GET /api/models?public=false 僅取私有的
  • 如果未登錄, 返回的結果將過濾掉無權限查看的內容
  • 如果已登錄, 返回的結果將包含私有的

POST /api/models

// 發送數據
{
    name: '',    // 設定名稱
    type: '',    // 指定訓練類型
    source: '',  // 指定源模型ID
    type: '',    // 模型類型(RoLa|SD2|SD1.5)
    data: {
        oss:     [], // 直接上傳到OSS的圖片地址列表
        images:  [], // 指定圖片的ID們
        choices: [], // 精選集的ID們
    },   // 指定數據集(可以是上傳到OSS的文件列表, 也可以是已有的圖片ID, 也可以是精選集ID)
}

// 返回數據
{
    id: 'xxx',     // 模型ID
    name: '',      // 模型名稱
    status: '',    // 模型狀態(必須訓練完成的才可用)
    createdAt: '', // 創建時間
    updatedAt: '', // 更新時間
}

模型詳情

GET /api/models/{model_id}

{
    id: 'xxxxx',     // 模型ID
    name: 'xxx',     // 模型名稱
    createdAt: '',   // 創建時間
    updatedAt: '',   // 更新時間
}

PATCH /api/models/{model_id}

{
    name: 'xxx',     // 修改模型名稱
}
  • 修改指定字段, 只傳遞需要修改的字段

DELETE /api/models/{model_id}

  • 刪除指定模型

獲取標籤

GET /api/tags

{
    page: 1,             // 当前页码
    pageSize: 20,        // 分页数
    next: true,          // 是否存在下一页
    list: [{
        id: 'xxxxx',     // 標籤ID
        name: 'xxx',     // 標籤名稱
        createdAt: '',   // 創建時間
        updatedAt: '',   // 更新時間
    }]
}

篩選規則:(數據過濾)

Method URL Info
GET /api/tags?user=1234 按用戶ID篩選
GET /api/tags?tag=xxx 按標籤分類篩選
DELETE /api/tags/{tag_id} 刪除指定標籤

獲取任務

GET /api/tasks

{
    page: 1,             // 当前页码
    pageSize: 20,        // 分页数
    next: true,          // 是否存在下一页
    list: [{
        id: 'xxxxx',     // 任務ID
        name: 'xxx',     // 任務名稱
        status: 'xxx',   // 任務狀態(waiting|running|success|error)
        progress: 100,   // 任務進度(0~100)
        data: {},        // 任務數據
        createdAt: '',   // 創建時間
        updatedAt: '',   // 更新時間
    }]
}

篩選規則:(數據過濾)

Method URL Info
GET /api/tasks?user=1234 按用戶ID篩選
GET /api/tasks?tag=xxx 按標籤分類篩選
DELETE /api/tasks/{task_id} 刪除指定任務

監聽任務

WebSocket /api/tasks/{task_id}

{
    id: 'xxxx',    // 任務ID
    status: 'xxx', // 任務狀態(waiting|running|success|error)
    progress: 100, // 任務進度(0~100)
    data: {},      // 返回數據
}
  • 使用websocket建立連接以對指定任務監聽狀態變化
  • 離開頁面時,或是任務結束時, 應斷開websocket連接
  • 當任務狀態發生變化時, 服務端向瀏覽器主動發送消息
  • 返回數據:任務執行中爲預覽, 任務完成時爲生成結果
Description
ai 繪圖服務端(快速重構)
Readme 318 KiB
Languages
Go 94.6%
Shell 5.4%