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