refactor: improve model resolution and normalization logic for OpenAI integration
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package service
|
||||
|
||||
// resolveOpenAIForwardModel determines the upstream model for OpenAI-compatible
|
||||
// forwarding. Group-level default mapping only applies when the account itself
|
||||
// did not match any explicit model_mapping rule.
|
||||
import "strings"
|
||||
|
||||
// resolveOpenAIForwardModel resolves the account/group mapping result for
|
||||
// OpenAI-compatible forwarding. Group-level default mapping only applies when
|
||||
// the account itself did not match any explicit model_mapping rule.
|
||||
func resolveOpenAIForwardModel(account *Account, requestedModel, defaultMappedModel string) string {
|
||||
if account == nil {
|
||||
if defaultMappedModel != "" {
|
||||
@@ -17,3 +19,23 @@ func resolveOpenAIForwardModel(account *Account, requestedModel, defaultMappedMo
|
||||
}
|
||||
return mappedModel
|
||||
}
|
||||
|
||||
func resolveOpenAIUpstreamModel(model string) string {
|
||||
if isBareGPT53CodexSparkModel(model) {
|
||||
return "gpt-5.3-codex-spark"
|
||||
}
|
||||
return normalizeCodexModel(strings.TrimSpace(model))
|
||||
}
|
||||
|
||||
func isBareGPT53CodexSparkModel(model string) bool {
|
||||
modelID := strings.TrimSpace(model)
|
||||
if modelID == "" {
|
||||
return false
|
||||
}
|
||||
if strings.Contains(modelID, "/") {
|
||||
parts := strings.Split(modelID, "/")
|
||||
modelID = parts[len(parts)-1]
|
||||
}
|
||||
normalized := strings.ToLower(strings.TrimSpace(modelID))
|
||||
return normalized == "gpt-5.3-codex-spark" || normalized == "gpt 5.3 codex spark"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user