@jambonz/llm 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +21 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +21 -4
- package/dist/index.js.map +1 -1
- package/dist/test-kit/index.cjs +21 -4
- package/dist/test-kit/index.cjs.map +1 -1
- package/dist/test-kit/index.js +21 -4
- package/dist/test-kit/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -81,7 +81,10 @@ async function* streamFromOpenAI(client, req, options) {
|
|
|
81
81
|
}
|
|
82
82
|
if (req.temperature !== void 0) body.temperature = req.temperature;
|
|
83
83
|
const effectiveMaxTokens = req.maxTokens ?? options.defaultMaxTokens;
|
|
84
|
-
if (effectiveMaxTokens !== void 0)
|
|
84
|
+
if (effectiveMaxTokens !== void 0) {
|
|
85
|
+
const param = options.tokensParam ?? (needsMaxCompletionTokens(req.model) ? "max_completion_tokens" : "max_tokens");
|
|
86
|
+
body[param] = effectiveMaxTokens;
|
|
87
|
+
}
|
|
85
88
|
let stream;
|
|
86
89
|
try {
|
|
87
90
|
stream = await client.chat.completions.create(body, { signal: req.signal });
|
|
@@ -264,6 +267,9 @@ function capabilitiesFor(modelId, knownModels) {
|
|
|
264
267
|
if (known) return known.capabilities;
|
|
265
268
|
return defaultCapabilitiesForUnknown(modelId);
|
|
266
269
|
}
|
|
270
|
+
function needsMaxCompletionTokens(modelId) {
|
|
271
|
+
return /^(o\d|gpt-5)/i.test(modelId);
|
|
272
|
+
}
|
|
267
273
|
function defaultCapabilitiesForUnknown(modelId) {
|
|
268
274
|
const isReasoning = /^o[13]([-/]|$)/i.test(modelId);
|
|
269
275
|
if (isReasoning) {
|
|
@@ -1641,7 +1647,12 @@ var VertexOpenAIAdapter = class {
|
|
|
1641
1647
|
stream(req) {
|
|
1642
1648
|
return streamFromOpenAI(this.ensureClient(), req, {
|
|
1643
1649
|
knownModels: vertexOpenAIManifest.knownModels,
|
|
1644
|
-
defaultMaxTokens: 4096
|
|
1650
|
+
defaultMaxTokens: 4096,
|
|
1651
|
+
// Pin legacy `max_tokens`: Vertex's OpenAI-compat partner-model
|
|
1652
|
+
// endpoint predates `max_completion_tokens` and may not recognize it.
|
|
1653
|
+
// The model-id heuristic wouldn't catch a partner model named in the
|
|
1654
|
+
// OpenAI style (unlikely today, but defensive).
|
|
1655
|
+
tokensParam: "max_tokens"
|
|
1645
1656
|
});
|
|
1646
1657
|
}
|
|
1647
1658
|
appendAssistantToolCall(history, toolCalls) {
|
|
@@ -2389,7 +2400,8 @@ var AzureOpenAIAdapter = class {
|
|
|
2389
2400
|
}
|
|
2390
2401
|
stream(req) {
|
|
2391
2402
|
return streamFromOpenAI(this.ensureClient(), req, {
|
|
2392
|
-
knownModels: azureOpenAIManifest.knownModels
|
|
2403
|
+
knownModels: azureOpenAIManifest.knownModels,
|
|
2404
|
+
tokensParam: "max_completion_tokens"
|
|
2393
2405
|
});
|
|
2394
2406
|
}
|
|
2395
2407
|
appendAssistantToolCall(history, toolCalls) {
|
|
@@ -2408,7 +2420,12 @@ var AzureOpenAIAdapter = class {
|
|
|
2408
2420
|
// still requires it as a parameter.
|
|
2409
2421
|
model: "probe",
|
|
2410
2422
|
messages: [{ role: "user", content: "ping" }],
|
|
2411
|
-
max_tokens:
|
|
2423
|
+
// Use `max_completion_tokens` (not legacy `max_tokens`): gpt-5 family
|
|
2424
|
+
// and o-series reasoning models return 400 on the legacy parameter.
|
|
2425
|
+
// The newer name is a superset — also accepted by gpt-4o, gpt-4-turbo,
|
|
2426
|
+
// and gpt-3.5-turbo deployments — so it's the safe choice for a probe
|
|
2427
|
+
// that has to work regardless of the underlying deployment model.
|
|
2428
|
+
max_completion_tokens: 1,
|
|
2412
2429
|
stream: false
|
|
2413
2430
|
});
|
|
2414
2431
|
}
|