fix: whisper model billing

- Refactor model name handling across multiple controllers to improve clarity and maintainability.
- Enhance error logging and handling for better debugging and request processing robustness.
- Update pricing models in accordance with new calculations, ensuring accuracy in the billing logic.
This commit is contained in:
Laisky.Cai
2025-01-26 08:02:55 +00:00
parent f1db73405e
commit 5e351bc02a
6 changed files with 28 additions and 21 deletions

View File

@@ -35,6 +35,20 @@ type Meta struct {
SystemPrompt string
}
// GetMappedModelName returns the mapped model name and a bool indicating if the model name is mapped
func GetMappedModelName(modelName string, mapping map[string]string) string {
if mapping == nil {
return modelName
}
mappedModelName := mapping[modelName]
if mappedModelName != "" {
return mappedModelName
}
return modelName
}
func GetByContext(c *gin.Context) *Meta {
if v, ok := c.Get(ctxkey.Meta); ok {
return v.(*Meta)
@@ -50,6 +64,7 @@ func GetByContext(c *gin.Context) *Meta {
Group: c.GetString(ctxkey.Group),
ModelMapping: c.GetStringMapString(ctxkey.ModelMapping),
OriginModelName: c.GetString(ctxkey.RequestModel),
ActualModelName: c.GetString(ctxkey.RequestModel),
BaseURL: c.GetString(ctxkey.BaseURL),
APIKey: strings.TrimPrefix(c.Request.Header.Get("Authorization"), "Bearer "),
RequestURLPath: c.Request.URL.String(),
@@ -65,6 +80,8 @@ func GetByContext(c *gin.Context) *Meta {
}
meta.APIType = channeltype.ToAPIType(meta.ChannelType)
meta.ActualModelName = GetMappedModelName(meta.OriginModelName, meta.ModelMapping)
Set2Context(c, &meta)
return &meta
}