Skip to content
Closed
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
680271d
feat(playground): add video size/duration/quality selectors
LJR199887 Mar 27, 2026
988b297
Merge pull request #1 from LJR199887/codex/find-project-purpose
LJR199887 Mar 27, 2026
9db210d
fix(playground): route video models to video endpoint
LJR199887 Mar 28, 2026
f5b1a79
Merge branch 'QuantumNous:main' into main
LJR199887 Mar 28, 2026
6658556
fix(playground): always route video models to video endpoint
LJR199887 Mar 28, 2026
d31fbb6
Merge branch 'main' into codex/find-project-purpose-3vdzr3
LJR199887 Mar 28, 2026
8446231
Merge pull request #2 from LJR199887/codex/find-project-purpose-3vdzr3
LJR199887 Mar 28, 2026
90063cb
fix(playground): use user-authenticated pg video generation endpoint
LJR199887 Mar 28, 2026
2186b57
Merge branch 'main' into codex/find-project-purpose-8t1iot
LJR199887 Mar 28, 2026
8e89b09
Merge pull request #3 from LJR199887/codex/find-project-purpose-8t1iot
LJR199887 Mar 28, 2026
989f667
feat(playground): show video content URL after task creation
LJR199887 Mar 28, 2026
37f5126
Merge branch 'main' into codex/find-project-purpose
LJR199887 Mar 28, 2026
e20c678
Merge pull request #4 from LJR199887/codex/find-project-purpose
LJR199887 Mar 28, 2026
629be09
Revert "Add playground video generation endpoints and UI; wire video …
LJR199887 Mar 28, 2026
b69a41e
Merge pull request #5 from LJR199887/revert-4-codex/find-project-purpose
LJR199887 Mar 28, 2026
8e19212
fix grok video url response
LJR199887 Mar 28, 2026
2933917
avoid duplicate video preview
LJR199887 Mar 28, 2026
df6cb95
add grok video preset options
LJR199887 Mar 28, 2026
37f727c
fix grok video quality request handling
LJR199887 Mar 28, 2026
b1b647d
fix grok 720p video request aliases
LJR199887 Mar 28, 2026
b1a56ec
Fix grok imagine playground image routing
LJR199887 Mar 28, 2026
8671548
Fix playground image relay mode
LJR199887 Mar 28, 2026
3ca517d
Handle empty prompt for grok imagine edit
LJR199887 Mar 28, 2026
ca554ba
Fix grok imagine video endpoint display
LJR199887 Mar 28, 2026
1ba2229
Add playground image size selector
LJR199887 Mar 28, 2026
2c76490
Expand playground image size options
LJR199887 Mar 28, 2026
46909d2
Pass image size to xai upstream
LJR199887 Mar 28, 2026
6935974
Fix grok image size options
LJR199887 Mar 28, 2026
dd00fc6
Add missing channel test endpoint types
LJR199887 Mar 28, 2026
c1e2dd1
Add adobe2api playground controls
LJR199887 Mar 28, 2026
2f2002b
Fix adobe image aspect ratio controls
LJR199887 Mar 28, 2026
7626c2a
Show model names in task logs
LJR199887 Mar 29, 2026
b0fa9d3
Add per-seconds task pricing
LJR199887 Mar 29, 2026
99a6c0d
feat: show model second-based pricing
LJR199887 Mar 29, 2026
0e364e5
feat: support duration billing mode in pricing editor
LJR199887 Mar 29, 2026
f0c3684
fix: remove duplicate duration pricing preview branch
LJR199887 Mar 29, 2026
9338346
feat: improve duration pricing display in model details
LJR199887 Mar 29, 2026
e7cde69
fix: improve duration pricing card preview
LJR199887 Mar 29, 2026
0277e88
feat: add playground creation center
LJR199887 Mar 29, 2026
fb1bea0
feat: separate creation center from playground
LJR199887 Mar 29, 2026
f8a210c
Revert "feat: separate creation center from playground"
LJR199887 Mar 29, 2026
cdb0895
Revert "feat: add playground creation center"
LJR199887 Mar 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions common/endpoint_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ var defaultEndpointInfoMap = map[constant.EndpointType]EndpointInfo{
constant.EndpointTypeGemini: {Path: "/v1beta/models/{model}:generateContent", Method: "POST"},
constant.EndpointTypeJinaRerank: {Path: "/v1/rerank", Method: "POST"},
constant.EndpointTypeImageGeneration: {Path: "/v1/images/generations", Method: "POST"},
constant.EndpointTypeImageEdit: {Path: "/v1/images/edits", Method: "POST"},
constant.EndpointTypeEmbeddings: {Path: "/v1/embeddings", Method: "POST"},
constant.EndpointTypeOpenAIVideo: {Path: "/v1/video/generations", Method: "POST"},
}

