Commit 2e4d27e0 by CaIon

feat(token_estimator): add concurrency support for multipliers retrieval

parent 1fededce
...@@ -3,6 +3,7 @@ package service ...@@ -3,6 +3,7 @@ package service
import ( import (
"math" "math"
"strings" "strings"
"sync"
"unicode" "unicode"
) )
...@@ -31,7 +32,8 @@ type multipliers struct { ...@@ -31,7 +32,8 @@ type multipliers struct {
BasePad int // 基础起步消耗 (Start/End tokens) BasePad int // 基础起步消耗 (Start/End tokens)
} }
var multipliersMap = map[Provider]multipliers{ var (
multipliersMap = map[Provider]multipliers{
Gemini: { Gemini: {
Word: 1.15, Number: 2.8, CJK: 0.68, Symbol: 0.38, MathSymbol: 1.05, URLDelim: 1.2, AtSign: 2.5, Emoji: 1.08, Newline: 1.15, Space: 0.2, BasePad: 0, Word: 1.15, Number: 2.8, CJK: 0.68, Symbol: 0.38, MathSymbol: 1.05, URLDelim: 1.2, AtSign: 2.5, Emoji: 1.08, Newline: 1.15, Space: 0.2, BasePad: 0,
}, },
...@@ -41,10 +43,15 @@ var multipliersMap = map[Provider]multipliers{ ...@@ -41,10 +43,15 @@ var multipliersMap = map[Provider]multipliers{
OpenAI: { OpenAI: {
Word: 1.02, Number: 1.55, CJK: 0.85, Symbol: 0.4, MathSymbol: 2.68, URLDelim: 1.0, AtSign: 2.0, Emoji: 2.12, Newline: 0.5, Space: 0.42, BasePad: 0, Word: 1.02, Number: 1.55, CJK: 0.85, Symbol: 0.4, MathSymbol: 2.68, URLDelim: 1.0, AtSign: 2.0, Emoji: 2.12, Newline: 0.5, Space: 0.42, BasePad: 0,
}, },
} }
multipliersLock sync.RWMutex
)
// getMultipliers 根据厂商获取权重配置 // getMultipliers 根据厂商获取权重配置
func getMultipliers(p Provider) multipliers { func getMultipliers(p Provider) multipliers {
multipliersLock.RLock()
defer multipliersLock.RUnlock()
switch p { switch p {
case Gemini: case Gemini:
return multipliersMap[Gemini] return multipliersMap[Gemini]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment