mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-13 03:43:44 +08:00
refactor: update variable names and improve code readability; add Makefile for linting and installation
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package ctxkey
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
const (
|
||||
Config = "config"
|
||||
Id = "id"
|
||||
@@ -25,7 +27,7 @@ const (
|
||||
TokenQuotaUnlimited = "token_quota_unlimited"
|
||||
BaseURL = "base_url"
|
||||
AvailableModels = "available_models"
|
||||
KeyRequestBody = "key_request_body"
|
||||
KeyRequestBody = gin.BodyBytesKey
|
||||
SystemPrompt = "system_prompt"
|
||||
Meta = "meta"
|
||||
)
|
||||
|
||||
@@ -33,7 +33,7 @@ func SaveTmpFile(filename string, data io.Reader) (string, error) {
|
||||
}
|
||||
|
||||
// GetAudioTokens returns the number of tokens in an audio file.
|
||||
func GetAudioTokens(ctx context.Context, audio io.Reader, tokensPerSecond int) (int, error) {
|
||||
func GetAudioTokens(ctx context.Context, audio io.Reader, tokensPerSecond float64) (int, error) {
|
||||
filename, err := SaveTmpFile("audio", audio)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "failed to save audio to temporary file")
|
||||
@@ -45,7 +45,7 @@ func GetAudioTokens(ctx context.Context, audio io.Reader, tokensPerSecond int) (
|
||||
return 0, errors.Wrap(err, "failed to get audio tokens")
|
||||
}
|
||||
|
||||
return int(math.Ceil(duration)) * tokensPerSecond, nil
|
||||
return int(math.Ceil(duration * tokensPerSecond)), nil
|
||||
}
|
||||
|
||||
// GetAudioDuration returns the duration of an audio file in seconds.
|
||||
|
||||
Reference in New Issue
Block a user