Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions controller/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions relay/mjproxy_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions relay/relay_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
25 changes: 24 additions & 1 deletion service/log_info_generate.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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{})
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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 changes: 6 additions & 0 deletions web/src/hooks/usage-logs/useUsageLogsData.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,12 @@ export const useLogsData = () => {
});
}
}
if (other?.request_path) {
expandDataLocal.push({
key: t('请求路径'),
value: other.request_path,
});
}
expandDatesLocal[logs[i].key] = expandDataLocal;
}

Expand Down
1 change: 1 addition & 0 deletions web/src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion web/src/i18n/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -2081,4 +2082,4 @@
"默认测试模型": "Modèle de test par défaut",
"默认补全倍率": "Taux de complétion par défaut"
}
}
}
1 change: 1 addition & 0 deletions web/src/i18n/locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -1693,6 +1693,7 @@
"请求失败": "Запрос не удался",
"请求头覆盖": "Переопределение заголовков запроса",
"请求并计费模型": "Запрос и выставление счёта модели",
"请求路径": "Путь запроса",
"请求时长: ${time}s": "Время запроса: ${time}s",
"请求次数": "Количество запросов",
"请求结束后多退少补": "После вывода запроса возврат излишков и доплата недостатка",
Expand Down
1 change: 1 addition & 0 deletions web/src/i18n/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -1666,6 +1666,7 @@
"请求失败": "请求失败",
"请求头覆盖": "请求头覆盖",
"请求并计费模型": "请求并计费模型",
"请求路径": "请求路径",
"请求时长: ${time}s": "请求时长: ${time}s",
"请求次数": "请求次数",
"请求结束后多退少补": "请求结束后多退少补",
Expand Down