Merge branch 'upstream/main'

This commit is contained in:
Laisky.Cai
2025-01-31 10:32:35 +00:00
18 changed files with 244 additions and 78 deletions

View File

@@ -1,6 +1,7 @@
package helper
import (
"context"
"fmt"
"html/template"
"log"
@@ -107,6 +108,18 @@ func GenRequestID() string {
return GetTimeString() + random.GetRandomNumberString(8)
}
func SetRequestID(ctx context.Context, id string) context.Context {
return context.WithValue(ctx, RequestIdKey, id)
}
func GetRequestID(ctx context.Context) string {
rawRequestId := ctx.Value(RequestIdKey)
if rawRequestId == nil {
return ""
}
return rawRequestId.(string)
}
func GetResponseID(c *gin.Context) string {
logID := c.GetString(RequestIdKey)
return fmt.Sprintf("chatcmpl-%s", logID)