// GetDefaultEndpointInfo 返回指定端点类型的默认信息以及是否存在
Expand Down
4 changes: 3 additions & 1 deletion common/endpoint_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ func GetEndpointTypesByChannelType(channelType int, modelName string) []constant
endpointTypes = []constant.EndpointType{constant.EndpointTypeOpenAI}
}
}
if IsImageGenerationModel(modelName) {
if IsImageEditModel(modelName) {
endpointTypes = append([]constant.EndpointType{constant.EndpointTypeImageEdit}, endpointTypes...)
} else if IsImageGenerationModel(modelName) {
// add to first
endpointTypes = append([]constant.EndpointType{constant.EndpointTypeImageGeneration}, endpointTypes...)
}
Expand Down
53 changes: 53 additions & 0 deletions common/endpoint_type_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package common

import (
"testing"

"github.com/QuantumNous/new-api/constant"
)

func TestGetEndpointTypesByChannelTypeRecognizesGrokImagineImageModels(t *testing.T) {
tests := []struct {
name string
channel int
model string
expected constant.EndpointType
}{
{
name: "grok imagine 1.0 generation",
channel: constant.ChannelTypeXai,
model: "grok-imagine-1.0",
expected: constant.EndpointTypeImageGeneration,
},
{
name: "grok imagine 1.0 fast generation",
channel: constant.ChannelTypeXai,
model: "grok-imagine-1.0-fast",
expected: constant.EndpointTypeImageGeneration,
},
{
name: "grok imagine 1.0 edit",
channel: constant.ChannelTypeXai,
model: "grok-imagine-1.0-edit",
expected: constant.EndpointTypeImageEdit,
},
{
name: "grok imagine video stays video",
channel: constant.ChannelTypeSora,
model: "grok-imagine-1.0-video",
expected: constant.EndpointTypeOpenAIVideo,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := GetEndpointTypesByChannelType(tt.channel, tt.model)
if len(got) == 0 {
t.Fatalf("expected endpoint types for %s", tt.model)
}
if got[0] != tt.expected {
t.Fatalf("expected first endpoint %s, got %s", tt.expected, got[0])
}
})
}
}
24 changes: 24 additions & 0 deletions common/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ var (
"dall-e-3",
"dall-e-2",
"gpt-image-1",
"exact:grok-imagine-1.0",
"exact:grok-imagine-1.0-fast",
"prefix:imagen-",
"flux-",
"flux.1-",
}
ImageEditModels = []string{
"exact:grok-imagine-1.0-edit",
}
OpenAITextModels = []string{
"gpt-",
"o1",
Expand All @@ -38,6 +43,25 @@ func IsOpenAIResponseOnlyModel(modelName string) bool {
func IsImageGenerationModel(modelName string) bool {
modelName = strings.ToLower(modelName)
for _, m := range ImageGenerationModels {
if strings.HasPrefix(m, "exact:") && modelName == strings.TrimPrefix(m, "exact:") {
return true
}
if strings.Contains(modelName, m) {
return true
}
if strings.HasPrefix(m, "prefix:") && strings.HasPrefix(modelName, strings.TrimPrefix(m, "prefix:")) {
return true
}
}
return false
}

func IsImageEditModel(modelName string) bool {
modelName = strings.ToLower(modelName)
for _, m := range ImageEditModels {
if strings.HasPrefix(m, "exact:") && modelName == strings.TrimPrefix(m, "exact:") {
return true
}
if strings.Contains(modelName, m) {
return true
}
Expand Down
1 change: 1 addition & 0 deletions constant/endpoint_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const (
EndpointTypeGemini EndpointType = "gemini"
EndpointTypeJinaRerank EndpointType = "jina-rerank"
EndpointTypeImageGeneration EndpointType = "image-generation"
EndpointTypeImageEdit EndpointType = "image-edit"
EndpointTypeEmbeddings EndpointType = "embeddings"
EndpointTypeOpenAIVideo EndpointType = "openai-video"
//EndpointTypeMidjourney EndpointType = "midjourney-proxy"
Expand Down
87 changes: 78 additions & 9 deletions controller/playground.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,91 @@ func Playground(c *gin.Context) {
return
}

userId := c.GetInt("id")
if newAPIError = setupPlaygroundTokenContext(c, fmt.Sprintf("playground-%s", relayInfo.UsingGroup), relayInfo.UsingGroup); newAPIError != nil {
return
}

Relay(c, types.RelayFormatOpenAI)
}

// Write user context to ensure acceptUnsetRatio is available
func PlaygroundVideoSubmit(c *gin.Context) {
var newAPIError *types.NewAPIError
defer func() {
if newAPIError != nil {
c.JSON(newAPIError.StatusCode, gin.H{
"error": newAPIError.ToOpenAIError(),
})
}
}()
if newAPIError = setupPlaygroundTokenContext(c, "playground-video", c.GetString("group")); newAPIError != nil {
return
}
RelayTask(c)
}

func PlaygroundImageGenerations(c *gin.Context) {
var newAPIError *types.NewAPIError
defer func() {
if newAPIError != nil {
c.JSON(newAPIError.StatusCode, gin.H{
"error": newAPIError.ToOpenAIError(),
})
}
}()
if newAPIError = setupPlaygroundTokenContext(c, "playground-image", c.GetString("group")); newAPIError != nil {
return
}
Relay(c, types.RelayFormatOpenAIImage)
}

func PlaygroundImageEdits(c *gin.Context) {
var newAPIError *types.NewAPIError
defer func() {
if newAPIError != nil {
c.JSON(newAPIError.StatusCode, gin.H{
"error": newAPIError.ToOpenAIError(),
})
}
}()
if newAPIError = setupPlaygroundTokenContext(c, "playground-image-edit", c.GetString("group")); newAPIError != nil {
return
}
Relay(c, types.RelayFormatOpenAIImage)
}

func PlaygroundVideoFetch(c *gin.Context) {
var newAPIError *types.NewAPIError
defer func() {
if newAPIError != nil {
c.JSON(newAPIError.StatusCode, gin.H{
"error": newAPIError.ToOpenAIError(),
})
}
}()
if newAPIError = setupPlaygroundTokenContext(c, "playground-video-fetch", c.GetString("group")); newAPIError != nil {
return
}
RelayTaskFetch(c)
}
Comment on lines +45 to +103

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Keep the access-token restriction consistent on the new /pg handlers.

Playground still rejects use_access_token, but these new image/video handlers skip that check and relay immediately after token setup. That opens a policy gap between the existing playground endpoint and /pg/images/* / /pg/video/*.

🛠️ Proposed fix
+func rejectPlaygroundAccessToken(c *gin.Context) *types.NewAPIError {
+	if c.GetBool("use_access_token") {
+		return types.NewError(errors.New("暂不支持使用 access token"), types.ErrorCodeAccessDenied, types.ErrOptionWithSkipRetry())
+	}
+	return nil
+}
+
 func PlaygroundVideoSubmit(c *gin.Context) {
 	var newAPIError *types.NewAPIError
 	defer func() {
 		if newAPIError != nil {
 			c.JSON(newAPIError.StatusCode, gin.H{
 				"error": newAPIError.ToOpenAIError(),
 			})
 		}
 	}()
+	if newAPIError = rejectPlaygroundAccessToken(c); newAPIError != nil {
+		return
+	}
 	if newAPIError = setupPlaygroundTokenContext(c, "playground-video", c.GetString("group")); newAPIError != nil {
 		return
 	}
 	RelayTask(c)
 }

Apply the same guard in PlaygroundImageGenerations, PlaygroundImageEdits, and PlaygroundVideoFetch.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@controller/playground.go` around lines 45 - 103, The new handlers
PlaygroundImageGenerations, PlaygroundImageEdits, and PlaygroundVideoFetch skip
the same access-token rejection that the existing Playground handler enforces;
after calling setupPlaygroundTokenContext in each of these functions, add the
identical guard from the Playground handler that checks for use_access_token and
sets/returns the same *types.NewAPIError when access tokens are present, before
calling Relay or RelayTaskFetch, so the policy is consistent across /pg
endpoints.


func setupPlaygroundTokenContext(c *gin.Context, tokenName string, tokenGroup string) *types.NewAPIError {
userId := c.GetInt("id")
userCache, err := model.GetUserCache(userId)
if err != nil {
newAPIError = types.NewError(err, types.ErrorCodeQueryDataError, types.ErrOptionWithSkipRetry())
return
return types.NewError(err, types.ErrorCodeQueryDataError, types.ErrOptionWithSkipRetry())
}
userCache.WriteContext(c)

if tokenGroup == "" {
tokenGroup = c.GetString("group")
}
if tokenGroup == "" {
tokenGroup = userCache.Group
}
tempToken := &model.Token{
UserId: userId,
Name: fmt.Sprintf("playground-%s", relayInfo.UsingGroup),
Group: relayInfo.UsingGroup,
Name: tokenName,
Group: tokenGroup,
}
_ = middleware.SetupContextForToken(c, tempToken)

Relay(c, types.RelayFormatOpenAI)
return nil
}
37 changes: 37 additions & 0 deletions controller/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/QuantumNous/new-api/middleware"
"github.com/QuantumNous/new-api/model"
"github.com/QuantumNous/new-api/relay"
taskcommon "github.com/QuantumNous/new-api/relay/channel/task/taskcommon"
relaycommon "github.com/QuantumNous/new-api/relay/common"
relayconstant "github.com/QuantumNous/new-api/relay/constant"
"github.com/QuantumNous/new-api/relay/helper"
Expand Down Expand Up @@ -586,6 +587,42 @@ func RelayTask(c *gin.Context) {
task.Quota = result.Quota
task.Data = result.TaskData
task.Action = relayInfo.Action
if adaptor := relay.GetTaskAdaptor(result.Platform); adaptor != nil && len(result.TaskData) > 0 {
if taskInfo, err := adaptor.ParseTaskResult(result.TaskData); err == nil && taskInfo != nil && taskInfo.Status != "" {
now := time.Now().Unix()
task.Status = model.TaskStatus(taskInfo.Status)
switch task.Status {
case model.TaskStatusSubmitted:
task.Progress = taskcommon.ProgressSubmitted
case model.TaskStatusQueued:
task.Progress = taskcommon.ProgressQueued
case model.TaskStatusInProgress:
task.Progress = taskcommon.ProgressInProgress
if task.StartTime == 0 {
task.StartTime = now
}
case model.TaskStatusSuccess:
task.Progress = taskcommon.ProgressComplete
if task.StartTime == 0 {
task.StartTime = now
}
if task.FinishTime == 0 {
task.FinishTime = now
}
task.PrivateData.ResultURL = taskInfo.Url
case model.TaskStatusFailure:
task.Progress = taskcommon.ProgressComplete
if task.FinishTime == 0 {
task.FinishTime = now
}
task.FailReason = taskInfo.Reason
task.PrivateData.ResultURL = taskInfo.Url
}
if taskInfo.Progress != "" {
task.Progress = taskInfo.Progress
}
}
}
if insertErr := task.Insert(); insertErr != nil {
common.SysError("insert task error: " + insertErr.Error())
}
Expand Down
2 changes: 2 additions & 0 deletions dto/openai_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ type ImageRequest struct {
Prompt string `json:"prompt" binding:"required"`
N *uint `json:"n,omitempty"`
Size string `json:"size,omitempty"`
AspectRatio string `json:"aspect_ratio,omitempty"`
OutputResolution string `json:"output_resolution,omitempty"`
Comment on lines +19 to +20

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# Check the actual content of dto/openai_image.go around lines 19-20
sed -n '1,30p' dto/openai_image.go

Repository: QuantumNous/new-api

Length of output: 1296


🏁 Script executed:

# Search for ImageRequest usage in relay/convert paths
rg -A 3 -B 3 "ImageRequest" relay/ --type go | head -100

Repository: QuantumNous/new-api

Length of output: 5864


🏁 Script executed:

# Check if there are similar pointer-typed string fields in other relay DTOs
rg '\*string.*json:.*omitempty' dto/ --type go | head -20

Repository: QuantumNous/new-api

Length of output: 1056


🏁 Script executed:

# Verify whether ImageRequest is marshaled/unmarshaled and where
rg "ImageRequest" . --type go | grep -E "(Marshal|Unmarshal|convert)" | head -20

Repository: QuantumNous/new-api

Length of output: 985


Make the new optional request fields pointer-typed.

dto.ImageRequest is re-marshaled for upstream providers in relay paths, so string + omitempty on aspect_ratio and output_resolution will drop explicitly empty values the client sent. Use pointer types instead.

Proposed fix
-	AspectRatio       string          `json:"aspect_ratio,omitempty"`
-	OutputResolution  string          `json:"output_resolution,omitempty"`
+	AspectRatio       *string         `json:"aspect_ratio,omitempty"`
+	OutputResolution  *string         `json:"output_resolution,omitempty"`
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
AspectRatio string `json:"aspect_ratio,omitempty"`
OutputResolution string `json:"output_resolution,omitempty"`
AspectRatio *string `json:"aspect_ratio,omitempty"`
OutputResolution *string `json:"output_resolution,omitempty"`
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@dto/openai_image.go` around lines 19 - 20, The AspectRatio and
OutputResolution fields on dto.ImageRequest should be changed from value strings
to pointer types (e.g., *string) so that omitempty preserves explicit empty
values when re-marshaling for relays; update the struct fields AspectRatio and
OutputResolution to use pointer-typed strings and then adjust any construction
sites that set ImageRequest fields to take addresses (or nil) accordingly while
keeping the same json tags.

Quality string `json:"quality,omitempty"`
ResponseFormat string `json:"response_format,omitempty"`
Style json.RawMessage `json:"style,omitempty"`
Expand Down
7 changes: 7 additions & 0 deletions dto/openai_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ type GeneralOpenAIRequest struct {
Input any `json:"input,omitempty"`
Instruction string `json:"instruction,omitempty"`
Size string `json:"size,omitempty"`
AspectRatio string `json:"aspect_ratio,omitempty"`
OutputResolution string `json:"output_resolution,omitempty"`
Seconds *string `json:"seconds,omitempty"`
Duration *int `json:"duration,omitempty"`
Quality *string `json:"quality,omitempty"`
Resolution string `json:"resolution,omitempty"`
ReferenceMode string `json:"reference_mode,omitempty"`
Comment on lines +49 to +55

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# Find the dto/openai_request.go file and examine the GeneralOpenAIRequest struct
cd / && find . -name "openai_request.go" -path "*/dto/*" 2>/dev/null | head -5

Repository: QuantumNous/new-api

Length of output: 104


🏁 Script executed:

# Check the GeneralOpenAIRequest struct definition
rg "type GeneralOpenAIRequest" --type go -A 50 | head -80

Repository: QuantumNous/new-api

Length of output: 4621


🏁 Script executed:

# Search for usage of GeneralOpenAIRequest in relay/convert paths
rg "GeneralOpenAIRequest" --type go | grep -E "(relay|convert)" | head -20

Repository: QuantumNous/new-api

Length of output: 2710


Use pointers for the new optional string fields.

dto.GeneralOpenAIRequest is parsed from client JSON and re-marshaled upstream to provider APIs. With string + omitempty, an explicit empty value for aspect_ratio, output_resolution, resolution, or reference_mode is indistinguishable from omission and gets dropped on re-marshal.

🔧 Proposed fix
-	AspectRatio         string            `json:"aspect_ratio,omitempty"`
-	OutputResolution    string            `json:"output_resolution,omitempty"`
+	AspectRatio         *string           `json:"aspect_ratio,omitempty"`
+	OutputResolution    *string           `json:"output_resolution,omitempty"`
 	Seconds             *string           `json:"seconds,omitempty"`
 	Duration            *int              `json:"duration,omitempty"`
 	Quality             *string           `json:"quality,omitempty"`
-	Resolution          string            `json:"resolution,omitempty"`
-	ReferenceMode       string            `json:"reference_mode,omitempty"`
+	Resolution          *string           `json:"resolution,omitempty"`
+	ReferenceMode       *string           `json:"reference_mode,omitempty"`

Per coding guidelines for dto/**/*.go: optional scalar fields MUST use pointer types with omitempty to preserve explicit zero values set by the client.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
AspectRatio string `json:"aspect_ratio,omitempty"`
OutputResolution string `json:"output_resolution,omitempty"`
Seconds *string `json:"seconds,omitempty"`
Duration *int `json:"duration,omitempty"`
Quality *string `json:"quality,omitempty"`
Resolution string `json:"resolution,omitempty"`
ReferenceMode string `json:"reference_mode,omitempty"`
AspectRatio *string `json:"aspect_ratio,omitempty"`
OutputResolution *string `json:"output_resolution,omitempty"`
Seconds *string `json:"seconds,omitempty"`
Duration *int `json:"duration,omitempty"`
Quality *string `json:"quality,omitempty"`
Resolution *string `json:"resolution,omitempty"`
ReferenceMode *string `json:"reference_mode,omitempty"`
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@dto/openai_request.go` around lines 49 - 55, The struct fields on
dto.GeneralOpenAIRequest using plain string types (AspectRatio,
OutputResolution, Resolution, ReferenceMode) must be changed to *string so
explicit empty string values from client JSON are preserved when re-marshaling;
update AspectRatio, OutputResolution, Resolution, and ReferenceMode to
pointer-to-string types (keep `json:"...,omitempty"` tags) and then audit places
constructing or reading those fields to handle nil vs non-nil appropriately
(e.g., check for nil before dereferencing or use helper to convert to string).

Functions json.RawMessage `json:"functions,omitempty"`
FrequencyPenalty *float64 `json:"frequency_penalty,omitempty"`
PresencePenalty *float64 `json:"presence_penalty,omitempty"`
Expand Down
4 changes: 2 additions & 2 deletions middleware/distributor.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ func Distribute() func(c *gin.Context) {
}
var selectGroup string
usingGroup := common.GetContextKeyString(c, constant.ContextKeyUsingGroup)
// check path is /pg/chat/completions
if strings.HasPrefix(c.Request.URL.Path, "/pg/chat/completions") {
// playground requests may override group in body
if strings.HasPrefix(c.Request.URL.Path, "/pg/") {
playgroundRequest := &dto.PlayGroundRequest{}
err = common.UnmarshalBodyReusable(c, playgroundRequest)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions model/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ func InitOptionMap() {
common.OptionMap["ModelRequestRateLimitGroup"] = setting.ModelRequestRateLimitGroup2JSONString()
common.OptionMap["ModelRatio"] = ratio_setting.ModelRatio2JSONString()
common.OptionMap["ModelPrice"] = ratio_setting.ModelPrice2JSONString()
common.OptionMap["ModelPriceBySeconds"] = ratio_setting.ModelPriceBySeconds2JSONString()
common.OptionMap["CacheRatio"] = ratio_setting.CacheRatio2JSONString()
common.OptionMap["CreateCacheRatio"] = ratio_setting.CreateCacheRatio2JSONString()
common.OptionMap["GroupRatio"] = ratio_setting.GroupRatio2JSONString()
Expand Down Expand Up @@ -472,6 +473,8 @@ func updateOptionMap(key string, value string) (err error) {
err = ratio_setting.UpdateCompletionRatioByJSONString(value)
case "ModelPrice":
err = ratio_setting.UpdateModelPriceByJSONString(value)
case "ModelPriceBySeconds":
err = ratio_setting.UpdateModelPriceBySecondsByJSONString(value)
case "CacheRatio":
err = ratio_setting.UpdateCacheRatioByJSONString(value)
case "CreateCacheRatio":
Expand Down
11 changes: 10 additions & 1 deletion model/pricing.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Pricing struct {
QuotaType int `json:"quota_type"`
ModelRatio float64 `json:"model_ratio"`
ModelPrice float64 `json:"model_price"`
ModelPriceBySeconds map[string]float64 `json:"model_price_by_seconds,omitempty"`
OwnerBy string `json:"owner_by"`
CompletionRatio float64 `json:"completion_ratio"`
CacheRatio *float64 `json:"cache_ratio,omitempty"`
Expand Down Expand Up @@ -273,6 +274,7 @@ func updatePricing() {
}
}

modelPriceBySecondsMap := ratio_setting.GetModelPriceBySecondsCopy()
pricingMap = make([]Pricing, 0)
for model, groups := range modelGroupsMap {
pricing := Pricing{
Expand All @@ -292,8 +294,15 @@ func updatePricing() {
pricing.Tags = meta.Tags
pricing.VendorID = meta.VendorID
}
secondsPriceMap, hasSecondsPrice := modelPriceBySecondsMap[ratio_setting.FormatMatchingModelName(model)]
modelPrice, findPrice := ratio_setting.GetModelPrice(model, false)
if findPrice {
if hasSecondsPrice && len(secondsPriceMap) > 0 {
pricing.ModelPriceBySeconds = make(map[string]float64, len(secondsPriceMap))
for seconds, price := range secondsPriceMap {
pricing.ModelPriceBySeconds[seconds] = price
}
pricing.QuotaType = 2
} else if findPrice {
pricing.ModelPrice = modelPrice
pricing.QuotaType = 1
} else {
Expand Down
Loading