AI 繪畫平臺難開發,難變現?試試 Stable Diffusion API Serverless 版解決方案

作者:王佳、江昱、筱姜

Stable Diffusion 模型,已經成爲 AI 行業從傳統深度學習時代走向 AIGC 時代的標誌性里程碑。越來越多的開發者藉助 stable-diffusion-webui(以下簡稱 SDWebUI)能力進行 AI 繪畫領域創業或者業務上新,獲得高流量及商業價值,但是面對多客戶、高併發的複雜場景,使用原生 Stable Diffusion API 會面臨以下挑戰:

1. 顯卡資源昂貴且難以購買,GPU 卡池管理技術門檻高: 高性能的 GPU 資源不僅價格昂貴,而且往往難以大規模採購。此外,GPU 卡池的有效管理和維護需要複雜的技術支持,也帶來了額外的挑戰。

2. 難以應對高併發: 原生的 Stable Diffusion API 採用單實例推理模式,其併發處理能力有限。在面對高併發場景時,尤其是併發請求具有大的波動性時,資源配置難以精確預測,從而可能導致系統錯誤和業務中斷。

3. 多模型切換難度大: 當不同模型的請求在高併發條件下同時發送到同一實例時,頻繁的模型切換成爲一個顯著的瓶頸。這種切換不僅消耗巨大,而且影響了推理效率,使得多模型部署在實際應用中變得複雜和低效。

爲了幫助用戶高效率、低成本應對企業級複雜場景,函數計算團隊正式推出 Stable Diffusion API Serverless 版解決方案,通過使用該方案,用戶可以充分利用 Stable Diffusion +Serverless 技術優勢快速開發上線 AI 繪畫應用,期待爲廣大開發者 AI 繪畫創業及變現提供思路。

基於 Stable Diffusion API Serverless 版解決方案搭建的,部署 AI 藝術字應用活動火熱進行中!生成姓氏頭像贏新春好禮,歡迎點擊 “閱讀原文” 體驗。

活動鏈接:https://developer.aliyun.com/topic/fcnewyear

應用場景

Stable Diffusion API Serverless 版本提供了多種可能性,以適應不同的應用場景和業務需求。

1. 個性化內容創作: 利用 Stable Diffusion API,內容創作者和數字藝術家可以快速生成個性化的藝術作品和圖像。例如,藝術家可以根據用戶的描述或關鍵詞,即時創作出獨特的藝術風格圖像,實現個性化的藝術創作和用戶互動。

2. 廣告和市場營銷: 在廣告和市場營銷領域,Stable Diffusion API 可以用來生成吸引人的視覺內容,從而增強廣告效果。例如,企業可以根據產品特性和目標受衆的偏好,快速創建多樣化的廣告圖像,以提升品牌形象和市場吸引力。

3. 遊戲和娛樂產業: 在遊戲和娛樂產業中,Stable Diffusion API 可以被用來增強用戶體驗,通過生成獨特的遊戲背景、角色和元素來豐富遊戲世界。例如,遊戲開發者可以使用 API 來設計獨特的遊戲環境和角色,爲玩家提供更豐富和個性化的遊戲體驗。

方案優勢

Stable Diffusion API Serverless 版本在多方面提供了顯著的優勢,特別是在簡化部署、成本效率、推理效率、資源管理、併發處理和用戶體驗上。以下是這些優勢的具體體現:

1. 上手簡單,快速部署: 藉助阿里雲 Serverless 應用中心,用戶可以實現快速部署,大幅簡化傳統 Stable Diffusion API 的複雜部署流程。這使得開發者能夠快速上手並專注於應用的開發和創新。

2. 計費靈活,成本效益顯著: Serverless 版本提供按需計費模式,用戶僅需爲實際使用的資源付費,無需預先投資昂貴的硬件。這種靈活的計費方式大幅降低了總體成本,尤其適合資源需求波動的場景。

