mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-12-27 02:05:56 +08:00
feat: able to fetch every request's cost
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user