ai-sdk-ollama 4.2.0 → 4.3.0

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.
Files changed (36) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +38 -13
  3. package/dist/index.browser.cjs +6286 -1903
  4. package/dist/index.browser.cjs.map +1 -1
  5. package/dist/index.browser.d.ts +1 -0
  6. package/dist/index.browser.d.ts.map +1 -1
  7. package/dist/index.browser.js +6286 -1903
  8. package/dist/index.browser.js.map +1 -1
  9. package/dist/index.cjs +6316 -1933
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.ts +1 -0
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +6316 -1933
  14. package/dist/index.js.map +1 -1
  15. package/dist/models/chat-language-model.d.ts +3 -2
  16. package/dist/models/chat-language-model.d.ts.map +1 -1
  17. package/dist/models/chat-language-model.test-helpers.d.ts +1 -1
  18. package/dist/models/chat-language-model.test-helpers.d.ts.map +1 -1
  19. package/dist/models/chat-result.d.ts +1 -2
  20. package/dist/models/chat-result.d.ts.map +1 -1
  21. package/dist/models/chat-stream.d.ts +2 -3
  22. package/dist/models/chat-stream.d.ts.map +1 -1
  23. package/dist/models/embedding-model.d.ts +2 -2
  24. package/dist/models/embedding-model.d.ts.map +1 -1
  25. package/dist/models/embedding-reranking-model.d.ts +3 -3
  26. package/dist/models/embedding-reranking-model.d.ts.map +1 -1
  27. package/dist/ollama-client.d.ts +40 -0
  28. package/dist/ollama-client.d.ts.map +1 -0
  29. package/dist/provider.browser.d.ts.map +1 -1
  30. package/dist/provider.d.ts +3 -2
  31. package/dist/provider.d.ts.map +1 -1
  32. package/dist/tool/web-fetch.d.ts +2 -4
  33. package/dist/tool/web-fetch.d.ts.map +1 -1
  34. package/dist/tool/web-search.d.ts +4 -6
  35. package/dist/tool/web-search.d.ts.map +1 -1
  36. package/package.json +12 -17
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 4.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 371f515: Track AI SDK 7.0.95 and open the provider up to custom Ollama clients.
8
+
9
+ - The `ai` peer range moves to `^7.0.95`, with `@ai-sdk/provider` and `@ai-sdk/provider-utils` updated to match.
10
+ - `OllamaClient` is a structural contract, so the official client, a maintained fork, or a custom adapter can be injected in both Node.js and browser builds. Streaming methods use the newly exported `AbortableStream` type.
11
+ - Per-request `AbortSignal`s are forwarded to the client, and an aborted request settles as a rejection across the reliability retry and fallback paths.
12
+ - Returned `message.thinking` is surfaced as AI SDK reasoning independently of the request's `think` setting, including on terminal stream chunks, and streamed text and reasoning blocks close symmetrically.
13
+ - Output usage carries the total token count Ollama reports and leaves the text/reasoning split unset, matching what the API provides.
14
+
3
15
  ## 4.2.0
4
16
 
5
17
  ### Minor Changes
package/README.md CHANGED
@@ -740,7 +740,10 @@ const ollama = createOllama({ apiKey: process.env.OLLAMA_API_KEY });
740
740
 
741
741
  ### Using Existing Ollama Client
742
742
 
743
- You can also pass an existing Ollama client instance to reuse your configuration:
743
+ You can also pass an existing Ollama client instance to reuse your configuration.
744
+ The provider accepts the exported structural `OllamaClient` interface, so the
745
+ official client, the maintained compatibility fork, or a custom adapter can be
746
+ injected in Node.js and browser builds.
744
747
 
745
748
  ```typescript
746
749
  import { Ollama } from 'ollama';
@@ -756,13 +759,36 @@ const existingClient = new Ollama({
756
759
  const ollamaSdk = createOllama({ client: existingClient });
757
760
 
758
761
  // Use both clients as needed
759
- await ollamaRaw.list(); // Direct Ollama operations
762
+ await existingClient.list(); // Direct Ollama operations
760
763
  const { text } = await generateText({
761
764
  model: ollamaSdk('llama3.2'),
762
765
  prompt: 'Hello!',
763
766
  });
764
767
  ```
