This commit is contained in:
Zheng Kai
2023-06-09 11:09:14 +08:00
parent 210c23b633
commit 51e0b5807a
8 changed files with 65 additions and 6 deletions

View File

@@ -7,6 +7,7 @@ import (
"project/pb"
"project/util"
"project/zj"
"strings"
)
func doMetrics(ab []byte, cached bool, r *http.Request) {
@@ -17,6 +18,7 @@ func doMetrics(ab []byte, cached bool, r *http.Request) {
err := json.Unmarshal(ab, o)
if err != nil {
zj.J(`unmarshal fail`, err)
util.WriteFile(`metrics-json-fail`, ab)
return
}
@@ -31,6 +33,10 @@ func doMetrics(ab []byte, cached bool, r *http.Request) {
zj.J(`token`, u.PromptTokens, u.TotalTokens)
}
metrics.RspTokenByModel(o.Model, u.TotalTokens)
metrics.RspTokenByKey(strings.TrimPrefix(r.Header.Get(`Authorization`), `Bearer `), u.TotalTokens)
ip, err := util.GetIP(r)
sip := ip.String()
if err != nil {