mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-13 11:53:42 +08:00
Merge branch 'main' into patch/images-edits
This commit is contained in:
@@ -1,13 +0,0 @@
|
||||
package ctxkey
|
||||
|
||||
const (
|
||||
ConfigPrefix = "cfg_"
|
||||
|
||||
ConfigAPIVersion = ConfigPrefix + "api_version"
|
||||
ConfigLibraryID = ConfigPrefix + "library_id"
|
||||
ConfigPlugin = ConfigPrefix + "plugin"
|
||||
ConfigSK = ConfigPrefix + "sk"
|
||||
ConfigAK = ConfigPrefix + "ak"
|
||||
ConfigRegion = ConfigPrefix + "region"
|
||||
ConfigUserID = ConfigPrefix + "user_id"
|
||||
)
|
||||
@@ -1,6 +1,7 @@
|
||||
package ctxkey
|
||||
|
||||
const (
|
||||
Config = "config"
|
||||
Id = "id"
|
||||
RequestId = "X-Oneapi-Request-Id"
|
||||
Username = "username"
|
||||
|
||||
@@ -2,6 +2,7 @@ package helper
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/songquanpeng/one-api/common/random"
|
||||
"html/template"
|
||||
"log"
|
||||
@@ -105,6 +106,11 @@ func GenRequestID() string {
|
||||
return GetTimeString() + random.GetRandomNumberString(8)
|
||||
}
|
||||
|
||||
func GetResponseID(c *gin.Context) string {
|
||||
logID := c.GetString(RequestIdKey)
|
||||
return fmt.Sprintf("chatcmpl-%s", logID)
|
||||
}
|
||||
|
||||
func Max(a int, b int) int {
|
||||
if a >= b {
|
||||
return a
|
||||
|
||||
5
common/helper/key.go
Normal file
5
common/helper/key.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package helper
|
||||
|
||||
const (
|
||||
RequestIdKey = "X-Oneapi-Request-Id"
|
||||
)
|
||||
@@ -88,7 +88,7 @@ func logHelper(ctx context.Context, level string, msg string) {
|
||||
if level == loggerINFO {
|
||||
writer = gin.DefaultWriter
|
||||
}
|
||||
id := ctx.Value(ctxkey.RequestId)
|
||||
id := ctx.Value(helper.RequestIdKey)
|
||||
if id == nil {
|
||||
id = helper.GenRequestID()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user