3. 優化的模型管理,提升推理效率: 通過優化多模型的管理和部署,Serverless 版本有效提高了推理效率。減少模型切換和加載的頻率,確保了快速、穩定的推理性能。

4. 自動擴縮容,高效資源管理: 利用自動擴縮容機制,Serverless 版本根據實時需求靈活調整資源使用,避免了資源浪費並保障了服務的連續性。

5. 異步處理和排隊機制,優化併發處理: Serverless 版本通過引入異步處理和高效排隊機制,克服了高併發場景下的挑戰,保證了服務的高可用性和響應速度。

總之,Stable Diffusion API Serverless 版本集成了阿里雲 Serverless 技術的核心優勢,提供了一種高效、成本有效且用戶友好的解決方案,爲開發者在 AI 繪畫和其他 AI 應用領域的創新和商業化提供支持。

方案架構圖

名詞解釋:

  • admin,提供模型管理,包括模型上傳+刪除等
  • webui,提供界面化的調試功能,主要是模型和參數調整、插件安裝等,達到更好出圖效果
  • proxy,API 的前端服務,提供非推理之外的功能,主要包括結果、進度查詢等
  • control,控制推理實例最大併發實例數。通過控制 control 的併發度,控制下游多函數推理服務的實例數
  • agent+sd-api,推理服務
    • 一個模型(checkpoints)創建一個函數,每個函數支持彈多個實例,總的實例數通過 control 併發度進行控制。
    • 之所以一個模型(checkpoints)創建一個函數,是爲了避免多模型併發推理使用場景下的模型間的頻繁切換帶來的開銷,提升推理效率,進而達到給用戶降本的效果
    • sd_ 開頭的都是動態創建函數

注意事項:

  • 使用過程中會動態創建 sdapi 函數,每個 checkpoint 對應一個函數,並且會在 ots 中 function 表中記錄對應的函數詳情。如果想刪除動態創建的函數,請清理對應 ots 中 function 表的函數記錄,避免後續調用出問題
  • 異步推理結果會默認存放到 oss 中,存放到 image/default 路徑下

部署 Stable Diffusion API Serverless 版

準備工作

開通雲產品:

  • 函數計算 FC:用於提供 CPU+GPU 算力
  • 對象存儲 OSS:用於保存輸出圖片結果;同時存儲請求中的中轉圖片,便面直接傳遞 base64 導致超出請求的 body 限制
  • 表格存儲 Tablestore:用於存儲推理結果、函數信息等
  • 文件存儲 NAS:用於多節點共享存儲空間

部署 Stable Diffusion Serverless API

  1. 進入函數計算 FC 3.0 控制檯,點擊左側“應用”進行應用中心。如果老用戶曾經創建過應用,點擊“創建應用”也可直達應用中心

  1. 點擊“人工智能”分類,選擇“fc-stable-diffusion-v3”模版,點擊“立即創建”

  1. 確定詳細參數進行應用創建,您可以重點注意三個信息的填寫,其他使用默認值即可。
  • 地域:選擇距離您較近的地區,如果後續有更多出圖需要,可以考慮選擇海外地區,以方便 hugging face 等網站的連接
  • 命名空間:如果您已經部署多個 SD,請在這裏進行區分,新用戶可使用默認值
  • 繪圖類型:選擇藝術字

  1. 首次使用需要額外的權限,可以根據提示“前往授權”

  1. 點擊“創建應用”,勾選瞭解內容,點擊“同意並繼續部署”,等待大約 1 分鐘

  1. 生成 WebUI 域名(注意保護此鏈接不外傳以免耗費您賬戶的費用),不要點擊鏈接,直接切換到右側“Serverless API”

  1. 點擊“Serverless API”點擊“初始化 Serverless API”,再次確認已經開通“FC、OSS、OTS”三款產品,勾選“已閱讀”點擊“下一步”

  1. 進行“角色名”的授權,勾選“啓用 Serverless API”,OTS 實例創建方式可以默認“自動創建”,確認後等待大約 30 秒

  1. 創建好 Serverless API,就可以參考下面 API 定義開始進行測試生產使用

