@jambonz/llm 0.4.0 → 0.4.2

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 CHANGED
@@ -126,7 +126,10 @@ async function* streamFromOpenAI(client, req, options) {
126
126
  }
127
127
  if (req.temperature !== void 0) body.temperature = req.temperature;
128
128
  const effectiveMaxTokens = req.maxTokens ?? options.defaultMaxTokens;
129
- if (effectiveMaxTokens !== void 0) body.max_tokens = effectiveMaxTokens;
129
+ if (effectiveMaxTokens !== void 0) {
130
+ const param = options.tokensParam ?? (needsMaxCompletionTokens(req.model) ? "max_completion_tokens" : "max_tokens");
131
+ body[param] = effectiveMaxTokens;
132
+ }
130
133
  let stream;
131
134
  try {
132
135
  stream = await client.chat.completions.create(body, { signal: req.signal });
@@ -309,6 +312,9 @@ function capabilitiesFor(modelId, knownModels) {
309
312
  if (known) return known.capabilities;
310
313
  return defaultCapabilitiesForUnknown(modelId);
311
314
  }
315
+ function needsMaxCompletionTokens(modelId) {
316
+ return /^(o\d|gpt-5)/i.test(modelId);
317
+ }
312
318
  function defaultCapabilitiesForUnknown(modelId) {
313
319
  const isReasoning = /^o[13]([-/]|$)/i.test(modelId);
314
320
  if (isReasoning) {
@@ -1686,7 +1692,12 @@ var VertexOpenAIAdapter = class {
1686
1692
  stream(req) {
1687
1693
  return streamFromOpenAI(this.ensureClient(), req, {
1688
1694
  knownModels: vertexOpenAIManifest.knownModels,
1689
- defaultMaxTokens: 4096
1695
+ defaultMaxTokens: 4096,
1696
+ // Pin legacy `max_tokens`: Vertex's OpenAI-compat partner-model
1697
+ // endpoint predates `max_completion_tokens` and may not recognize it.
1698
+ // The model-id heuristic wouldn't catch a partner model named in the
1699
+ // OpenAI style (unlikely today, but defensive).
1700
+ tokensParam: "max_tokens"
1690
1701
  });
1691
1702
  }
1692
1703
  appendAssistantToolCall(history, toolCalls) {
@@ -2380,8 +2391,8 @@ var azureOpenAIManifest = {
2380
2391
  label: "API Version",
2381
2392
  type: "text",
2382
2393
  required: true,
2383
- default: "2024-10-21",
2384
- help: "Data-plane api-version, e.g. 2024-10-21. Microsoft rolls these frequently; see Azure OpenAI API reference docs for the current stable GA version."
2394
+ default: "2025-03-01-preview",
2395
+ help: "Data-plane api-version, e.g. 2025-03-01-preview. Microsoft rolls these frequently; newer gpt-5 / o-series deployments require an api-version that supports the Responses API (2025-03-01-preview or later). See Azure OpenAI API reference docs for the current recommended version."
2385
2396
  }
2386
2397
  ]
2387
2398
  }
@@ -2428,7 +2439,8 @@ var AzureOpenAIAdapter = class {
2428
2439
  }
2429
2440
  stream(req) {
2430
2441
  return streamFromOpenAI(this.ensureClient(), req, {
2431
- knownModels: azureOpenAIManifest.knownModels
2442
+ knownModels: azureOpenAIManifest.knownModels,
2443
+ tokensParam: "max_completion_tokens"
2432
2444
  });
2433
2445
  }
2434
2446
  appendAssistantToolCall(history, toolCalls) {
@@ -2447,7 +2459,12 @@ var AzureOpenAIAdapter = class {
2447
2459
  // still requires it as a parameter.
2448
2460
  model: "probe",
2449
2461
  messages: [{ role: "user", content: "ping" }],
2450
- max_tokens: 1,
2462
+ // Use `max_completion_tokens` (not legacy `max_tokens`): gpt-5 family
2463
+ // and o-series reasoning models return 400 on the legacy parameter.
2464
+ // The newer name is a superset — also accepted by gpt-4o, gpt-4-turbo,
2465
+ // and gpt-3.5-turbo deployments — so it's the safe choice for a probe
2466
+ // that has to work regardless of the underlying deployment model.
2467
+ max_completion_tokens: 1,
2451
2468
  stream: false
2452
2469
  });
2453
2470
  }