ソースを参照

Merge pull request #2038 from seefs001/feature/endpoint_type_log

feat: endpoint type log
Seefs 2 ヶ月 前
コミット
ea870a7846

+ 3 - 0
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

+ 2 - 2
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,

+ 3 - 0
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 {

+ 24 - 1
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
 }

+ 6 - 0
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;
     }
 

+ 1 - 0
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",

+ 2 - 1
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"
   }
-}
+}

+ 1 - 0
web/src/i18n/locales/ru.json

@@ -1693,6 +1693,7 @@
     "请求失败": "Запрос не удался",
     "请求头覆盖": "Переопределение заголовков запроса",
     "请求并计费模型": "Запрос и выставление счёта модели",
+    "请求路径": "Путь запроса",
     "请求时长: ${time}s": "Время запроса: ${time}s",
     "请求次数": "Количество запросов",
     "请求结束后多退少补": "После вывода запроса возврат излишков и доплата недостатка",

+ 1 - 0
web/src/i18n/locales/zh.json

@@ -1666,6 +1666,7 @@
     "请求失败": "请求失败",
     "请求头覆盖": "请求头覆盖",
     "请求并计费模型": "请求并计费模型",
+    "请求路径": "请求路径",
     "请求时长: ${time}s": "请求时长: ${time}s",
     "请求次数": "请求次数",
     "请求结束后多退少补": "请求结束后多退少补",