Stable Diffusion API Serverless 版支持的 API 詳情

API 接口主要分兩類:

  • 非推理類接口,用於結果和進度查詢、模型管理、應用重啓等
  • 推理類接口,文生圖、圖生圖、圖片放大等

具體可以參考: https://github.com/devsapp/serverless-stable-diffusion-api/blob/main/api/api.yaml

1. 模型相關 API

模型的註冊、更新和刪除都通過 admin 界面化操作即可

1.1 獲取模型列表 API

GET /modelsresponse:

[
  {
  "type": "stableDiffusion",
  "name": "model_v1",
  "ossPath": "/path/to/oss/model_v1",
  "etag": "3f786850e387550fdab836ed7e6dc881de23001b",
  "status": "loaded", // registering|loading|loaded|unloaded|deleted
  "registeredTime": "2023-01-01T12:00:00Z",
  "lastModificationTime": "2023-01-10T12:00:00Z"
  }
]

2. 推理相關 API

支持文生圖和圖生圖

支持同步模式和異步模式兩種,默認同步模式

  • 同步模式:header 中添加 {"Request-Type":"sync"},不添加默認爲同步模式
  • 異步模式:header 中添加

推理結果會同步存儲到 oss 和 ots 中,可以通過 /tasks/{taskId}/result 接口獲取推理結果(oss 圖片地址、推理參數等)

2.1 txt2img

POST /txt2img

request:其中 stable_diffusion_model, sd_vae 新加字段,其他保持跟原生 webui:txt2img 保持一致

其中 controlnet 中圖片支持兩種格式:

  • 圖片的 base64 編碼:備註:base64 請求存在超過 FC 異步請求 body 上限可能,如果超過上限請使用 oss 方式
  • oss 上圖片路徑,支持 png/jpg/jpeg
{
  "stable_diffusion_model": "diffusion_v1", // sd主模型
  "sd_vae": "vae_v1", // vae模型
  "enable_hr": true,
  "denoising_strength": 0.5,
  "firstphase_width": 640,
  "firstphase_height": 480,
  "hr_scale": 2,
  "hr_upscaler": "upscale_method_v1",
  "hr_second_pass_steps": 10,
  "hr_resize_x": 1280,
  "hr_resize_y": 960,
  "hr_sampler_name": "sampler_v1",
  "hr_prompt": "High resolution prompt",
  "hr_negative_prompt": "Negative high resolution prompt",
  "prompt": "Mountain landscape during sunset",
  "styles": [
    "style1",
    "style2"
  ],
  "seed": 123456,
  "subseed": 789,
  "subseed_strength": 5,
  "seed_resize_from_h": 480,
  "seed_resize_from_w": 640,
  "sampler_name": "sampler_v2",
  "batch_size": 32,
  "n_iter": 1000,
  "steps": 100,
  "cfg_scale": 1,
  "width": 640,
  "height": 480,
  "restore_faces": true,
  "tiling": false,
  "do_not_save_samples": false,
  "do_not_save_grid": false,
  "negative_prompt": "Avoid mountains",
  "eta": 5,
  "s_min_uncond": 1,
  "s_churn": 3,
  "s_tmax": 10,
  "s_tmin": 1,
  "s_noise": 2,
  "override_settings": {
    "settingKey": "settingValue"
  },
  "override_settings_restore_afterwards": true,
  "script_args": [
    {
      "argKey": "argValue"
    }
  ],
  "sampler_index": "index_v1",
  "script_name": "script_v1",
  "send_images": true,
  "save_images": true,
  "alwayson_scripts": {
    "controlnet": {
        "args": [
            {
                "image":"base64srcimg|image/default/xxxx.png", //支持傳輸base64和oss對應圖片path(png/jpg/jpeg)
                "enabled":True,
                "module":"canny",
                "model":"control_v11p_sd15_scribble",
                "weight":1,
                "resize_mode":"Crop and Resize",
                "low_vram":False,
                "processor_res":512,
                "threshold_a":100,
                "threshold_b":200,
                "guidance_start":0,
                "guidance_end":1,
                "pixel_perfect":True,
                "control_mode":"Balanced",
                "input_mode":"simple",
                "batch_images":"",
                "output_dir":"",
                "loopback":False
            }
        ]
    }
  }
}

