-
Notifications
You must be signed in to change notification settings - Fork 11.1k
feat: 图像倍率,音频倍率和音频补全倍率配置 #1698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: 图像倍率,音频倍率和音频补全倍率配置 #1698
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -112,6 +112,9 @@ func InitOptionMap() { | |
| common.OptionMap["GroupGroupRatio"] = ratio_setting.GroupGroupRatio2JSONString() | ||
| common.OptionMap["UserUsableGroups"] = setting.UserUsableGroups2JSONString() | ||
| common.OptionMap["CompletionRatio"] = ratio_setting.CompletionRatio2JSONString() | ||
| common.OptionMap["ImageRatio"] = ratio_setting.ImageRatio2JSONString() | ||
| common.OptionMap["AudioRatio"] = ratio_setting.AudioRatio2JSONString() | ||
| common.OptionMap["AudioCompletionRatio"] = ratio_setting.AudioCompletionRatio2JSONString() | ||
| common.OptionMap["TopUpLink"] = common.TopUpLink | ||
| //common.OptionMap["ChatLink"] = common.ChatLink | ||
| //common.OptionMap["ChatLink2"] = common.ChatLink2 | ||
|
|
@@ -397,6 +400,12 @@ func updateOptionMap(key string, value string) (err error) { | |
| err = ratio_setting.UpdateModelPriceByJSONString(value) | ||
| case "CacheRatio": | ||
| err = ratio_setting.UpdateCacheRatioByJSONString(value) | ||
| case "ImageRatio": | ||
| err = ratio_setting.UpdateImageRatioByJSONString(value) | ||
| case "AudioRatio": | ||
| err = ratio_setting.UpdateAudioRatioByJSONString(value) | ||
| case "AudioCompletionRatio": | ||
| err = ratio_setting.UpdateAudioCompletionRatioByJSONString(value) | ||
|
Comment on lines
+403
to
+408
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainStale cache risk: ImageRatio update lacks exposed-data invalidation AudioRatio/AudioCompletionRatio updaters call InvalidateExposedDataCache() on success (see setting/ratio_setting/model_ratio.go), but UpdateImageRatioByJSONString does not. Exposed ratio endpoints/UI may serve stale ImageRatio after updates. Proposed fix (in setting/ratio_setting/model_ratio.go): func UpdateImageRatioByJSONString(jsonStr string) error {
imageRatioMapMutex.Lock()
defer imageRatioMapMutex.Unlock()
imageRatioMap = make(map[string]float64)
err := common.Unmarshal([]byte(jsonStr), &imageRatioMap)
if err == nil {
InvalidateExposedDataCache()
}
return err
}Verify current behavior: 🏁 Script executed: #!/bin/bash
# Show the ImageRatio updater and check for cache invalidation usage
rg -nP -C3 'func\s+UpdateImageRatioByJSONString\(' --type=go
rg -n 'InvalidateExposedDataCache\(' setting/ratio_setting --type=goLength of output: 1121 Add cache invalidation to UpdateImageRatioByJSONString 🤖 Prompt for AI Agents |
||
| case "TopUpLink": | ||
| common.TopUpLink = value | ||
| //case "ChatLink": | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -278,6 +278,18 @@ var defaultModelPrice = map[string]float64{ | |
| "mj_upload": 0.05, | ||
| } | ||
|
|
||
| var defaultAudioRatio = map[string]float64{ | ||
| "gpt-4o-audio-preview": 16, | ||
| "gpt-4o-mini-audio-preview": 66.67, | ||
| "gpt-4o-realtime-preview": 8, | ||
| "gpt-4o-mini-realtime-preview": 16.67, | ||
| } | ||
|
Comment on lines
+281
to
+286
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mismatched model IDs between audio ratio and audio completion ratio defaultAudioRatio uses "-realtime-preview" keys; defaultAudioCompletionRatio uses "-realtime" keys. Given incoming names are often "-realtime-preview[-DATE]", completion lookups will miss and fall back to 2. Align keys. var defaultAudioCompletionRatio = map[string]float64{
- "gpt-4o-realtime": 2,
- "gpt-4o-mini-realtime": 2,
+ "gpt-4o-realtime-preview": 2,
+ "gpt-4o-mini-realtime-preview": 2,
}Also applies to: 288-291 🤖 Prompt for AI Agents✅ Addressed in commit d15718a |
||
|
|
||
| var defaultAudioCompletionRatio = map[string]float64{ | ||
| "gpt-4o-realtime": 2, | ||
| "gpt-4o-mini-realtime": 2, | ||
| } | ||
|
|
||
| var ( | ||
| modelPriceMap map[string]float64 = nil | ||
| modelPriceMapMutex = sync.RWMutex{} | ||
|
|
@@ -326,6 +338,15 @@ func InitRatioSettings() { | |
| imageRatioMap = defaultImageRatio | ||
| imageRatioMapMutex.Unlock() | ||
|
|
||
| // initialize audioRatioMap | ||
| audioRatioMapMutex.Lock() | ||
| audioRatioMap = defaultAudioRatio | ||
| audioRatioMapMutex.Unlock() | ||
|
|
||
| // initialize audioCompletionRatioMap | ||
| audioCompletionRatioMapMutex.Lock() | ||
| audioCompletionRatioMap = defaultAudioCompletionRatio | ||
| audioCompletionRatioMapMutex.Unlock() | ||
| } | ||
|
|
||
| func GetModelPriceMap() map[string]float64 { | ||
|
|
@@ -417,6 +438,18 @@ func GetDefaultModelRatioMap() map[string]float64 { | |
| return defaultModelRatio | ||
| } | ||
|
|
||
| func GetDefaultImageRatioMap() map[string]float64 { | ||
| return defaultImageRatio | ||
| } | ||
|
|
||
| func GetDefaultAudioRatioMap() map[string]float64 { | ||
| return defaultAudioRatio | ||
| } | ||
|
|
||
| func GetDefaultAudioCompletionRatioMap() map[string]float64 { | ||
| return defaultAudioCompletionRatio | ||
| } | ||
|
|
||
| func GetCompletionRatioMap() map[string]float64 { | ||
| CompletionRatioMutex.RLock() | ||
| defer CompletionRatioMutex.RUnlock() | ||
|
|
@@ -584,32 +617,22 @@ func getHardcodedCompletionModelRatio(name string) (float64, bool) { | |
| } | ||
|
|
||
| func GetAudioRatio(name string) float64 { | ||
| if strings.Contains(name, "-realtime") { | ||
| if strings.HasSuffix(name, "gpt-4o-realtime-preview") { | ||
| return 8 | ||
| } else if strings.Contains(name, "gpt-4o-mini-realtime-preview") { | ||
| return 10 / 0.6 | ||
| } else { | ||
| return 20 | ||
| } | ||
| } | ||
| if strings.Contains(name, "-audio") { | ||
| if strings.HasPrefix(name, "gpt-4o-audio-preview") { | ||
| return 40 / 2.5 | ||
| } else if strings.HasPrefix(name, "gpt-4o-mini-audio-preview") { | ||
| return 10 / 0.15 | ||
| } else { | ||
| return 40 | ||
| } | ||
| audioRatioMapMutex.RLock() | ||
| defer audioRatioMapMutex.RUnlock() | ||
| name = FormatMatchingModelName(name) | ||
| if ratio, ok := audioRatioMap[name]; ok { | ||
| return ratio | ||
| } | ||
| return 20 | ||
| } | ||
|
|
||
| func GetAudioCompletionRatio(name string) float64 { | ||
| if strings.HasPrefix(name, "gpt-4o-realtime") { | ||
| return 2 | ||
| } else if strings.HasPrefix(name, "gpt-4o-mini-realtime") { | ||
| return 2 | ||
| audioCompletionRatioMapMutex.RLock() | ||
| defer audioCompletionRatioMapMutex.RUnlock() | ||
| name = FormatMatchingModelName(name) | ||
| if ratio, ok := audioCompletionRatioMap[name]; ok { | ||
|
|
||
| return ratio | ||
| } | ||
| return 2 | ||
| } | ||
|
|
@@ -630,6 +653,14 @@ var defaultImageRatio = map[string]float64{ | |
| } | ||
| var imageRatioMap map[string]float64 | ||
| var imageRatioMapMutex sync.RWMutex | ||
| var ( | ||
| audioRatioMap map[string]float64 = nil | ||
| audioRatioMapMutex = sync.RWMutex{} | ||
| ) | ||
| var ( | ||
| audioCompletionRatioMap map[string]float64 = nil | ||
| audioCompletionRatioMapMutex = sync.RWMutex{} | ||
| ) | ||
|
|
||
| func ImageRatio2JSONString() string { | ||
| imageRatioMapMutex.RLock() | ||
|
|
@@ -658,6 +689,71 @@ func GetImageRatio(name string) (float64, bool) { | |
| return ratio, true | ||
| } | ||
|
|
||
| func AudioRatio2JSONString() string { | ||
| audioRatioMapMutex.RLock() | ||
| defer audioRatioMapMutex.RUnlock() | ||
| jsonBytes, err := common.Marshal(audioRatioMap) | ||
| if err != nil { | ||
| common.SysError("error marshalling audio ratio: " + err.Error()) | ||
| } | ||
| return string(jsonBytes) | ||
| } | ||
|
|
||
| func UpdateAudioRatioByJSONString(jsonStr string) error { | ||
|
|
||
| tmp := make(map[string]float64) | ||
| if err := common.Unmarshal([]byte(jsonStr), &tmp); err != nil { | ||
| return err | ||
| } | ||
| audioRatioMapMutex.Lock() | ||
| audioRatioMap = tmp | ||
| audioRatioMapMutex.Unlock() | ||
| InvalidateExposedDataCache() | ||
| return nil | ||
| } | ||
|
|
||
| func GetAudioRatioCopy() map[string]float64 { | ||
| audioRatioMapMutex.RLock() | ||
| defer audioRatioMapMutex.RUnlock() | ||
| copyMap := make(map[string]float64, len(audioRatioMap)) | ||
| for k, v := range audioRatioMap { | ||
| copyMap[k] = v | ||
| } | ||
| return copyMap | ||
| } | ||
|
|
||
| func AudioCompletionRatio2JSONString() string { | ||
| audioCompletionRatioMapMutex.RLock() | ||
| defer audioCompletionRatioMapMutex.RUnlock() | ||
| jsonBytes, err := common.Marshal(audioCompletionRatioMap) | ||
| if err != nil { | ||
| common.SysError("error marshalling audio completion ratio: " + err.Error()) | ||
| } | ||
| return string(jsonBytes) | ||
| } | ||
|
|
||
| func UpdateAudioCompletionRatioByJSONString(jsonStr string) error { | ||
| tmp := make(map[string]float64) | ||
| if err := common.Unmarshal([]byte(jsonStr), &tmp); err != nil { | ||
| return err | ||
| } | ||
| audioCompletionRatioMapMutex.Lock() | ||
| audioCompletionRatioMap = tmp | ||
| audioCompletionRatioMapMutex.Unlock() | ||
| InvalidateExposedDataCache() | ||
| return nil | ||
| } | ||
|
|
||
| func GetAudioCompletionRatioCopy() map[string]float64 { | ||
| audioCompletionRatioMapMutex.RLock() | ||
| defer audioCompletionRatioMapMutex.RUnlock() | ||
| copyMap := make(map[string]float64, len(audioCompletionRatioMap)) | ||
| for k, v := range audioCompletionRatioMap { | ||
| copyMap[k] = v | ||
| } | ||
| return copyMap | ||
| } | ||
|
|
||
| func GetModelRatioCopy() map[string]float64 { | ||
| modelRatioMapMutex.RLock() | ||
| defer modelRatioMapMutex.RUnlock() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
New options handled; align image-ratio cache invalidation with audio/model
Controller wiring is fine. Ensure UpdateImageRatioByJSONString also invalidates exposed cache (audio functions already do). See suggested fix in ratio_setting/model_ratio.go.
After applying the InvalidateExposedDataCache() fix, please verify the exposed ratios API reflects changes immediately after updating ImageRatio via this endpoint.
🏁 Script executed:
Length of output: 3706
Add cache invalidation to UpdateImageRatioByJSONString
UpdateImageRatioByJSONString in setting/ratio_setting/model_ratio.go (around line 673) currently unmarshals into imageRatioMap without calling InvalidateExposedDataCache(). Mirror the audio handlers by invoking InvalidateExposedDataCache() on successful unmarshal. After making this change, verify that the exposed ratios API reflects image-ratio updates immediately.
🤖 Prompt for AI Agents