feat: sync deployed v1.0.0-rc.38-custom.42
Sync production source including routing, billing, Astra detection and public uptime. Update custom build instructions and license packaging.
This commit is contained in:
1 parent
aa6c3f50f4
commit
ceddfd3d6b
828 files changed
+122253
-13702
No files matched your search
@@ -2,9 +2,9 @@ package dto
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
kitutil "github.com/QuantumNous/new-api/relaykit/relayconvert/kitutil"
|
||||
"github.com/QuantumNous/new-api/relaykit/types"
|
||||
@@ -14,6 +14,13 @@ import (
|
||||
// wrapped-negative n overflows quota calculation into a negative charge.
|
||||
const MaxImageN = 128
|
||||
|
||||
// ImageBillingParameters contains only the provider scalars parsed by request
|
||||
// validation. Keep this separate from the complete provider request payload.
|
||||
type ImageBillingParameters struct {
|
||||
N *uint `json:"n,omitempty"`
|
||||
PromptExtend *bool `json:"prompt_extend,omitempty"`
|
||||
}
|
||||
|
||||
type ImageRequest struct {
|
||||
Model string `json:"model"`
|
||||
Prompt string `json:"prompt" binding:"required"`
|
||||
@@ -39,7 +46,29 @@ type ImageRequest struct {
|
||||
UserId json.RawMessage `json:"user_id,omitempty"`
|
||||
Image json.RawMessage `json:"image,omitempty"`
|
||||
// 用匿名参数接收额外参数
|
||||
Extra map[string]json.RawMessage `json:"-"`
|
||||
Extra map[string]json.RawMessage `json:"-"`
|
||||
BillingParameters *ImageBillingParameters `json:"-"`
|
||||
}
|
||||
|
||||
// ImageCount resolves the validated request quantity. Top-level zero retains
|
||||
// its legacy default of one; an explicit provider count must be positive.
|
||||
func (i *ImageRequest) ImageCount(useProviderParameters bool) (int, error) {
|
||||
n := uint(1)
|
||||
if i.N != nil && *i.N != 0 {
|
||||
n = *i.N
|
||||
}
|
||||
if n > MaxImageN {
|
||||
return 0, fmt.Errorf("n must be an integer between 1 and %d", MaxImageN)
|
||||
}
|
||||
if parameters := i.BillingParameters; parameters != nil && parameters.N != nil {
|
||||
if *parameters.N > MaxImageN || useProviderParameters && *parameters.N == 0 {
|
||||
return 0, fmt.Errorf("parameters.n must be an integer between 1 and %d", MaxImageN)
|
||||
}
|
||||
if useProviderParameters {
|
||||
n = *parameters.N
|
||||
}
|
||||
}
|
||||
return int(n), nil
|
||||
}
|
||||
|
||||
func (i *ImageRequest) UnmarshalJSON(data []byte) error {
|
||||
@@ -131,29 +160,6 @@ func indexComma(s string) int {
|
||||
}
|
||||
|
||||
func (i *ImageRequest) GetTokenCountMeta() *types.TokenCountMeta {
|
||||
var sizeRatio = 1.0
|
||||
var qualityRatio = 1.0
|
||||
|
||||
if strings.HasPrefix(i.Model, "dall-e") {
|
||||
// Size
|
||||
if i.Size == "256x256" {
|
||||
sizeRatio = 0.4
|
||||
} else if i.Size == "512x512" {
|
||||
sizeRatio = 0.45
|
||||
} else if i.Size == "1024x1024" {
|
||||
sizeRatio = 1
|
||||
} else if i.Size == "1024x1792" || i.Size == "1792x1024" {
|
||||
sizeRatio = 2
|
||||
}
|
||||
|
||||
if i.Model == "dall-e-3" && i.Quality == "hd" {
|
||||
qualityRatio = 2.0
|
||||
if i.Size == "1024x1792" || i.Size == "1792x1024" {
|
||||
qualityRatio = 1.5
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
imageN := uint(1)
|
||||
if i.N != nil && *i.N > 0 {
|
||||
imageN = *i.N
|
||||
@@ -165,7 +171,7 @@ func (i *ImageRequest) GetTokenCountMeta() *types.TokenCountMeta {
|
||||
return &types.TokenCountMeta{
|
||||
CombineText: i.Prompt,
|
||||
MaxTokens: 1584,
|
||||
ImagePriceRatio: sizeRatio * qualityRatio,
|
||||
ImagePriceRatio: i.legacyDallePriceRatio(),
|
||||
BillingRatios: map[string]float64{"n": float64(imageN)},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user