response:

{
  "status":"succeeded", // 推理任務狀態
  "taskId":"1HmyrbhBJD", // 推理任務id, 後續結果獲取,進度查詢,取消推理都依賴於該id
  "ossUrl" :["xxxxx"] // 同步模式下返回的oss上圖片臨時地址(有一定時效性)
}

2.2 img2img

POST /img2img

request:其中 stable_diffusion_model,sd_vae 新加字段,其他保持跟原生 webui:img2img 保持一致其中 controlnet 和 init_images 中圖片支持兩種格式:

  • 圖片的 base64 編碼:備註:base64 請求存在超過 FC 異步請求 body 上限可能,如果超過上限請使用 oss 方式
  • oss 上圖片路徑,支持 png/jpg/jpeg
{
  "stable_diffusion_model": "diffusion_v2",  // sd主模型
  "sd_vae": "vae_v2",  // vae模型
  "init_images": [  //支持base64、oss圖片地址兩種格式
    "Base64SrcImg|ossPath",
    "Base64SrcImg|ossPath"
  ],
  "resize_mode": 1,
  "denoising_strength": 0.8,
  "image_cfg_scale": 2,
  "mask": "mask_path",
  "mask_blur": 3,
  "mask_blur_x": 2,
  "mask_blur_y": 2,
  "inpainting_fill": 4,
  "inpaint_full_res": true,
  "inpaint_full_res_padding": 2,
  "inpainting_mask_invert": 0,
  "initial_noise_multiplier": 5,
  "prompt": "Forest landscape",
  "styles": [
    "styleA",
    "styleB"
  ],
  "seed": 654321,
  "subseed": 987,
  "subseed_strength": 6,
  "seed_resize_from_h": 480,
  "seed_resize_from_w": 640,
  "sampler_name": "sampler_v3",
  "batch_size": 64,
  "n_iter": 500,
  "steps": 50,
  "cfg_scale": 2,
  "width": 1280,
  "height": 960,
  "restore_faces": false,
  "tiling": true,
  "do_not_save_samples": false,
  "do_not_save_grid": true,
  "negative_prompt": "Avoid forests",
  "eta": 6,
  "s_min_uncond": 2,
  "s_churn": 4,
  "s_tmax": 11,
  "s_tmin": 2,
  "s_noise": 3,
  "override_settings": {
    "settingKeyV2": "settingValueV2"
  },
  "override_settings_restore_afterwards": false,
  "script_args": [
    "arg1",
    "arg2"
  ],
  "sampler_index": "index_v2",
  "include_init_images": false,
  "script_name": "script_v2",
  "send_images": false,
  "save_images": true,
  "alwayson_scripts": {
    "controlnet": {
        "args": [
            {
                "image":"base64srcimg|ossPath", //支持base64、oss圖片地址兩種格式
                "enabled":True,
                "module":"canny",
                "model":"control_v11p_sd15_scribble",
                "weight":1,
                "resize_mode":"Crop and Resize",
                "low_vram":False,
                "processor_res":512,
                "threshold_a":100,
                "threshold_b":200,
                "guidance_start":0,
                "guidance_end":1,
                "pixel_perfect":True,
                "control_mode":"Balanced",
                "input_mode":"simple",
                "batch_images":"",
                "output_dir":"",
                "loopback":False
            }
        ]
    }
  }
}

response:

