mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-12 03:13:41 +08:00
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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user