From fd1f4e2ac2f9a9fd059c35088794fc0c30b0e06e Mon Sep 17 00:00:00 2001 From: Felix-Ayush <67006255+Ayush7614@users.noreply.github.com> Date: Thu, 30 Jul 2026 00:51:15 +0530 Subject: [PATCH] fix(puter-js): forward temperature 0 and max_tokens 0 in ai.chat (#3455) Truthy checks dropped legitimate zero values, so deterministic sampling never reached the driver. Match the stream option and use !== undefined. --- src/puter-js/src/modules/ai/ai.test.js | 12 ++++++++++++ src/puter-js/src/modules/ai/chat.js | 12 +++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/puter-js/src/modules/ai/ai.test.js b/src/puter-js/src/modules/ai/ai.test.js index 05bccf3b8..c9ef15cb1 100644 --- a/src/puter-js/src/modules/ai/ai.test.js +++ b/src/puter-js/src/modules/ai/ai.test.js @@ -163,6 +163,18 @@ describe('ai.chat driver payloads', () => { }); }); + it('chat(prompt, options) forwards temperature: 0 and max_tokens: 0', async () => { + await ai.chat('hello', { + temperature: 0, + max_tokens: 0, + }); + expect(lastBody().args).toEqual({ + messages: [{ content: 'hello' }], + temperature: 0, + max_tokens: 0, + }); + }); + it('chat(prompt, imageURL) builds a vision request', async () => { await ai.chat('describe', 'https://example.com/cat.png'); expect(lastBody().args).toEqual({ diff --git a/src/puter-js/src/modules/ai/chat.js b/src/puter-js/src/modules/ai/chat.js index ad939aea1..78216f174 100644 --- a/src/puter-js/src/modules/ai/chat.js +++ b/src/puter-js/src/modules/ai/chat.js @@ -201,14 +201,16 @@ export async function chat ( /** @type {ChatOptions & { stream?: boolean }} */ const userParams = extras.find(isPlainObject) ?? {}; - // Copy relevant parameters from userParams to requestParams - if (userParams.model) { + // Copy relevant parameters from userParams to requestParams. + // Use `!== undefined` so legitimate zeros (temperature: 0, max_tokens: 0) + // are forwarded — truthy checks silently drop them. + if (userParams.model !== undefined) { requestParams.model = userParams.model; } - if (userParams.temperature) { + if (userParams.temperature !== undefined) { requestParams.temperature = userParams.temperature; } - if (userParams.max_tokens) { + if (userParams.max_tokens !== undefined) { requestParams.max_tokens = userParams.max_tokens; } @@ -220,7 +222,7 @@ export async function chat ( } for (const name of PARAMS_TO_PASS) { - if (userParams[name]) { + if (userParams[name] !== undefined) { requestParams[name] = userParams[name]; } }