{
  "status":"succeeded", // 推理任務狀態
  "taskId":"1HmyrbhBJD", // 推理任務id, 後續結果獲取,進度查詢,取消推理都依賴於該id
  "ossUrl" :["xxxxx"] // 同步模式下返回的oss上圖片臨時地址(有一定時效性)
}

3. 圖片處理 API

3.1 圖片放大

圖片放大,支持單張圖片處理,暫不支持批量處理。respone 返回 taskId,調用獲取結果接口獲取圖片地址即可

其中 image 支持兩種格式:

  • 圖片的 base64
  • oss 上圖片路徑,支持 png/jpg/jpeg

POST /extra_images

request:

{
    "resize_mode": 0,
    "show_extras_results": True,
    "gfpgan_visibility": 0,
    "codeformer_visibility": 0,
    "codeformer_weight": 0,
    "upscaling_resize": 4,
    "upscaling_crop": True,
    "upscaler_1": "Lanczos",
    "upscaler_2": "None",
    "extras_upscaler_2_visibility": 0,
    "upscale_first": False,
    "image":self.file_to_base64(),
    "image" : "base64|ossPath" //支持傳輸base64和oss對應圖片path(png/jpg/jpeg)
}

response:

{
    "status":"succeeded",
    "taskId":"TovRrc0Jnr",
    "ossUrl" :["xxxxx"] // 同步模式下返回的oss上圖片臨時地址(有一定時效性)
}

4. 結果相關 API

4.1 獲取結果

通過 taskid 獲取推理結果

GET /tasks/{taskId}/result

response:

