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
Unverified
Commit
2399de97
authored
Aug 08, 2026
by
ENCHIGO
Committed by
GitHub
Aug 08, 2026
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(ali): stop injecting top_p into requests that omit it (#6674)
parent
5c3abffe
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
5 deletions
+72
-5
relay/channel/ali/text.go
+13
-5
relay/channel/ali/text_test.go
+59
-0
No files found.
relay/channel/ali/text.go
View file @
2399de97
...
...
@@ -18,11 +18,19 @@ func requestOpenAI2Ali(request dto.GeneralOpenAIRequest, upstreamModelName strin
request
.
ThinkingBudget
=
nil
}
topP
:=
lo
.
FromPtrOr
(
request
.
TopP
,
0
)
if
topP
>=
1
{
request
.
TopP
=
lo
.
ToPtr
(
0.999
)
}
else
if
topP
<=
0
{
request
.
TopP
=
lo
.
ToPtr
(
0.001
)
// DashScope rejects top_p at the 0 and 1 boundaries, so an explicit value is
// clamped into the open interval. The clamp stays at two decimals because
// some models on the platform reject a third decimal with
// "top_p参数非法:限制小数点[2]位".
//
// A request that omits top_p is left untouched: injecting a value would
// silently replace the model's own default with near-greedy decoding.
if
request
.
TopP
!=
nil
{
if
*
request
.
TopP
>=
1
{
request
.
TopP
=
lo
.
ToPtr
(
0.99
)
}
else
if
*
request
.
TopP
<=
0
{
request
.
TopP
=
lo
.
ToPtr
(
0.01
)
}
}
return
&
request
}
relay/channel/ali/text_test.go
0 → 100644
View file @
2399de97
package
ali
import
(
"testing"
"github.com/QuantumNous/new-api/relaykit/dto"
"github.com/samber/lo"
"github.com/stretchr/testify/assert"
)
func
TestRequestOpenAI2AliTopP
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
topP
*
float64
want
*
float64
}{
{
name
:
"omitted top_p is not injected"
,
topP
:
nil
,
want
:
nil
,
},
{
name
:
"in-range top_p is preserved"
,
topP
:
lo
.
ToPtr
(
0.8
),
want
:
lo
.
ToPtr
(
0.8
),
},
{
name
:
"top_p of 1 is clamped to two decimals"
,
topP
:
lo
.
ToPtr
(
1.0
),
want
:
lo
.
ToPtr
(
0.99
),
},
{
name
:
"top_p above 1 is clamped to two decimals"
,
topP
:
lo
.
ToPtr
(
1.5
),
want
:
lo
.
ToPtr
(
0.99
),
},
{
name
:
"top_p of 0 is clamped to two decimals"
,
topP
:
lo
.
ToPtr
(
0.0
),
want
:
lo
.
ToPtr
(
0.01
),
},
{
name
:
"negative top_p is clamped to two decimals"
,
topP
:
lo
.
ToPtr
(
-
0.3
),
want
:
lo
.
ToPtr
(
0.01
),
},
}
for
_
,
tt
:=
range
tests
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
got
:=
requestOpenAI2Ali
(
dto
.
GeneralOpenAIRequest
{
Model
:
"qwen-plus"
,
TopP
:
tt
.
topP
,
},
"qwen-plus"
)
assert
.
Equal
(
t
,
tt
.
want
,
got
.
TopP
)
})
}
}
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