Add failsafe incase max_tokens is 0 or negative for a model (#1954)
Docker Image CI / build-and-push-image (push) Has been cancelled
Maintain Release Merge PR / update-release-pr (push) Has been cancelled
release-please / release-please (push) Has been cancelled
test / test (20.x) (push) Has been cancelled
test / test (22.x) (push) Has been cancelled
test / backend (node env, api-test) (22.x) (push) Has been cancelled
test / puterjs (browser env, playwright) (22.x) (push) Has been cancelled
test / puterjs (node env, vitest) (22.x) (push) Has been cancelled

This commit is contained in:
Neal Shah
2025-11-09 19:22:34 -05:00
committed by GitHub
parent 3c3367ca52
commit bb2c78ae2d
@@ -403,6 +403,9 @@ class AIChatService extends BaseService {
parameters.max_tokens = Math.floor(Math.min(parameters.max_tokens ?? Number.POSITIVE_INFINITY,
max_allowed_output_tokens,
model_max_tokens - (Math.ceil(text.length / 4))));
if (parameters.max_tokens < 1) {
parameters.max_tokens = undefined;
}
}
try {
ret = await svc_driver.call_new_({