765
768
 
769
+ #### Custom client adapters
770
+
771
+ `OllamaClient` is structural, so any object with the right shape works — no
772
+ `Ollama` instance required. Streaming methods return an `AbortableStream`, an
773
+ async iterable with an `abort()`:
774
+
775
+ ```typescript
776
+ import type { AbortableStream, OllamaClient } from 'ai-sdk-ollama';
777
+ import { createOllama } from 'ai-sdk-ollama';
778
+
779
+ const client: OllamaClient = {
780
+ chat: myChat, // returns a ChatResponse, or an AbortableStream of them
781
+ embed: myEmbed,
782
+ webSearch: myWebSearch,
783
+ webFetch: myWebFetch,
784
+ };
785
+
786
+ const ollama = createOllama({ client });
787
+ ```
788
+
789
+ Per-request cancellation is forwarded to the client as an `AbortSignal`, and an
790
+ aborted request rejects rather than resolving with a retried or fallback result.
791
+
766
792
  ### Structured Output
767
793
 
768
794
  ```typescript
@@ -918,39 +944,38 @@ const { output: custom } = await generateText({
918
944
 
919
945
  ### Reasoning Support
920
946
 
921
- Some models like DeepSeek-R1 support reasoning (chain-of-thought) output. Enable this feature to see the model's thinking process:
947
+ Use `think` to request reasoning generation from models that support it. Returned `message.thinking` is exposed as AI SDK reasoning, separately from final text, in both generation results and streams (including terminal chunks).
922
948
 
923
949
  ```typescript
924
950
  import { ollama } from 'ai-sdk-ollama';
925
951
  import { generateText } from 'ai';
926
952
 
927
953
  // Enable reasoning for models that support it (e.g., deepseek-r1:7b)
928
- const model = ollama('deepseek-r1:7b', { reasoning: true });
954
+ const model = ollama('deepseek-r1:7b', { think: true });
929
955
 
930
956
  // Generate text with reasoning
931
- const { text } = await generateText({
957
+ const { text, reasoningText } = await generateText({
932
958
  model,
933
959
  prompt:
934
960
  'Solve: If I have 3 boxes, each with 4 smaller boxes, and each smaller box has 5 items, how many items total?',
935
961
  });
936
962
 
937
963
  console.log('Answer:', text);
938
- // DeepSeek-R1 includes reasoning in the output with <think> tags:
939
- // <think>
940
- // First, I'll calculate the number of smaller boxes: 3 × 4 = 12
941
- // Then, the total items: 12 × 5 = 60
942
- // </think>
943
- // You have 60 items in total.
964
+ console.log('Reasoning:', reasoningText);
944
965
 
945
966
  // Compare with reasoning disabled
946
- const modelNoReasoning = ollama('deepseek-r1:7b', { reasoning: false });
967
+ const modelNoReasoning = ollama('deepseek-r1:7b', { think: false });
947
968
  const { text: noReasoningText } = await generateText({
948
969
  model: modelNoReasoning,
949
970
  prompt: 'Calculate 3 × 4 × 5',
950
971
  });
951
- // Output: 60 (without showing the thinking process)
972
+ console.log('Answer:', noReasoningText);
952
973
  ```
953
974
 
975
+ `think` controls the request, not filtering of the response. If the server returns thinking with `think` omitted or `false`, the adapter still preserves it as reasoning; it does not turn it into final text. If no thinking is returned, no reasoning content is added.
976
+
977
+ Ollama supplies a combined output token count. The adapter preserves that total and the raw counters, but leaves the text/reasoning token breakdown unknown instead of attributing all output tokens to text.
978
+
954
979
  **Recommended Reasoning Models**:
955
980
 
956
981
  - `deepseek-r1:7b` - Balanced performance and reasoning capability (5GB)