diff --git a/Dockerfile b/Dockerfile index ade561e408..01a522ddb1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,15 +5,16 @@ COPY ./VERSION . COPY ./web . WORKDIR /web/default +RUN npm config set registry https://registry.npmmirror.com RUN npm install RUN DISABLE_ESLINT_PLUGIN='true' REACT_APP_VERSION=$(cat VERSION) npm run build WORKDIR /web/berry -RUN npm install +RUN npm install --force RUN DISABLE_ESLINT_PLUGIN='true' REACT_APP_VERSION=$(cat VERSION) npm run build WORKDIR /web/air -RUN npm install +RUN npm install --force RUN DISABLE_ESLINT_PLUGIN='true' REACT_APP_VERSION=$(cat VERSION) npm run build FROM golang:alpine AS builder2 @@ -22,7 +23,8 @@ RUN apk add --no-cache g++ ENV GO111MODULE=on \ CGO_ENABLED=1 \ - GOOS=linux + GOOS=linux \ + GOPROXY=https://goproxy.cn,direct WORKDIR /build ADD go.mod go.sum ./ diff --git a/relay/adaptor/aiproxy/adaptor.go b/relay/adaptor/aiproxy/adaptor.go index 42d49c0a45..f2485727a9 100644 --- a/relay/adaptor/aiproxy/adaptor.go +++ b/relay/adaptor/aiproxy/adaptor.go @@ -9,6 +9,7 @@ import ( "github.com/songquanpeng/one-api/relay/model" "io" "net/http" + "strings" ) type Adaptor struct { @@ -20,12 +21,18 @@ func (a *Adaptor) Init(meta *meta.Meta) { } func (a *Adaptor) GetRequestURL(meta *meta.Meta) (string, error) { - return fmt.Sprintf("%s/api/library/ask", meta.BaseURL), nil + baseURL := meta.BaseURL + if strings.HasSuffix(meta.APIKey, "#vip") { + baseURL = "https://apivip.aiproxy.io" + } + return fmt.Sprintf("%s/api/library/ask", baseURL), nil } func (a *Adaptor) SetupRequestHeader(c *gin.Context, req *http.Request, meta *meta.Meta) error { adaptor.SetupCommonRequestHeader(c, req, meta) - req.Header.Set("Authorization", "Bearer "+meta.APIKey) + apiKey := meta.APIKey + apiKey = strings.TrimSuffix(apiKey, "#vip") + req.Header.Set("Authorization", "Bearer "+apiKey) return nil } diff --git a/relay/adaptor/ali/image.go b/relay/adaptor/ali/image.go index 8261803dbe..2b34d17e99 100644 --- a/relay/adaptor/ali/image.go +++ b/relay/adaptor/ali/image.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "github.com/gin-gonic/gin" + "github.com/songquanpeng/one-api/common/ctxkey" "github.com/songquanpeng/one-api/common/helper" "github.com/songquanpeng/one-api/common/logger" "github.com/songquanpeng/one-api/relay/adaptor/openai" @@ -19,7 +20,11 @@ import ( func ImageHandler(c *gin.Context, resp *http.Response) (*model.ErrorWithStatusCode, *model.Usage) { apiKey := c.Request.Header.Get("Authorization") apiKey = strings.TrimPrefix(apiKey, "Bearer ") - responseFormat := c.GetString("response_format") + + var responseFormat string + if req, exists := c.Get(ctxkey.ConvertedRequest); exists { + responseFormat = req.(*ImageRequest).ResponseFormat + } var aliTaskResponse TaskResponse responseBody, err := io.ReadAll(resp.Body) diff --git a/relay/adaptor/ali/main.go b/relay/adaptor/ali/main.go index f9039dbe49..b344875838 100644 --- a/relay/adaptor/ali/main.go +++ b/relay/adaptor/ali/main.go @@ -71,7 +71,7 @@ func ConvertEmbeddingRequest(request model.GeneralOpenAIRequest) *EmbeddingReque func ConvertImageRequest(request model.ImageRequest) *ImageRequest { var imageRequest ImageRequest imageRequest.Input.Prompt = request.Prompt - imageRequest.Model = request.Model + imageRequest.Model = strings.TrimPrefix(request.Model, "ali-") imageRequest.Parameters.Size = strings.Replace(request.Size, "x", "*", -1) imageRequest.Parameters.N = request.N imageRequest.ResponseFormat = request.ResponseFormat diff --git a/relay/adaptor/openai/adaptor.go b/relay/adaptor/openai/adaptor.go index 5dc395adfa..cd3339fd01 100644 --- a/relay/adaptor/openai/adaptor.go +++ b/relay/adaptor/openai/adaptor.go @@ -50,6 +50,11 @@ func (a *Adaptor) GetRequestURL(meta *meta.Meta) (string, error) { return minimax.GetRequestURL(meta) case channeltype.Doubao: return doubao.GetRequestURL(meta) + case channeltype.AIProxy: + if strings.HasSuffix(meta.APIKey, "#vip") { + return GetFullRequestURL("https://apivip.aiproxy.io", meta.RequestURLPath, meta.ChannelType), nil + } + fallthrough case channeltype.Novita: return novita.GetRequestURL(meta) default: @@ -63,7 +68,11 @@ func (a *Adaptor) SetupRequestHeader(c *gin.Context, req *http.Request, meta *me req.Header.Set("api-key", meta.APIKey) return nil } - req.Header.Set("Authorization", "Bearer "+meta.APIKey) + apiKey := meta.APIKey + if meta.ChannelType == channeltype.AIProxy { + apiKey = strings.TrimSuffix(apiKey, "#vip") + } + req.Header.Set("Authorization", "Bearer "+apiKey) if meta.ChannelType == channeltype.OpenRouter { req.Header.Set("HTTP-Referer", "https://github.com/songquanpeng/one-api") req.Header.Set("X-Title", "One API") diff --git a/relay/billing/ratio/image.go b/relay/billing/ratio/image.go index ced0c6678c..640fb0af84 100644 --- a/relay/billing/ratio/image.go +++ b/relay/billing/ratio/image.go @@ -51,6 +51,4 @@ var ImagePromptLengthLimitations = map[string]int{ } var ImageOriginModelName = map[string]string{ - "ali-stable-diffusion-xl": "stable-diffusion-xl", - "ali-stable-diffusion-v1.5": "stable-diffusion-v1.5", } diff --git a/relay/controller/image.go b/relay/controller/image.go index 1e06e858ef..7d874cc5e8 100644 --- a/relay/controller/image.go +++ b/relay/controller/image.go @@ -164,6 +164,7 @@ func RelayImageHelper(c *gin.Context, relayMode int) *relaymodel.ErrorWithStatus if err != nil { return openai.ErrorWrapper(err, "marshal_image_request_failed", http.StatusInternalServerError) } + c.Set(ctxkey.ConvertedRequest, finalRequest) requestBody = bytes.NewBuffer(jsonStr) } diff --git a/relay/controller/text.go b/relay/controller/text.go index 52ee9949ae..18dd2d3deb 100644 --- a/relay/controller/text.go +++ b/relay/controller/text.go @@ -4,13 +4,13 @@ import ( "bytes" "encoding/json" "fmt" + "github.com/songquanpeng/one-api/relay/adaptor" "io" "net/http" "github.com/gin-gonic/gin" "github.com/songquanpeng/one-api/common/logger" "github.com/songquanpeng/one-api/relay" - "github.com/songquanpeng/one-api/relay/adaptor" "github.com/songquanpeng/one-api/relay/adaptor/openai" "github.com/songquanpeng/one-api/relay/apitype" "github.com/songquanpeng/one-api/relay/billing" @@ -54,7 +54,6 @@ func RelayTextHelper(c *gin.Context) *model.ErrorWithStatusCode { } adaptor.Init(meta) - // get request body requestBody, err := getRequestBody(c, meta, textRequest, adaptor) if err != nil { return openai.ErrorWrapper(err, "convert_request_failed", http.StatusInternalServerError)