Bläddra i källkod

feat: add more params to search log (#374)

zijiren 3 månader sedan
förälder
incheckning
f8d2ca8057
5 ändrade filer med 140 tillägg och 20 borttagningar
  1. 6 0
      core/controller/log.go
  2. 44 3
      core/docs/docs.go
  3. 44 3
      core/docs/swagger.json
  4. 42 12
      core/docs/swagger.yaml
  5. 4 2
      core/model/log.go

+ 6 - 0
core/controller/log.go

@@ -12,6 +12,7 @@ import (
 )
 
 func parseCommonParams(c *gin.Context) (params struct {
+	group     string
 	tokenName string
 	modelName string
 	channelID int
@@ -25,6 +26,7 @@ func parseCommonParams(c *gin.Context) (params struct {
 	user      string
 },
 ) {
+	params.group = c.Query("group")
 	params.tokenName = c.Query("token_name")
 	params.modelName = c.Query("model_name")
 	params.channelID, _ = strconv.Atoi(c.Query("channel"))
@@ -165,7 +167,9 @@ func GetGroupLogs(c *gin.Context) {
 //	@Param			end_timestamp	query		int		false	"End timestamp (milliseconds)"
 //	@Param			model_name		query		string	false	"Filter by model name"
 //	@Param			channel			query		int		false	"Filter by channel"
+//	@Param			group			query		string	true	"Group name"
 //	@Param			token_id		query		int		false	"Filter by token id"
+//	@Param			token_name		query		string	false	"Filter by token name"
 //	@Param			order			query		string	false	"Order"
 //	@Param			request_id		query		string	false	"Request ID"
 //	@Param			code_type		query		string	false	"Status code type"
@@ -185,7 +189,9 @@ func SearchLogs(c *gin.Context) {
 	result, err := model.SearchLogs(
 		keyword,
 		params.requestID,
+		params.group,
 		params.tokenID,
+		params.tokenName,
 		params.modelName,
 		startTime,
 		endTime,

+ 44 - 3
core/docs/docs.go

@@ -3223,12 +3223,25 @@ const docTemplate = `{
                         "name": "channel",
                         "in": "query"
                     },
+                    {
+                        "type": "string",
+                        "description": "Group name",
+                        "name": "group",
+                        "in": "query",
+                        "required": true
+                    },
                     {
                         "type": "integer",
                         "description": "Filter by token id",
                         "name": "token_id",
                         "in": "query"
                     },
+                    {
+                        "type": "string",
+                        "description": "Filter by token name",
+                        "name": "token_name",
+                        "in": "query"
+                    },
                     {
                         "type": "string",
                         "description": "Order",
@@ -4816,7 +4829,8 @@ const docTemplate = `{
                             46,
                             47,
                             48,
-                            49
+                            49,
+                            50
                         ],
                         "type": "integer",
                         "description": "Channel type",
@@ -9345,6 +9359,21 @@ const docTemplate = `{
                 "name": {
                     "type": "string"
                 },
+                "period_last_update_amount": {
+                    "description": "Total usage at last period reset",
+                    "type": "number"
+                },
+                "period_last_update_time": {
+                    "description": "Last time period was reset",
+                    "type": "string"
+                },
+                "period_quota": {
+                    "type": "number"
+                },
+                "period_type": {
+                    "description": "daily, weekly, monthly, default is monthly",
+                    "type": "string"
+                },
                 "quota": {
                     "type": "number"
                 },
@@ -9783,7 +9812,8 @@ const docTemplate = `{
                 46,
                 47,
                 48,
-                49
+                49,
+                50
             ],
             "x-enum-varnames": [
                 "ChannelTypeOpenAI",
@@ -9822,7 +9852,8 @@ const docTemplate = `{
                 "ChannelTypeDoc2x",
                 "ChannelTypeJina",
                 "ChannelTypeTextEmbeddingsInference",
-                "ChannelTypeQianfan"
+                "ChannelTypeQianfan",
+                "ChannelTypeSangforAICP"
             ]
         },
         "model.ChartData": {
@@ -12067,7 +12098,17 @@ const docTemplate = `{
                 "name": {
                     "type": "string"
                 },
+                "period_last_update_time": {
+                    "type": "integer"
+                },
+                "period_quota": {
+                    "type": "number"
+                },
+                "period_type": {
+                    "type": "string"
+                },
                 "quota": {
+                    "description": "Quota system",
                     "type": "number"
                 },
                 "status": {

+ 44 - 3
core/docs/swagger.json

@@ -3214,12 +3214,25 @@
                         "name": "channel",
                         "in": "query"
                     },
+                    {
+                        "type": "string",
+                        "description": "Group name",
+                        "name": "group",
+                        "in": "query",
+                        "required": true
+                    },
                     {
                         "type": "integer",
                         "description": "Filter by token id",
                         "name": "token_id",
                         "in": "query"
                     },
+                    {
+                        "type": "string",
+                        "description": "Filter by token name",
+                        "name": "token_name",
+                        "in": "query"
+                    },
                     {
                         "type": "string",
                         "description": "Order",
@@ -4807,7 +4820,8 @@
                             46,
                             47,
                             48,
-                            49
+                            49,
+                            50
                         ],
                         "type": "integer",
                         "description": "Channel type",
@@ -9336,6 +9350,21 @@
                 "name": {
                     "type": "string"
                 },
+                "period_last_update_amount": {
+                    "description": "Total usage at last period reset",
+                    "type": "number"
+                },
+                "period_last_update_time": {
+                    "description": "Last time period was reset",
+                    "type": "string"
+                },
+                "period_quota": {
+                    "type": "number"
+                },
+                "period_type": {
+                    "description": "daily, weekly, monthly, default is monthly",
+                    "type": "string"
+                },
                 "quota": {
                     "type": "number"
                 },
@@ -9774,7 +9803,8 @@
                 46,
                 47,
                 48,
-                49
+                49,
+                50
             ],
             "x-enum-varnames": [
                 "ChannelTypeOpenAI",
@@ -9813,7 +9843,8 @@
                 "ChannelTypeDoc2x",
                 "ChannelTypeJina",
                 "ChannelTypeTextEmbeddingsInference",
-                "ChannelTypeQianfan"
+                "ChannelTypeQianfan",
+                "ChannelTypeSangforAICP"
             ]
         },
         "model.ChartData": {
@@ -12058,7 +12089,17 @@
                 "name": {
                     "type": "string"
                 },
+                "period_last_update_time": {
+                    "type": "integer"
+                },
+                "period_quota": {
+                    "type": "number"
+                },
+                "period_type": {
+                    "type": "string"
+                },
                 "quota": {
+                    "description": "Quota system",
                     "type": "number"
                 },
                 "status": {

+ 42 - 12
core/docs/swagger.yaml

@@ -659,6 +659,17 @@ definitions:
         type: array
       name:
         type: string
+      period_last_update_amount:
+        description: Total usage at last period reset
+        type: number
+      period_last_update_time:
+        description: Last time period was reset
+        type: string
+      period_quota:
+        type: number
+      period_type:
+        description: daily, weekly, monthly, default is monthly
+        type: string
       quota:
         type: number
       request_count:
@@ -981,6 +992,7 @@ definitions:
     - 47
     - 48
     - 49
+    - 50
     type: integer
     x-enum-varnames:
     - ChannelTypeOpenAI
@@ -1020,6 +1032,7 @@ definitions:
     - ChannelTypeJina
     - ChannelTypeTextEmbeddingsInference
     - ChannelTypeQianfan
+    - ChannelTypeSangforAICP
   model.ChartData:
     properties:
       audio_input_tokens:
@@ -1042,16 +1055,16 @@ definitions:
         type: integer
       retry_count:
         type: integer
+      status_400_count:
+        type: integer
+      status_429_count:
+        type: integer
       status_4xx_count:
         type: integer
       status_500_count:
         type: integer
       status_5xx_count:
         type: integer
-      status_400_count:
-        type: integer
-      status_429_count:
-        type: integer
       timestamp:
         type: integer
       total_time_milliseconds:
@@ -1453,16 +1466,16 @@ definitions:
         type: integer
       rpm:
         type: integer
+      status_400_count:
+        type: integer
+      status_429_count:
+        type: integer
       status_4xx_count:
         type: integer
       status_500_count:
         type: integer
       status_5xx_count:
         type: integer
-      status_400_count:
-        type: integer
-      status_429_count:
-        type: integer
       token_names:
         items:
           type: string
@@ -2399,16 +2412,16 @@ definitions:
         type: integer
       retry_count:
         type: integer
+      status_4xx_count:
+        type: integer
+      status_500_count:
+        type: integer
       status_5xx_count:
         type: integer
       status_400_count:
         type: integer
       status_429_count:
         type: integer
-      status_4xx_count:
-        type: integer
-      status_500_count:
-        type: integer
       timestamp:
         type: integer
       token_name:
@@ -2537,7 +2550,14 @@ definitions:
         type: array
       name:
         type: string
+      period_last_update_time:
+        type: integer
+      period_quota:
+        type: number
+      period_type:
+        type: string
       quota:
+        description: Quota system
         type: number
       status:
         type: integer
@@ -4617,10 +4637,19 @@ paths:
         in: query
         name: channel
         type: integer
+      - description: Group name
+        in: query
+        name: group
+        required: true
+        type: string
       - description: Filter by token id
         in: query
         name: token_id
         type: integer
+      - description: Filter by token name
+        in: query
+        name: token_name
+        type: string
       - description: Order
         in: query
         name: order
@@ -5581,6 +5610,7 @@ paths:
         - 47
         - 48
         - 49
+        - 50
         in: path
         name: type
         required: true

+ 4 - 2
core/model/log.go

@@ -915,7 +915,9 @@ func searchLogs(
 func SearchLogs(
 	keyword string,
 	requestID string,
+	group string,
 	tokenID int,
+	tokenName string,
 	modelName string,
 	startTimestamp time.Time,
 	endTimestamp time.Time,
@@ -941,11 +943,11 @@ func SearchLogs(
 		var err error
 
 		total, logs, err = searchLogs(
-			"",
+			group,
 			keyword,
 			requestID,
 			tokenID,
-			"",
+			tokenName,
 			modelName,
 			startTimestamp,
 			endTimestamp,