mirror of
https://github.com/HeyPuter/puter.git
synced 2026-08-24 06:58:21 +00:00
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:
@@ -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({
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user