diff --git a/controller/relay.go b/controller/relay.go index e8ea1998e..4a81e3565 100644 --- a/controller/relay.go +++ b/controller/relay.go @@ -299,6 +299,9 @@ func processChannelError(c *gin.Context, channelError types.ChannelError, err *t userGroup := c.GetString("group") channelId := c.GetInt("channel_id") other := make(map[string]interface{}) + if c.Request != nil && c.Request.URL != nil { + other["request_path"] = c.Request.URL.Path + } other["error_type"] = err.GetErrorType() other["error_code"] = err.GetErrorCode() other["status_code"] = err.StatusCode diff --git a/relay/mjproxy_handler.go b/relay/mjproxy_handler.go index ad42dfecc..8916ab181 100644 --- a/relay/mjproxy_handler.go +++ b/relay/mjproxy_handler.go @@ -218,7 +218,7 @@ func RelaySwapFace(c *gin.Context, info *relaycommon.RelayInfo) *dto.MidjourneyR tokenName := c.GetString("token_name") logContent := fmt.Sprintf("模型固定价格 %.2f,分组倍率 %.2f,操作 %s", priceData.ModelPrice, priceData.GroupRatioInfo.GroupRatio, constant.MjActionSwapFace) - other := service.GenerateMjOtherInfo(priceData) + other := service.GenerateMjOtherInfo(info, priceData) model.RecordConsumeLog(c, info.UserId, model.RecordConsumeLogParams{ ChannelId: info.ChannelId, ModelName: modelName, @@ -518,7 +518,7 @@ func RelayMidjourneySubmit(c *gin.Context, relayInfo *relaycommon.RelayInfo) *dt } tokenName := c.GetString("token_name") logContent := fmt.Sprintf("模型固定价格 %.2f,分组倍率 %.2f,操作 %s,ID %s", priceData.ModelPrice, priceData.GroupRatioInfo.GroupRatio, midjRequest.Action, midjResponse.Result) - other := service.GenerateMjOtherInfo(priceData) + other := service.GenerateMjOtherInfo(relayInfo, priceData) model.RecordConsumeLog(c, relayInfo.UserId, model.RecordConsumeLogParams{ ChannelId: relayInfo.ChannelId, ModelName: modelName, diff --git a/relay/relay_task.go b/relay/relay_task.go index 4a30fb68b..bf20f5bbd 100644 --- a/relay/relay_task.go +++ b/relay/relay_task.go @@ -165,6 +165,9 @@ func RelayTaskSubmit(c *gin.Context, info *relaycommon.RelayInfo) (taskErr *dto. } } other := make(map[string]interface{}) + if c != nil && c.Request != nil && c.Request.URL != nil { + other["request_path"] = c.Request.URL.Path + } other["model_price"] = modelPrice other["group_ratio"] = groupRatio if hasUserGroupRatio { diff --git a/service/log_info_generate.go b/service/log_info_generate.go index 5b737692e..95a88dfbc 100644 --- a/service/log_info_generate.go +++ b/service/log_info_generate.go @@ -1,6 +1,8 @@ package service import ( + "strings" + "github.com/QuantumNous/new-api/common" "github.com/QuantumNous/new-api/constant" "github.com/QuantumNous/new-api/dto" @@ -10,6 +12,25 @@ import ( "github.com/gin-gonic/gin" ) +func appendRequestPath(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, other map[string]interface{}) { + if other == nil { + return + } + if ctx != nil && ctx.Request != nil && ctx.Request.URL != nil { + if path := ctx.Request.URL.Path; path != "" { + other["request_path"] = path + return + } + } + if relayInfo != nil && relayInfo.RequestURLPath != "" { + path := relayInfo.RequestURLPath + if idx := strings.Index(path, "?"); idx != -1 { + path = path[:idx] + } + other["request_path"] = path + } +} + func GenerateTextOtherInfo(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, modelRatio, groupRatio, completionRatio float64, cacheTokens int, cacheRatio float64, modelPrice float64, userGroupRatio float64) map[string]interface{} { other := make(map[string]interface{}) @@ -42,6 +63,7 @@ func GenerateTextOtherInfo(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, m adminInfo["multi_key_index"] = common.GetContextKeyInt(ctx, constant.ContextKeyChannelMultiKeyIndex) } other["admin_info"] = adminInfo + appendRequestPath(ctx, relayInfo, other) return other } @@ -78,12 +100,13 @@ func GenerateClaudeOtherInfo(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, return info } -func GenerateMjOtherInfo(priceData types.PerCallPriceData) map[string]interface{} { +func GenerateMjOtherInfo(relayInfo *relaycommon.RelayInfo, priceData types.PerCallPriceData) map[string]interface{} { other := make(map[string]interface{}) other["model_price"] = priceData.ModelPrice other["group_ratio"] = priceData.GroupRatioInfo.GroupRatio if priceData.GroupRatioInfo.HasSpecialRatio { other["user_group_ratio"] = priceData.GroupRatioInfo.GroupSpecialRatio } + appendRequestPath(nil, relayInfo, other) return other } diff --git a/web/src/hooks/usage-logs/useUsageLogsData.jsx b/web/src/hooks/usage-logs/useUsageLogsData.jsx index 36684c2c5..6041d7427 100644 --- a/web/src/hooks/usage-logs/useUsageLogsData.jsx +++ b/web/src/hooks/usage-logs/useUsageLogsData.jsx @@ -468,6 +468,12 @@ export const useLogsData = () => { }); } } + if (other?.request_path) { + expandDataLocal.push({ + key: t('请求路径'), + value: other.request_path, + }); + } expandDatesLocal[logs[i].key] = expandDataLocal; } diff --git a/web/src/i18n/locales/en.json b/web/src/i18n/locales/en.json index 7ec941281..db62d5f59 100644 --- a/web/src/i18n/locales/en.json +++ b/web/src/i18n/locales/en.json @@ -1675,6 +1675,7 @@ "请求失败": "Request failed", "请求头覆盖": "Request header override", "请求并计费模型": "Request and charge model", + "请求路径": "Request path", "请求时长: ${time}s": "Request time: ${time}s", "请求次数": "Number of Requests", "请求结束后多退少补": "Adjust after request completion", diff --git a/web/src/i18n/locales/fr.json b/web/src/i18n/locales/fr.json index bafe945c0..27789a191 100644 --- a/web/src/i18n/locales/fr.json +++ b/web/src/i18n/locales/fr.json @@ -1684,6 +1684,7 @@ "请求失败": "Échec de la demande", "请求头覆盖": "Remplacement des en-têtes de demande", "请求并计费模型": "Modèle de demande et de facturation", + "请求路径": "Chemin de requête", "请求时长: ${time}s": "Durée de la requête : ${time}s", "请求次数": "Nombre de demandes", "请求结束后多退少补": "Ajuster après la fin de la demande", @@ -2081,4 +2082,4 @@ "默认测试模型": "Modèle de test par défaut", "默认补全倍率": "Taux de complétion par défaut" } -} \ No newline at end of file +} diff --git a/web/src/i18n/locales/ru.json b/web/src/i18n/locales/ru.json index 7f031dccb..db0a47626 100644 --- a/web/src/i18n/locales/ru.json +++ b/web/src/i18n/locales/ru.json @@ -1693,6 +1693,7 @@ "请求失败": "Запрос не удался", "请求头覆盖": "Переопределение заголовков запроса", "请求并计费模型": "Запрос и выставление счёта модели", + "请求路径": "Путь запроса", "请求时长: ${time}s": "Время запроса: ${time}s", "请求次数": "Количество запросов", "请求结束后多退少补": "После вывода запроса возврат излишков и доплата недостатка", diff --git a/web/src/i18n/locales/zh.json b/web/src/i18n/locales/zh.json index fe085af12..62c8836be 100644 --- a/web/src/i18n/locales/zh.json +++ b/web/src/i18n/locales/zh.json @@ -1666,6 +1666,7 @@ "请求失败": "请求失败", "请求头覆盖": "请求头覆盖", "请求并计费模型": "请求并计费模型", + "请求路径": "请求路径", "请求时长: ${time}s": "请求时长: ${time}s", "请求次数": "请求次数", "请求结束后多退少补": "请求结束后多退少补",