mirror of
https://gitee.com/blackfox/geekai.git
synced 2024-12-02 12:17:42 +08:00
feat: allow user config third-party platform openai and mj api key
This commit is contained in:
parent
c83ac48bd2
commit
976da45bce
@ -65,6 +65,7 @@ type StableDiffusionConfig struct {
|
|||||||
type MidJourneyPlusConfig struct {
|
type MidJourneyPlusConfig struct {
|
||||||
Enabled bool // 如果启用了 MidJourney Plus,将会自动禁用原生的MidJourney服务
|
Enabled bool // 如果启用了 MidJourney Plus,将会自动禁用原生的MidJourney服务
|
||||||
ApiURL string // api 地址
|
ApiURL string // api 地址
|
||||||
|
Mode string // 绘画模式,可选值:fast/turbo/relax
|
||||||
CdnURL string // CDN 加速地址
|
CdnURL string // CDN 加速地址
|
||||||
ApiKey string
|
ApiKey string
|
||||||
NotifyURL string // 任务进度更新回调地址
|
NotifyURL string // 任务进度更新回调地址
|
||||||
|
@ -7,11 +7,10 @@ import (
|
|||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/imroc/req/v3"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
|
||||||
"github.com/imroc/req/v3"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var logger = logger2.GetLogger()
|
var logger = logger2.GetLogger()
|
||||||
@ -29,6 +28,9 @@ func NewClient(config types.MidJourneyPlusConfig) *Client {
|
|||||||
} else {
|
} else {
|
||||||
apiURL = config.ApiURL
|
apiURL = config.ApiURL
|
||||||
}
|
}
|
||||||
|
if config.Mode == "" {
|
||||||
|
config.Mode = "fast"
|
||||||
|
}
|
||||||
return &Client{Config: config, apiURL: apiURL}
|
return &Client{Config: config, apiURL: apiURL}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,7 +64,7 @@ type ErrRes struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Imagine(task types.MjTask) (ImageRes, error) {
|
func (c *Client) Imagine(task types.MjTask) (ImageRes, error) {
|
||||||
apiURL := fmt.Sprintf("%s/mj-fast/mj/submit/imagine", c.apiURL)
|
apiURL := fmt.Sprintf("%s/mj-%s/mj/submit/imagine", c.apiURL, c.Config.Mode)
|
||||||
body := ImageReq{
|
body := ImageReq{
|
||||||
BotType: "MID_JOURNEY",
|
BotType: "MID_JOURNEY",
|
||||||
Prompt: task.Prompt,
|
Prompt: task.Prompt,
|
||||||
@ -101,7 +103,7 @@ func (c *Client) Imagine(task types.MjTask) (ImageRes, error) {
|
|||||||
|
|
||||||
// Blend 融图
|
// Blend 融图
|
||||||
func (c *Client) Blend(task types.MjTask) (ImageRes, error) {
|
func (c *Client) Blend(task types.MjTask) (ImageRes, error) {
|
||||||
apiURL := fmt.Sprintf("%s/mj-fast/mj/submit/blend", c.apiURL)
|
apiURL := fmt.Sprintf("%s/mj-%s/mj/submit/blend", c.apiURL, c.Config.Mode)
|
||||||
body := ImageReq{
|
body := ImageReq{
|
||||||
BotType: "MID_JOURNEY",
|
BotType: "MID_JOURNEY",
|
||||||
Dimensions: "SQUARE",
|
Dimensions: "SQUARE",
|
||||||
@ -141,7 +143,7 @@ func (c *Client) Blend(task types.MjTask) (ImageRes, error) {
|
|||||||
|
|
||||||
// SwapFace 换脸
|
// SwapFace 换脸
|
||||||
func (c *Client) SwapFace(task types.MjTask) (ImageRes, error) {
|
func (c *Client) SwapFace(task types.MjTask) (ImageRes, error) {
|
||||||
apiURL := fmt.Sprintf("%s/mj-fast/mj/insight-face/swap", c.apiURL)
|
apiURL := fmt.Sprintf("%s/mj-%s/mj/insight-face/swap", c.apiURL, c.Config.Mode)
|
||||||
// 生成图片 Base64 编码
|
// 生成图片 Base64 编码
|
||||||
if len(task.ImgArr) != 2 {
|
if len(task.ImgArr) != 2 {
|
||||||
return ImageRes{}, errors.New("参数错误,必须上传2张图片")
|
return ImageRes{}, errors.New("参数错误,必须上传2张图片")
|
||||||
|
Loading…
Reference in New Issue
Block a user