{
    "images":[
        "images/admin/Xldf9m80im_1.png" // images 推理結果, oss圖片path
    ],
    "ossUrl" :["xxxxx"], oss上圖片臨時地址(有一定時效性)
    "info":{                  // info 推理過程中產生信息
        "all_negative_prompts":[
            ""
        ],
        "all_prompts":[
            "cute beautiful blonde, very detailed, 21 years old, inoccent face, natural wave hair, blue eyes, high-res, masterpiece, best quality,intricate details, highly detailed,sharp focus, detailed skin,realistic skin texture,texture, detailed eyes \u003clora:shuimobysimV3:1\u003e"
        ],
        "all_seeds":[
            3896184641
        ],
        "all_subseeds":[
            6579621
        ],
        "alwayson_scripts":"",
        "batch_size":1,
        "cfg_scale":7,
        "clip_skip":1,
        "denoising_strength":0,
        "do_not_save_grid":false,
        "do_not_save_samples":false,
        "enable_hr":false,
        "eta":null,
        "extra_generation_params":{

        },
        "face_restoration_model":null,
        "firstphase_height":0,
        "firstphase_width":0,
        "height":512,
        "hr_negative_prompt":"",
        "hr_prompt":"",
        "hr_resize_x":0,
        "hr_resize_y":0,
        "hr_sampler_name":null,
        "hr_scale":2,
        "hr_second_pass_steps":0,
        "hr_upscaler":null,
        "index_of_first_image":0,
        "infotexts":[
            "cute beautiful blonde, very detailed, 21 years old, inoccent face, natural wave hair, blue eyes, high-res, masterpiece, best quality,intricate details, highly detailed,sharp focus, detailed skin,realistic skin texture,texture, detailed eyes \u003clora:shuimobysimV3:1\u003e\nSteps: 50, Sampler: Euler, CFG scale: 7.0, Seed: 3896184641, Size: 512x512, Model hash: 18ed2b6c48, Model: xxmix9realistic_v40, Denoising strength: 0, Version: v1.5.1"
        ],
        "is_using_inpainting_conditioning":false,
        "job_timestamp":"20230828073155",
        "n_iter":1,
        "negative_prompt":"",
        "override_settings":{

        },
        "override_settings_restore_afterwards":true,
        "prompt":"cute beautiful blonde, very detailed, 21 years old, inoccent face, natural wave hair, blue eyes, high-res, masterpiece, best quality,intricate details, highly detailed,sharp focus, detailed skin,realistic skin texture,texture, detailed eyes \u003clora:shuimobysimV3:1\u003e",
        "restore_faces":false,
        "s_churn":0,
        "s_min_uncond":0,
        "s_noise":1,
        "s_tmax":null,
        "s_tmin":0,
        "sampler_index":"Euler",
        "sampler_name":"Euler",
        "save_images":false,
        "script_args":[

        ],
        "script_name":null,
        "sd_model_hash":"18ed2b6c48",
        "seed":3896184641,
        "seed_resize_from_h":-1,
        "seed_resize_from_w":-1,
        "send_images":true,
        "steps":50,
        "styles":[

        ],
        "subseed":6579621,
        "subseed_strength":0,
        "tiling":false,
        "width":512
    },
    "parameters":{           // parameters實際推理過程中的參數
        "all_negative_prompts":[
            ""
        ],
        "all_prompts":[
            "cute beautiful blonde, very detailed, 21 years old, inoccent face, natural wave hair, blue eyes, high-res, masterpiece, best quality,intricate details, highly detailed,sharp focus, detailed skin,realistic skin texture,texture, detailed eyes \u003clora:shuimobysimV3:1\u003e"
        ],
        "all_seeds":[
            3896184641
        ],
        "all_subseeds":[
            6579621
        ],
        "alwayson_scripts":"",
        "batch_size":1,
        "cfg_scale":7,
        "clip_skip":1,
        "denoising_strength":0,
        "do_not_save_grid":false,
        "do_not_save_samples":false,
        "enable_hr":false,
        "eta":null,
        "extra_generation_params":{

        },
        "face_restoration_model":null,
        "firstphase_height":0,
        "firstphase_width":0,
        "height":512,
        "hr_negative_prompt":"",
        "hr_prompt":"",
        "hr_resize_x":0,
        "hr_resize_y":0,
        "hr_sampler_name":null,
        "hr_scale":2,
        "hr_second_pass_steps":0,
        "hr_upscaler":null,
        "index_of_first_image":0,
        "infotexts":[
            "cute beautiful blonde, very detailed, 21 years old, inoccent face, natural wave hair, blue eyes, high-res, masterpiece, best quality,intricate details, highly detailed,sharp focus, detailed skin,realistic skin texture,texture, detailed eyes \u003clora:shuimobysimV3:1\u003e\nSteps: 50, Sampler: Euler, CFG scale: 7.0, Seed: 3896184641, Size: 512x512, Model hash: 18ed2b6c48, Model: xxmix9realistic_v40, Denoising strength: 0, Version: v1.5.1"
        ],
        "is_using_inpainting_conditioning":false,
        "job_timestamp":"20230828073155",
        "n_iter":1,
        "negative_prompt":"",
        "override_settings":{

        },
        "override_settings_restore_afterwards":true,
        "prompt":"cute beautiful blonde, very detailed, 21 years old, inoccent face, natural wave hair, blue eyes, high-res, masterpiece, best quality,intricate details, highly detailed,sharp focus, detailed skin,realistic skin texture,texture, detailed eyes \u003clora:shuimobysimV3:1\u003e",
        "restore_faces":false,
        "s_churn":0,
        "s_min_uncond":0,
        "s_noise":1,
        "s_tmax":null,
        "s_tmin":0,
        "sampler_index":"Euler",
        "sampler_name":"Euler",
        "save_images":false,
        "script_args":[

        ],
        "script_name":null,
        "sd_model_hash":"18ed2b6c48",
        "seed":3896184641,
        "seed_resize_from_h":-1,
        "seed_resize_from_w":-1,
        "send_images":true,
        "steps":50,
        "styles":[

        ],
        "subseed":6579621,
        "subseed_strength":0,
        "tiling":false,
        "width":512
    },
    "taskId":"Xldf9m80im"
}

4.2 查詢進度

推理進度查詢

GET /tasks/{taskId}/progress,同 webui 中的 progress

response:

