Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
97185681
authored
Oct 13, 2025
by
Seefs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: endpoint type log
parent
7391b15b
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
83 additions
and
19 deletions
+83
-19
constant/context_key.go
+1
-0
controller/relay.go
+4
-0
relay/common/relay_info.go
+27
-15
relay/mjproxy_handler.go
+2
-2
relay/relay_task.go
+3
-0
service/log_info_generate.go
+7
-1
web/src/components/table/usage-logs/UsageLogsColumnDefs.jsx
+39
-1
No files found.
constant/context_key.go
View file @
97185681
...
@@ -8,6 +8,7 @@ const (
...
@@ -8,6 +8,7 @@ const (
ContextKeyOriginalModel
ContextKey
=
"original_model"
ContextKeyOriginalModel
ContextKey
=
"original_model"
ContextKeyRequestStartTime
ContextKey
=
"request_start_time"
ContextKeyRequestStartTime
ContextKey
=
"request_start_time"
ContextKeyRelayFormat
ContextKey
=
"relay_format"
/* token related keys */
/* token related keys */
ContextKeyTokenUnlimited
ContextKey
=
"token_unlimited_quota"
ContextKeyTokenUnlimited
ContextKey
=
"token_unlimited_quota"
...
...
controller/relay.go
View file @
97185681
...
@@ -299,6 +299,10 @@ func processChannelError(c *gin.Context, channelError types.ChannelError, err *t
...
@@ -299,6 +299,10 @@ func processChannelError(c *gin.Context, channelError types.ChannelError, err *t
userGroup
:=
c
.
GetString
(
"group"
)
userGroup
:=
c
.
GetString
(
"group"
)
channelId
:=
c
.
GetInt
(
"channel_id"
)
channelId
:=
c
.
GetInt
(
"channel_id"
)
other
:=
make
(
map
[
string
]
interface
{})
other
:=
make
(
map
[
string
]
interface
{})
relayFormat
:=
common
.
GetContextKeyString
(
c
,
constant
.
ContextKeyRelayFormat
)
if
relayFormat
!=
""
{
other
[
"relay_format"
]
=
relayFormat
}
other
[
"error_type"
]
=
err
.
GetErrorType
()
other
[
"error_type"
]
=
err
.
GetErrorType
()
other
[
"error_code"
]
=
err
.
GetErrorCode
()
other
[
"error_code"
]
=
err
.
GetErrorCode
()
other
[
"status_code"
]
=
err
.
StatusCode
other
[
"status_code"
]
=
err
.
StatusCode
...
...
relay/common/relay_info.go
View file @
97185681
...
@@ -426,38 +426,50 @@ func genBaseRelayInfo(c *gin.Context, request dto.Request) *RelayInfo {
...
@@ -426,38 +426,50 @@ func genBaseRelayInfo(c *gin.Context, request dto.Request) *RelayInfo {
}
}
func
GenRelayInfo
(
c
*
gin
.
Context
,
relayFormat
types
.
RelayFormat
,
request
dto
.
Request
,
ws
*
websocket
.
Conn
)
(
*
RelayInfo
,
error
)
{
func
GenRelayInfo
(
c
*
gin
.
Context
,
relayFormat
types
.
RelayFormat
,
request
dto
.
Request
,
ws
*
websocket
.
Conn
)
(
*
RelayInfo
,
error
)
{
var
info
*
RelayInfo
switch
relayFormat
{
switch
relayFormat
{
case
types
.
RelayFormatOpenAI
:
case
types
.
RelayFormatOpenAI
:
return
GenRelayInfoOpenAI
(
c
,
request
),
nil
info
=
GenRelayInfoOpenAI
(
c
,
request
)
case
types
.
RelayFormatOpenAIAudio
:
case
types
.
RelayFormatOpenAIAudio
:
return
GenRelayInfoOpenAIAudio
(
c
,
request
),
nil
info
=
GenRelayInfoOpenAIAudio
(
c
,
request
)
case
types
.
RelayFormatOpenAIImage
:
case
types
.
RelayFormatOpenAIImage
:
return
GenRelayInfoImage
(
c
,
request
),
nil
info
=
GenRelayInfoImage
(
c
,
request
)
case
types
.
RelayFormatOpenAIRealtime
:
case
types
.
RelayFormatOpenAIRealtime
:
return
GenRelayInfoWs
(
c
,
ws
),
nil
info
=
GenRelayInfoWs
(
c
,
ws
)
case
types
.
RelayFormatClaude
:
case
types
.
RelayFormatClaude
:
return
GenRelayInfoClaude
(
c
,
request
),
nil
info
=
GenRelayInfoClaude
(
c
,
request
)
case
types
.
RelayFormatRerank
:
case
types
.
RelayFormatRerank
:
if
request
,
ok
:=
request
.
(
*
dto
.
RerankRequest
);
ok
{
rerankReq
,
ok
:=
request
.
(
*
dto
.
RerankRequest
)
return
GenRelayInfoRerank
(
c
,
request
),
nil
if
!
ok
{
}
return
nil
,
errors
.
New
(
"request is not a RerankRequest"
)
return
nil
,
errors
.
New
(
"request is not a RerankRequest"
)
}
info
=
GenRelayInfoRerank
(
c
,
rerankReq
)
case
types
.
RelayFormatGemini
:
case
types
.
RelayFormatGemini
:
return
GenRelayInfoGemini
(
c
,
request
),
nil
info
=
GenRelayInfoGemini
(
c
,
request
)
case
types
.
RelayFormatEmbedding
:
case
types
.
RelayFormatEmbedding
:
return
GenRelayInfoEmbedding
(
c
,
request
),
nil
info
=
GenRelayInfoEmbedding
(
c
,
request
)
case
types
.
RelayFormatOpenAIResponses
:
case
types
.
RelayFormatOpenAIResponses
:
if
request
,
ok
:=
request
.
(
*
dto
.
OpenAIResponsesRequest
);
ok
{
responsesReq
,
ok
:=
request
.
(
*
dto
.
OpenAIResponsesRequest
)
return
GenRelayInfoResponses
(
c
,
request
),
nil
if
!
ok
{
}
return
nil
,
errors
.
New
(
"request is not a OpenAIResponsesRequest"
)
return
nil
,
errors
.
New
(
"request is not a OpenAIResponsesRequest"
)
}
info
=
GenRelayInfoResponses
(
c
,
responsesReq
)
case
types
.
RelayFormatTask
:
case
types
.
RelayFormatTask
:
return
genBaseRelayInfo
(
c
,
nil
),
nil
info
=
genBaseRelayInfo
(
c
,
nil
)
info
.
RelayFormat
=
types
.
RelayFormatTask
case
types
.
RelayFormatMjProxy
:
case
types
.
RelayFormatMjProxy
:
return
genBaseRelayInfo
(
c
,
nil
),
nil
info
=
genBaseRelayInfo
(
c
,
nil
)
info
.
RelayFormat
=
types
.
RelayFormatMjProxy
default
:
default
:
return
nil
,
errors
.
New
(
"invalid relay format"
)
return
nil
,
errors
.
New
(
"invalid relay format"
)
}
}
if
info
!=
nil
{
common
.
SetContextKey
(
c
,
constant
.
ContextKeyRelayFormat
,
string
(
info
.
RelayFormat
))
}
return
info
,
nil
}
}
func
(
info
*
RelayInfo
)
SetPromptTokens
(
promptTokens
int
)
{
func
(
info
*
RelayInfo
)
SetPromptTokens
(
promptTokens
int
)
{
...
...
relay/mjproxy_handler.go
View file @
97185681
...
@@ -218,7 +218,7 @@ func RelaySwapFace(c *gin.Context, info *relaycommon.RelayInfo) *dto.MidjourneyR
...
@@ -218,7 +218,7 @@ func RelaySwapFace(c *gin.Context, info *relaycommon.RelayInfo) *dto.MidjourneyR
tokenName
:=
c
.
GetString
(
"token_name"
)
tokenName
:=
c
.
GetString
(
"token_name"
)
logContent
:=
fmt
.
Sprintf
(
"模型固定价格 %.2f,分组倍率 %.2f,操作 %s"
,
priceData
.
ModelPrice
,
priceData
.
GroupRatioInfo
.
GroupRatio
,
constant
.
MjActionSwapFace
)
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
{
model
.
RecordConsumeLog
(
c
,
info
.
UserId
,
model
.
RecordConsumeLogParams
{
ChannelId
:
info
.
ChannelId
,
ChannelId
:
info
.
ChannelId
,
ModelName
:
modelName
,
ModelName
:
modelName
,
...
@@ -518,7 +518,7 @@ func RelayMidjourneySubmit(c *gin.Context, relayInfo *relaycommon.RelayInfo) *dt
...
@@ -518,7 +518,7 @@ func RelayMidjourneySubmit(c *gin.Context, relayInfo *relaycommon.RelayInfo) *dt
}
}
tokenName
:=
c
.
GetString
(
"token_name"
)
tokenName
:=
c
.
GetString
(
"token_name"
)
logContent
:=
fmt
.
Sprintf
(
"模型固定价格 %.2f,分组倍率 %.2f,操作 %s,ID %s"
,
priceData
.
ModelPrice
,
priceData
.
GroupRatioInfo
.
GroupRatio
,
midjRequest
.
Action
,
midjResponse
.
Result
)
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
{
model
.
RecordConsumeLog
(
c
,
relayInfo
.
UserId
,
model
.
RecordConsumeLogParams
{
ChannelId
:
relayInfo
.
ChannelId
,
ChannelId
:
relayInfo
.
ChannelId
,
ModelName
:
modelName
,
ModelName
:
modelName
,
...
...
relay/relay_task.go
View file @
97185681
...
@@ -165,6 +165,9 @@ func RelayTaskSubmit(c *gin.Context, info *relaycommon.RelayInfo) (taskErr *dto.
...
@@ -165,6 +165,9 @@ func RelayTaskSubmit(c *gin.Context, info *relaycommon.RelayInfo) (taskErr *dto.
}
}
}
}
other
:=
make
(
map
[
string
]
interface
{})
other
:=
make
(
map
[
string
]
interface
{})
if
info
.
RelayFormat
!=
""
{
other
[
"relay_format"
]
=
string
(
info
.
RelayFormat
)
}
other
[
"model_price"
]
=
modelPrice
other
[
"model_price"
]
=
modelPrice
other
[
"group_ratio"
]
=
groupRatio
other
[
"group_ratio"
]
=
groupRatio
if
hasUserGroupRatio
{
if
hasUserGroupRatio
{
...
...
service/log_info_generate.go
View file @
97185681
...
@@ -13,6 +13,9 @@ import (
...
@@ -13,6 +13,9 @@ import (
func
GenerateTextOtherInfo
(
ctx
*
gin
.
Context
,
relayInfo
*
relaycommon
.
RelayInfo
,
modelRatio
,
groupRatio
,
completionRatio
float64
,
func
GenerateTextOtherInfo
(
ctx
*
gin
.
Context
,
relayInfo
*
relaycommon
.
RelayInfo
,
modelRatio
,
groupRatio
,
completionRatio
float64
,
cacheTokens
int
,
cacheRatio
float64
,
modelPrice
float64
,
userGroupRatio
float64
)
map
[
string
]
interface
{}
{
cacheTokens
int
,
cacheRatio
float64
,
modelPrice
float64
,
userGroupRatio
float64
)
map
[
string
]
interface
{}
{
other
:=
make
(
map
[
string
]
interface
{})
other
:=
make
(
map
[
string
]
interface
{})
if
relayInfo
!=
nil
&&
relayInfo
.
RelayFormat
!=
""
{
other
[
"relay_format"
]
=
string
(
relayInfo
.
RelayFormat
)
}
other
[
"model_ratio"
]
=
modelRatio
other
[
"model_ratio"
]
=
modelRatio
other
[
"group_ratio"
]
=
groupRatio
other
[
"group_ratio"
]
=
groupRatio
other
[
"completion_ratio"
]
=
completionRatio
other
[
"completion_ratio"
]
=
completionRatio
...
@@ -78,8 +81,11 @@ func GenerateClaudeOtherInfo(ctx *gin.Context, relayInfo *relaycommon.RelayInfo,
...
@@ -78,8 +81,11 @@ func GenerateClaudeOtherInfo(ctx *gin.Context, relayInfo *relaycommon.RelayInfo,
return
info
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
:=
make
(
map
[
string
]
interface
{})
if
relayInfo
!=
nil
&&
relayInfo
.
RelayFormat
!=
""
{
other
[
"relay_format"
]
=
string
(
relayInfo
.
RelayFormat
)
}
other
[
"model_price"
]
=
priceData
.
ModelPrice
other
[
"model_price"
]
=
priceData
.
ModelPrice
other
[
"group_ratio"
]
=
priceData
.
GroupRatioInfo
.
GroupRatio
other
[
"group_ratio"
]
=
priceData
.
GroupRatioInfo
.
GroupRatio
if
priceData
.
GroupRatioInfo
.
HasSpecialRatio
{
if
priceData
.
GroupRatioInfo
.
HasSpecialRatio
{
...
...
web/src/components/table/usage-logs/UsageLogsColumnDefs.jsx
View file @
97185681
...
@@ -103,6 +103,38 @@ function renderType(type, t) {
...
@@ -103,6 +103,38 @@ function renderType(type, t) {
}
}
}
}
const
relayFormatMeta
=
{
openai
:
{
color
:
'blue'
,
label
:
'OpenAI'
},
claude
:
{
color
:
'purple'
,
label
:
'Claude'
},
gemini
:
{
color
:
'orange'
,
label
:
'Gemini'
},
openai_responses
:
{
color
:
'violet'
,
label
:
'Responses'
},
openai_audio
:
{
color
:
'teal'
,
label
:
'Audio'
},
openai_image
:
{
color
:
'pink'
,
label
:
'Image'
},
openai_realtime
:
{
color
:
'indigo'
,
label
:
'Realtime'
},
rerank
:
{
color
:
'cyan'
,
label
:
'Rerank'
},
embedding
:
{
color
:
'green'
,
label
:
'Embedding'
},
task
:
{
color
:
'amber'
,
label
:
'Task'
},
mj_proxy
:
{
color
:
'red'
,
label
:
'Midjourney'
},
};
function
renderRelayFormat
(
relayFormat
)
{
if
(
!
relayFormat
)
{
return
null
;
}
const
meta
=
relayFormatMeta
[
relayFormat
]
||
{
color
:
'grey'
,
label
:
relayFormat
.
replace
(
/_/g
,
' '
)
.
replace
(
/
\b\w
/g
,
(
c
)
=>
c
.
toUpperCase
()),
};
return
(
<
Tag
color=
{
meta
.
color
}
type=
'light'
shape=
'circle'
size=
'small'
>
{
meta
.
label
}
</
Tag
>
);
}
function
renderIsStream
(
bool
,
t
)
{
function
renderIsStream
(
bool
,
t
)
{
if
(
bool
)
{
if
(
bool
)
{
return
(
return
(
...
@@ -371,7 +403,13 @@ export const getLogsColumns = ({
...
@@ -371,7 +403,13 @@ export const getLogsColumns = ({
title
:
t
(
'类型'
),
title
:
t
(
'类型'
),
dataIndex
:
'type'
,
dataIndex
:
'type'
,
render
:
(
text
,
record
,
index
)
=>
{
render
:
(
text
,
record
,
index
)
=>
{
return
<>
{
renderType
(
text
,
t
)
}
</>;
const
relayFormat
=
getLogOther
(
record
.
other
)?.
relay_format
;
return
(
<
Space
size=
'small'
wrap
>
{
renderType
(
text
,
t
)
}
{
renderRelayFormat
(
relayFormat
)
}
</
Space
>
);
},
},
},
},
{
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment