feat: able to fetch every request's cost

This commit is contained in:
Laisky.Cai
2024-04-23 00:58:25 +00:00
parent 7047d9605e
commit 84a6817314
14 changed files with 119 additions and 19 deletions

View File

@@ -6,6 +6,7 @@ import (
"strconv"
"strings"
gutils "github.com/Laisky/go-utils/v4"
"github.com/Laisky/one-api/common/ctxkey"
"github.com/Laisky/one-api/common/logger"
"github.com/Laisky/one-api/model"
@@ -75,6 +76,11 @@ func SetupContextForSelectedChannel(c *gin.Context, channel *model.Channel, mode
c.Set(ctxkey.ChannelRatio, minimalRatio)
c.Set(ctxkey.ChannelModel, channel)
// generate an unique cost id for each request
if _, ok := c.Get(ctxkey.RequestId); !ok {
c.Set(ctxkey.RequestId, gutils.UUID7())
}
c.Set(ctxkey.Channel, channel.Type)
c.Set(ctxkey.ChannelId, channel.Id)
c.Set(ctxkey.ChannelName, channel.Name)