-
Notifications
You must be signed in to change notification settings - Fork 58
/
cost.go
53 lines (45 loc) · 1.63 KB
/
cost.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package deepinfra
import (
"errors"
"fmt"
"strings"
)
var DeepinfraPerMillionTokenCost = map[string]map[string]float64{
"prompt": {
"baai/bge-large-en-v1.5": 0.01,
"baai/bge-base-en-v1.5": 0.005,
"intfloat/e5-base-v2": 0.005,
"intfloat/e5-large-v2": 0.01,
"sentence-transformers/all-minilm-l12-v2": 0.005,
"sentence-transformers/all-minilm-l6-v2": 0.005,
"sentence-transformers/all-mpnet-base-v2": 0.005,
"sentence-transformers/clip-vit-b-32": 0.005,
"sentence-transformers/clip-vit-b-32-multilingual-v1": 0.005,
"sentence-transformers/multi-qa-mpnet-base-dot-v1": 0.005,
"sentence-transformers/paraphrase-minilm-l6-v2": 0.005,
"shibing624/text2vec-base-chinese": 0.005,
"thenlper/gte-base": 0.005,
"thenlper/gte-large": 0.01,
},
}
type CostEstimator struct {
tokenCostMap map[string]map[string]float64
}
func NewCostEstimator() *CostEstimator {
return &CostEstimator{
tokenCostMap: DeepinfraPerMillionTokenCost,
}
}
func (ce *CostEstimator) EstimateEmbeddingsInputCost(model string, tks int) (float64, error) {
costMap, ok := ce.tokenCostMap["prompt"]
if !ok {
return 0, errors.New("prompt token cost is not provided")
}
lowerCased := strings.ToLower(model)
cost, ok := costMap[lowerCased]
if !ok {
return 0, fmt.Errorf("%s is not present in the cost map provided", model)
}
tksInFloat := float64(tks)
return tksInFloat / 1000000 * cost, nil
}