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.
This commit is contained in:
Felix-Ayush
2026-07-29 12:21:15 -07:00
committed by GitHub
parent 70bf03a6e7
commit fd1f4e2ac2
2 changed files with 19 additions and 5 deletions
+12
View File
@@ -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({
+7 -5
View File
@@ -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];
}
}