diff --git a/common/utils.go b/common/utils.go index 3130020..6c89d41 100644 --- a/common/utils.go +++ b/common/utils.go @@ -258,3 +258,12 @@ func MapToJsonStrFloat(m map[string]float64) string { } return string(bytes) } + +func StrToMap(str string) map[string]interface{} { + m := make(map[string]interface{}) + err := json.Unmarshal([]byte(str), &m) + if err != nil { + return nil + } + return m +} diff --git a/controller/relay.go b/controller/relay.go index 0bbd409..a066e5d 100644 --- a/controller/relay.go +++ b/controller/relay.go @@ -43,7 +43,7 @@ func Relay(c *gin.Context) { group := c.GetString("group") originalModel := c.GetString("original_model") openaiErr := relayHandler(c, relayMode) - useChannel := []int{channelId} + c.Set("use_channel", []string{fmt.Sprintf("%d", channelId)}) if openaiErr != nil { go processChannelError(c, channelId, openaiErr) } else { @@ -56,7 +56,9 @@ func Relay(c *gin.Context) { break } channelId = channel.Id - useChannel = append(useChannel, channelId) + useChannel := c.GetStringSlice("use_channel") + useChannel = append(useChannel, fmt.Sprintf("%d", channelId)) + c.Set("use_channel", useChannel) common.LogInfo(c.Request.Context(), fmt.Sprintf("using channel #%d to retry (remain times %d)", channel.Id, i)) middleware.SetupContextForSelectedChannel(c, channel, originalModel) @@ -67,6 +69,7 @@ func Relay(c *gin.Context) { go processChannelError(c, channelId, openaiErr) } } + useChannel := c.GetStringSlice("use_channel") if len(useChannel) > 1 { retryLogStr := fmt.Sprintf("重试:%s", strings.Trim(strings.Join(strings.Fields(fmt.Sprint(useChannel)), "->"), "[]")) common.LogInfo(c.Request.Context(), retryLogStr) diff --git a/model/log.go b/model/log.go index 57c64d0..2e72b71 100644 --- a/model/log.go +++ b/model/log.go @@ -142,6 +142,15 @@ func GetUserLogs(userId int, logType int, startTimestamp int64, endTimestamp int tx = tx.Where("created_at <= ?", endTimestamp) } err = tx.Order("id desc").Limit(num).Offset(startIdx).Omit("id").Find(&logs).Error + for i := range logs { + var otherMap map[string]interface{} + otherMap = common.StrToMap(logs[i].Other) + if otherMap != nil { + // delete admin + delete(otherMap, "admin_info") + } + logs[i].Other = common.MapToJsonStr(otherMap) + } return logs, err } diff --git a/relay/relay-text.go b/relay/relay-text.go index d5ee728..007b3b1 100644 --- a/relay/relay-text.go +++ b/relay/relay-text.go @@ -320,6 +320,9 @@ func postConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, textRe other["group_ratio"] = groupRatio other["completion_ratio"] = completionRatio other["model_price"] = modelPrice + adminInfo := make(map[string]interface{}) + adminInfo["use_channel"] = ctx.GetStringSlice("use_channel") + other["admin_info"] = adminInfo model.RecordConsumeLog(ctx, relayInfo.UserId, relayInfo.ChannelId, promptTokens, completionTokens, logModel, tokenName, quota, logContent, relayInfo.TokenId, userQuota, int(useTimeSeconds), relayInfo.IsStream, other) //if quota != 0 { diff --git a/web/src/components/LogsTable.js b/web/src/components/LogsTable.js index 8efb9db..f8436ad 100644 --- a/web/src/components/LogsTable.js +++ b/web/src/components/LogsTable.js @@ -294,6 +294,30 @@ const LogsTable = () => { ); }, }, + { + title: '重试', + dataIndex: 'retry', + className: isAdmin() ? 'tableShow' : 'tableHiddle', + render: (text, record, index) => { + let content = '渠道:' + record.channel; + if (record.other !== '') { + let other = JSON.parse(record.other); + if (other.admin_info !== undefined) { + if ( + other.admin_info.use_channel !== null && + other.admin_info.use_channel !== undefined && + other.admin_info.use_channel !== '' + ) { + // channel id array + let useChannel = other.admin_info.use_channel; + let useChannelStr = useChannel.join('->'); + content = `渠道:${useChannelStr}`; + } + } + } + return isAdminUser ?