{
    "currentImage":"",
    "etaRelative":0.10594336,
    "progress":0.99,
    "state":{
        "interrupted":false,
        "job":"scripts_txt2img",
        "job_count":1,
        "job_no":0,
        "job_timestamp":"20230828073155",
        "sampling_step":49,
        "sampling_steps":50,
        "skipped":false
    },
    "taskId":"Xldf9m80im"
}

4.3 取消推理

取消對應任務POST /tasks/{taskId}/cancellation

5. 動態資源相關 API

5.1 獲取動態創建 sd 函數

獲取動態創建的 sdapi 函數

GET /list/sdapi/fucntions

response:

{
    "functions":[
        {
            "functionName":"sd_739f6de96fdbb66704296cd11ab3f96c182fde7f2cbbb127185b184a43414dea",
            "model":"chilloutmix_NiPrunedFp16Fix.safetensors"
        }
    ],
    "status":"success"
}

5.2 更新動態創建 sd 資源

批量更新動態創建 sd 函數資源,比如鏡像、環境變量、cpu、顯存等。其中 models 不指定代表更新所有動態創建 sd 函數資源

POST /batch_update_sd_resource

request:

{
    "models": ["chilloutmix_NiPrunedFp16Fix.safetensors"],
    "cpu": 4,
    "memorySize": 16384, // MB
    "image": "xxx",
    "extraArgs": "--api --nowebui --no-hashing",
    "instanceType": "fc.gpu.ampere.1",
    "gpuMemorySize": 16384, // MB
    "timeout": 60, //s
    "env": {},
    "vpcConfig":{
        "securityGroupId":"xxx",
        "vSwitchIds":[
            "xxx"
        ],
        "vpcId":"xxx"
    },
    "nasConfig": {
      "groupId" : 123,
      "mountPoints": [
        {
        "enableTLS": true|false,
        "mountDir": "xxx",
        "serverAddr": "dddd"
        }
      ],
      "userId": 123
    },
    "mountPoints":[
      {
        "bucketName": "xxx",
        "bucketPath": "xxx",
        "endpoint": "xxx",
        "mountDir": "ddd",
        "readOnly": true|false
      }
    ]
}

response:

{
  "status": "success|fail",
  "failFuncList": ["xxx"], // 失敗的函數列表
  "errMsg": ["xxxx"] //錯誤信息
}

5.3 批量刪除動態創建函數接口

批量刪除動態創建的函數,入參函數列表

POST /del/sd/functions

request:

{
    "functions":["xxxxx"]
}
responese
// status_code=200
{
    "status":"success"
}
// status_code=500
{
    "fails":[
        {
            "err":"xxxx",
            "functionName":"xxxx"
        }
    ],
    "status":"fail"
}

6. 其他接口

  • 原生 webui-api 接口,除了上面支持的功能接口,剩下的 api 接口
  • 插件自定義的 api 接口

其中支持同步、異步模式+任務模式:

  • 同步/異步,header 中設置 Request-Type,其中值 sync 爲同步模式,async 爲異步模式,不設置該值默認爲同步模式,異步獲取結果需要從上面的獲取結果接口(tasks/{taskId}/result)獲取最終的結果
  • 任務模式,header 中設置 Task-Flag,會將結果保存到 ots 進行持久化,同樣支持同步+異步

最佳實踐

爲了方便大家直觀體驗一下該解決方案成效,基於函數計算團隊開發者的基於 Stable Diffusion Serverless API 解決方案搭建的 AI 文字生成應用,作爲一個實驗 demo 開放體驗,期待爲廣大開發者 AI 繪畫創業及變現提供一些有益思考。直接參加體驗活動,送好禮!

活動鏈接:https://developer.aliyun.com/topic/fcnewyear

部署成功的 AI 繪畫應用:

眯着眼睛看看是什麼字?

開源代碼
github : https://github.com/devsapp/serverless-stable-diffusion-api

可以自己基於開源代碼加工開發

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章