ai-sdk-ollama 4.6.3 → 4.6.5

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.6.5
4
+
5
+ ### Patch Changes
6
+
7
+ - 89796b6: Report Ollama's `prompt_eval_cached_count` as `usage.inputTokens.cacheRead` (and in `usage.raw`).
8
+
9
+ ## 4.6.4
10
+
11
+ ### Patch Changes
12
+
13
+ - fed4a15: Add `truncate` and `keep_alive` embedding model settings, forwarded to Ollama's `/api/embed`.
14
+
3
15
  ## 4.6.3
4
16
 
5
17
  ### Patch Changes
@@ -1778,6 +1778,7 @@ function buildContent(reasoning, text, toolCalls) {
1778
1778
  }
1779
1779
  var OLLAMA_USAGE_FIELDS = [
1780
1780
  "prompt_eval_count",
1781
+ "prompt_eval_cached_count",
1781
1782
  "eval_count",
1782
1783
  "total_duration",
1783
1784
  "load_duration",
@@ -1802,12 +1803,13 @@ function ollamaResponseDetails(response) {
1802
1803
  }
1803
1804
  return details;
1804
1805
  }
1805
- function createUsage(inputTokenCount, outputTokenCount, raw) {
1806
+ function createUsage(inputTokenCount, outputTokenCount, raw, cachedInputTokenCount) {
1806
1807
  return {
1807
1808
  inputTokens: {
1808
1809
  total: inputTokenCount,
1809
- noCache: inputTokenCount,
1810
- cacheRead: void 0,
1810
+ // prompt_eval_count includes the cached tokens.
1811
+ noCache: inputTokenCount !== void 0 && cachedInputTokenCount !== void 0 ? Math.max(0, inputTokenCount - cachedInputTokenCount) : inputTokenCount,
1812
+ cacheRead: cachedInputTokenCount,
1811
1813
  cacheWrite: void 0
1812
1814
  },
1813
1815
  outputTokens: {
@@ -1832,7 +1834,8 @@ function aggregateUsage(...responses) {
1832
1834
  return createUsage(
1833
1835
  raw.prompt_eval_count,
1834
1836
  raw.eval_count,
1835
- Object.keys(raw).length > 0 ? raw : void 0
1837
+ Object.keys(raw).length > 0 ? raw : void 0,
1838
+ raw.prompt_eval_cached_count
1836
1839
  );
1837
1840
  }
1838
1841
  function requestBody(parameters) {
@@ -2677,6 +2680,12 @@ var OllamaEmbeddingModel = class {
2677
2680
  options: this.settings.options,
2678
2681
  ...this.settings.dimensions !== void 0 && {
2679
2682
  dimensions: this.settings.dimensions
2683
+ },
2684
+ ...this.settings.truncate !== void 0 && {
2685
+ truncate: this.settings.truncate
2686
+ },
2687
+ ...this.settings.keep_alive !== void 0 && {
2688
+ keep_alive: this.settings.keep_alive
2680
2689
  }
2681
2690
  };
2682
2691
  const response = abortSignal ? await this.config.client.embed(request, { signal: abortSignal }) : await this.config.client.embed(request);