Merge 04aee84485
into fdd7bf41c0
This commit is contained in:
commit
a29aacd063
@ -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 ./
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -72,7 +72,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
|
||||
|
@ -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")
|
||||
|
@ -61,6 +61,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",
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user