fix(chat-params): guard non-positive max output tokens
This commit is contained in:
@@ -253,4 +253,36 @@ describe("createChatParamsHandler", () => {
|
||||
options: {},
|
||||
})
|
||||
})
|
||||
|
||||
test("falls back to default maxOutputTokens when stored and compatibility tokens are non-positive", async () => {
|
||||
//#given
|
||||
setSessionPromptParams("ses_chat_params", {
|
||||
maxOutputTokens: 0,
|
||||
})
|
||||
|
||||
const handler = createChatParamsHandler({
|
||||
anthropicEffort: null,
|
||||
})
|
||||
|
||||
const input = {
|
||||
sessionID: "ses_chat_params",
|
||||
agent: { name: "oracle" },
|
||||
model: { providerID: "custom-provider", modelID: "custom-model" },
|
||||
provider: { id: "custom-provider" },
|
||||
message: {},
|
||||
}
|
||||
|
||||
const output: ChatParamsOutput = {
|
||||
topP: 1,
|
||||
topK: 1,
|
||||
maxOutputTokens: 0,
|
||||
options: {},
|
||||
}
|
||||
|
||||
//#when
|
||||
await handler(input, output)
|
||||
|
||||
//#then
|
||||
expect(output.maxOutputTokens).toBe(4096)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -96,7 +96,10 @@ export function createChatParamsHandler(args: {
|
||||
if (storedPromptParams.topP !== undefined) {
|
||||
output.topP = storedPromptParams.topP
|
||||
}
|
||||
if (storedPromptParams.maxOutputTokens !== undefined) {
|
||||
if (
|
||||
typeof storedPromptParams.maxOutputTokens === "number" &&
|
||||
storedPromptParams.maxOutputTokens > 0
|
||||
) {
|
||||
(output as Record<string, unknown>).maxOutputTokens = storedPromptParams.maxOutputTokens
|
||||
}
|
||||
if (storedPromptParams.options) {
|
||||
@@ -162,10 +165,12 @@ export function createChatParamsHandler(args: {
|
||||
}
|
||||
|
||||
if ("maxTokens" in compatibility) {
|
||||
if (compatibility.maxTokens !== undefined) {
|
||||
if (compatibility.maxTokens !== undefined && compatibility.maxTokens > 0) {
|
||||
output.maxOutputTokens = compatibility.maxTokens
|
||||
} else {
|
||||
delete output.maxOutputTokens
|
||||
const capabilitiesLimit = capabilities?.maxOutputTokens
|
||||
output.maxOutputTokens =
|
||||
typeof capabilitiesLimit === "number" && capabilitiesLimit > 0 ? capabilitiesLimit : 4096
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -553,6 +553,18 @@ describe("resolveCompatibleModelSettings", () => {
|
||||
expect(result.changes).toEqual([])
|
||||
})
|
||||
|
||||
test("#given desired.maxTokens is 0 #then maxTokens is dropped", () => {
|
||||
const result = resolveCompatibleModelSettings({
|
||||
providerID: "openai",
|
||||
modelID: "gpt-5.4",
|
||||
desired: { maxTokens: 0 },
|
||||
capabilities: { maxOutputTokens: 128_000 },
|
||||
})
|
||||
|
||||
expect(result.maxTokens).toBeUndefined()
|
||||
expect(result.changes).toEqual([])
|
||||
})
|
||||
|
||||
// Passthrough: undefined desired values produce no changes
|
||||
test("no-op when desired settings are empty", () => {
|
||||
const result = resolveCompatibleModelSettings({
|
||||
|
||||
@@ -162,6 +162,10 @@ export function resolveCompatibleModelSettings(
|
||||
}
|
||||
|
||||
let maxTokens = input.desired.maxTokens
|
||||
if (maxTokens !== undefined && maxTokens <= 0) {
|
||||
maxTokens = undefined
|
||||
}
|
||||
|
||||
if (
|
||||
maxTokens !== undefined &&
|
||||
input.capabilities?.maxOutputTokens !== undefined &&
|
||||
|
||||
Reference in New Issue
Block a user