fix: ali image model cannot be found and the error with the incorrect return format.

This commit is contained in:
mlkt 2024-05-26 02:52:22 +08:00
parent e9981fff36
commit 076ec68989
3 changed files with 8 additions and 2 deletions

View File

@ -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)

View File

@ -69,7 +69,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

View File

@ -91,6 +91,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)
}