@ljoukov/llm 7.0.2 → 7.0.3

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/README.md CHANGED
@@ -491,6 +491,18 @@ const { value } = await generateJson({
491
491
  console.log(value.ok, value.message);
492
492
  ```
493
493
 
494
+ For Gemini calls that need a specific thinking budget, pass `thinkingBudget`. This overrides the model default and
495
+ `thinkingLevel` for Gemini requests:
496
+
497
+ ```ts
498
+ const { value } = await generateJson({
499
+ model: "gemini-flash-latest",
500
+ input: "Return a JSON object with ok=true and message='hello'.",
501
+ schema,
502
+ thinkingBudget: 0,
503
+ });
504
+ ```
505
+
494
506
  ### Streaming JSON outputs
495
507
 
496
508
  Use `streamJson()` to stream thought deltas and get best-effort partial JSON snapshots while the model is still
package/dist/index.cjs CHANGED
@@ -7258,10 +7258,14 @@ function toGemini25ProThinkingBudget(thinkingLevel) {
7258
7258
  return 32768;
7259
7259
  }
7260
7260
  }
7261
- function resolveGeminiThinkingConfig(modelId, thinkingLevel) {
7261
+ function resolveGeminiThinkingConfig(modelId, thinkingLevel, thinkingBudget) {
7262
7262
  if (isGeminiImageModelId(modelId) || modelId === "gemini-flash-lite-latest") {
7263
7263
  return void 0;
7264
7264
  }
7265
+ if (thinkingBudget !== void 0) {
7266
+ const normalizedBudget = Math.max(0, Math.floor(thinkingBudget));
7267
+ return normalizedBudget === 0 ? { thinkingBudget: 0 } : { includeThoughts: true, thinkingBudget: normalizedBudget };
7268
+ }
7265
7269
  if (thinkingLevel) {
7266
7270
  if (modelId === "gemini-2.5-pro") {
7267
7271
  return {
@@ -7637,6 +7641,7 @@ function startLlmCallLoggerFromContents(options) {
7637
7641
  ...options.request.imageAspectRatio ? { imageAspectRatio: options.request.imageAspectRatio } : {},
7638
7642
  ...options.request.imageSize ? { imageSize: options.request.imageSize } : {},
7639
7643
  ...options.request.thinkingLevel ? { thinkingLevel: options.request.thinkingLevel } : {},
7644
+ ...options.request.thinkingBudget !== void 0 ? { thinkingBudget: options.request.thinkingBudget } : {},
7640
7645
  ...options.request.mediaResolution ? { mediaResolution: options.request.mediaResolution } : {},
7641
7646
  ...options.request.openAiTextFormat ? { openAiTextFormat: sanitiseLogValue(options.request.openAiTextFormat) } : {},
7642
7647
  ...getCurrentToolCallContext() ? { toolContext: getCurrentToolCallContext() } : {}
@@ -7938,7 +7943,11 @@ async function runTextCall(params) {
7938
7943
  })
7939
7944
  )
7940
7945
  );
7941
- const thinkingConfig = resolveGeminiThinkingConfig(modelForProvider, request.thinkingLevel);
7946
+ const thinkingConfig = resolveGeminiThinkingConfig(
7947
+ modelForProvider,
7948
+ request.thinkingLevel,
7949
+ request.thinkingBudget
7950
+ );
7942
7951
  const mediaResolution = toGeminiMediaResolution(request.mediaResolution);
7943
7952
  const config = {
7944
7953
  maxOutputTokens: 32e3,
@@ -8245,6 +8254,7 @@ function startJsonStream(request, operation) {
8245
8254
  responseMimeType: request.responseMimeType ?? "application/json",
8246
8255
  responseJsonSchema,
8247
8256
  thinkingLevel: request.thinkingLevel,
8257
+ thinkingBudget: request.thinkingBudget,
8248
8258
  ...openAiTextFormatForAttempt ? { openAiTextFormat: openAiTextFormatForAttempt } : {},
8249
8259
  telemetry: false,
8250
8260
  signal
@@ -9649,7 +9659,11 @@ async function runToolLoop(request) {
9649
9659
  firstModelEventAtMs = Date.now();
9650
9660
  }
9651
9661
  };
9652
- const thinkingConfig = resolveGeminiThinkingConfig(request.model, request.thinkingLevel);
9662
+ const thinkingConfig = resolveGeminiThinkingConfig(
9663
+ request.model,
9664
+ request.thinkingLevel,
9665
+ request.thinkingBudget
9666
+ );
9653
9667
  const mediaResolution = toGeminiMediaResolution(request.mediaResolution);
9654
9668
  const config = {
9655
9669
  maxOutputTokens: 32e3,