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
02db4c76
Commit
02db4c76
authored
Jan 19, 2026
by
cyhhao
Browse files
fix(网关): 修复流式 tool 输入参数转换
parent
a05b8b56
Changes
1
Hide whitespace changes
Inline
Side-by-side
backend/internal/service/gateway_service.go
View file @
02db4c76
...
@@ -3391,7 +3391,7 @@ func (s *GatewayService) handleStreamingResponse(ctx context.Context, resp *http
...
@@ -3391,7 +3391,7 @@ func (s *GatewayService) handleStreamingResponse(ctx context.Context, resp *http
eventName
=
eventType
eventName
=
eventType
}
}
if needModelReplace
&& eventType == "message_start"
{
if
needModelReplace
{
if
msg
,
ok
:=
event
[
"message"
]
.
(
map
[
string
]
any
);
ok
{
if
msg
,
ok
:=
event
[
"message"
]
.
(
map
[
string
]
any
);
ok
{
if
model
,
ok
:=
msg
[
"model"
]
.
(
string
);
ok
&&
model
==
mappedModel
{
if
model
,
ok
:=
msg
[
"model"
]
.
(
string
);
ok
&&
model
==
mappedModel
{
msg
[
"model"
]
=
originalModel
msg
[
"model"
]
=
originalModel
...
@@ -3556,45 +3556,6 @@ func (s *GatewayService) handleStreamingResponse(ctx context.Context, resp *http
...
@@ -3556,45 +3556,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
)
{
func
rewriteParamKeysInValue
(
value
any
,
cache
map
[
string
]
string
)
(
any
,
bool
)
{
switch
v
:=
value
.
(
type
)
{
switch
v
:=
value
.
(
type
)
{
case
map
[
string
]
any
:
case
map
[
string
]
any
:
...
@@ -3715,22 +3676,6 @@ func replaceToolNamesInText(text string, toolNameMap map[string]string) string {
...
@@ -3715,22 +3676,6 @@ func replaceToolNamesInText(text string, toolNameMap map[string]string) string {
return
output
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
)
{
func
(
s
*
GatewayService
)
parseSSEUsage
(
data
string
,
usage
*
ClaudeUsage
)
{
// 解析message_start获取input tokens(标准Claude API格式)
// 解析message_start获取input tokens(标准Claude API格式)
var
msgStart
struct
{
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