Merge branch 'main' into patch/images-edits

This commit is contained in:
Laisky.Cai
2024-05-28 11:11:03 +08:00
committed by GitHub
35 changed files with 637 additions and 513 deletions

View File

@@ -53,6 +53,16 @@ func (e GeneralErrorResponse) ToMessage() string {
}
func RelayErrorHandler(resp *http.Response) (ErrorWithStatusCode *model.ErrorWithStatusCode) {
if resp == nil {
return &model.ErrorWithStatusCode{
StatusCode: 500,
Error: model.Error{
Message: "resp is nil",
Type: "upstream_error",
Code: "bad_response",
},
}
}
ErrorWithStatusCode = &model.ErrorWithStatusCode{
StatusCode: resp.StatusCode,
Error: model.Error{

View File

@@ -208,6 +208,9 @@ func getMappedModelName(modelName string, mapping map[string]string) (string, bo
func isErrorHappened(meta *meta.Meta, resp *http.Response) bool {
if resp == nil {
if meta.ChannelType == channeltype.AwsClaude {
return false
}
return true
}
if resp.StatusCode != http.StatusOK {

View File

@@ -57,6 +57,11 @@ func RelayImageHelper(c *gin.Context, relayMode int) *relaymodel.ErrorWithStatus
return openai.ErrorWrapper(err, "get_image_cost_ratio_failed", http.StatusInternalServerError)
}
imageModel := imageRequest.Model
// Convert the original image model
imageRequest.Model, _ = getMappedModelName(imageRequest.Model, billingratio.ImageOriginModelName)
c.Set("response_format", imageRequest.ResponseFormat)
var requestBody io.Reader
if strings.ToLower(c.GetString(ctxkey.ContentType)) == "application/json" &&
isModelMapped || meta.ChannelType == channeltype.Azure { // make Azure channel request body
@@ -92,7 +97,7 @@ func RelayImageHelper(c *gin.Context, relayMode int) *relaymodel.ErrorWithStatus
requestBody = bytes.NewBuffer(jsonStr)
}
modelRatio := billingratio.GetModelRatio(imageRequest.Model)
modelRatio := billingratio.GetModelRatio(imageModel)
groupRatio := billingratio.GetGroupRatio(meta.Group)
ratio := modelRatio * groupRatio
userQuota, err := model.CacheGetUserQuota(ctx, meta.UserId)