Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
eb7d8302
Commit
eb7d8302
authored
Jan 19, 2026
by
cyhhao
Browse files
fix(网关): 修复流式 tool 输入参数转换
parent
eca38984
Changes
1
Hide whitespace changes
Inline
Side-by-side
backend/internal/service/gateway_service.go
View file @
eb7d8302
...
...
@@ -3536,7 +3536,7 @@ func (s *GatewayService) handleStreamingResponse(ctx context.Context, resp *http
eventName
=
eventType
}
if
needModelReplace
&&
eventType
==
"message_start"
{
if
needModelReplace
{
if
msg
,
ok
:=
event
[
"message"
]
.
(
map
[
string
]
any
);
ok
{
if
model
,
ok
:=
msg
[
"model"
]
.
(
string
);
ok
&&
model
==
mappedModel
{
msg
[
"model"
]
=
originalModel
...
...
@@ -3701,45 +3701,6 @@ func (s *GatewayService) handleStreamingResponse(ctx context.Context, resp *http
}
// replaceModelInSSELine 替换SSE数据行中的model字段
func
(
s
*
GatewayService
)
replaceModelInSSELine
(
line
,
fromModel
,
toModel
string
)
string
{
if
!
sseDataRe
.
MatchString
(
line
)
{
return
line
}
data
:=
sseDataRe
.
ReplaceAllString
(
line
,
""
)
if
data
==
""
||
data
==
"[DONE]"
{
return
line
}
var
event
map
[
string
]
any
if
err
:=
json
.
Unmarshal
([]
byte
(
data
),
&
event
);
err
!=
nil
{
return
line
}
// 只替换 message_start 事件中的 message.model
if
event
[
"type"
]
!=
"message_start"
{
return
line
}
msg
,
ok
:=
event
[
"message"
]
.
(
map
[
string
]
any
)
if
!
ok
{
return
line
}
model
,
ok
:=
msg
[
"model"
]
.
(
string
)
if
!
ok
||
model
!=
fromModel
{
return
line
}
msg
[
"model"
]
=
toModel
newData
,
err
:=
json
.
Marshal
(
event
)
if
err
!=
nil
{
return
line
}
return
"data: "
+
string
(
newData
)
}
func
rewriteParamKeysInValue
(
value
any
,
cache
map
[
string
]
string
)
(
any
,
bool
)
{
switch
v
:=
value
.
(
type
)
{
case
map
[
string
]
any
:
...
...
@@ -3860,22 +3821,6 @@ func replaceToolNamesInText(text string, toolNameMap map[string]string) string {
return
output
}
func
(
s
*
GatewayService
)
replaceToolNamesInSSELine
(
line
string
,
toolNameMap
map
[
string
]
string
)
string
{
if
!
sseDataRe
.
MatchString
(
line
)
{
return
line
}
data
:=
sseDataRe
.
ReplaceAllString
(
line
,
""
)
if
data
==
""
||
data
==
"[DONE]"
{
return
line
}
replaced
:=
replaceToolNamesInText
(
data
,
toolNameMap
)
if
replaced
==
data
{
return
line
}
return
"data: "
+
replaced
}
func
(
s
*
GatewayService
)
parseSSEUsage
(
data
string
,
usage
*
ClaudeUsage
)
{
// 解析message_start获取input tokens(标准Claude API格式)
var
msgStart
struct
{
...
...
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