ai-sdk-ollama 4.6.2 → 4.6.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/CHANGELOG.md +14 -0
- package/README.md +8 -0
- package/dist/functions/generate-text.d.ts +5 -7
- package/dist/functions/generate-text.d.ts.map +1 -1
- package/dist/functions/stream-text.d.ts +7 -5
- package/dist/functions/stream-text.d.ts.map +1 -1
- package/dist/functions/synthesis.d.ts +53 -0
- package/dist/functions/synthesis.d.ts.map +1 -0
- package/dist/index.browser.cjs +483 -490
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +491 -492
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +483 -490
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +491 -492
- package/dist/index.js.map +1 -1
- package/dist/models/decision-model.d.ts.map +1 -1
- package/dist/utils/add-usage.d.ts +4 -0
- package/dist/utils/add-usage.d.ts.map +1 -0
- package/package.json +11 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 4.6.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- c214c21: `generateText` and `streamText` keep the AI SDK's generics, so tool-specific options such as `experimental_toolCallers` type-check and `output` takes its type from your `Output`.
|
|
8
|
+
|
|
9
|
+
`usage` and `totalUsage` include synthesis and structured-output follow-up calls. In `streamText`, so do `text`, the `finish` part and `onEnd`/`onFinish`, and synthesis runs once, when you read the answer. `toUIMessageStream` and `toUIMessageStreamResponse` carry the answer, so `useChat` shows it.
|
|
10
|
+
|
|
11
|
+
With the default `stopWhen`, `toolChoice: 'required'` or a named tool applies to the first step and later steps use `auto`. Synthesis prompts carry each tool's input and output.
|
|
12
|
+
|
|
13
|
+
Decision models report a clear error for box questions and for questions without instructions.
|
|
14
|
+
|
|
15
|
+
`enableToolLogging` and `synthesisTimeout` are deprecated.
|
|
16
|
+
|
|
3
17
|
## 4.6.2
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -368,6 +368,14 @@ const result = await generateText({
|
|
|
368
368
|
console.log(result.text); // "15 + 27 equals 42. Using the math tool, I calculated..."
|
|
369
369
|
```
|
|
370
370
|
|
|
371
|
+
When a run ends on tool results with no answer, the wrapper makes one more model call, without tools, to write it:
|
|
372
|
+
|
|
373
|
+
- `usage`, `totalUsage` and `text` include that call, as do the `finish` part and `onEnd`/`onFinish` of `streamText`.
|
|
374
|
+
- `streamText` runs it once, when you read `textStream`, `stream`, `fullStream` or `text`. `toUIMessageStream`, `toUIMessageStreamResponse`, `toTextStreamResponse` and the `pipe` methods carry the answer too. Reading `usage` or calling `consumeStream` alone doesn't start it.
|
|
375
|
+
- With the default `stopWhen`, `toolChoice: 'required'` or a named tool applies to the first step, and later steps use `auto` so the model can answer in text.
|
|
376
|
+
|
|
377
|
+
`streamText` takes `enhancedOptions: { enableStreamingSynthesis, minStreamLength }`, which default to `true` and `10`.
|
|
378
|
+
|
|
371
379
|
### Combining Tools with Structured Output
|
|
372
380
|
|
|
373
381
|
The `enableToolsWithStructuredOutput` option allows you to use both tool calling and structured output together:
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* generateText - Enhanced generateText with Ollama-specific reliability
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* that addresses the core Ollama limitation: tools execute but no final text is generated.
|
|
4
|
+
* When a run ends on tool results with no answer, one more model call writes it.
|
|
6
5
|
*/
|
|
7
|
-
import {
|
|
6
|
+
import type { Context } from '@ai-sdk/provider-utils';
|
|
7
|
+
import { generateText as _generateText, type GenerateTextResult, type OutputInterface, type ToolSet } from 'ai';
|
|
8
8
|
/**
|
|
9
9
|
* Enhanced options for Ollama-specific reliability features
|
|
10
10
|
*/
|
|
@@ -31,13 +31,10 @@ export interface EnhancedOptions {
|
|
|
31
31
|
/**
|
|
32
32
|
* EXPERIMENTAL: Enable tool calling with structured output (output)
|
|
33
33
|
*
|
|
34
|
-
* The official AI SDK doesn't support combining toolChoice: 'required' with output.
|
|
35
34
|
* When enabled, this uses a two-phase approach:
|
|
36
35
|
* 1. Execute tools first (without output)
|
|
37
36
|
* 2. Generate structured output with tool results injected as context
|
|
38
37
|
*
|
|
39
|
-
* This is NOT standard AI SDK behavior - only enable if you need both features together.
|
|
40
|
-
*
|
|
41
38
|
* @default false
|
|
42
39
|
*/
|
|
43
40
|
enableToolsWithStructuredOutput?: boolean;
|
|
@@ -45,7 +42,7 @@ export interface EnhancedOptions {
|
|
|
45
42
|
/**
|
|
46
43
|
* Enhanced generateText options that extend the official AI SDK options
|
|
47
44
|
*/
|
|
48
|
-
export type GenerateTextOptions = Parameters<typeof _generateText
|
|
45
|
+
export type GenerateTextOptions<TOOLS extends ToolSet = ToolSet, RUNTIME_CONTEXT extends Context = Context, OUTPUT extends OutputInterface = OutputInterface> = Parameters<typeof _generateText<TOOLS, RUNTIME_CONTEXT, OUTPUT>>[0] & {
|
|
49
46
|
/**
|
|
50
47
|
* Enhanced options for Ollama-specific reliability features
|
|
51
48
|
*/
|
|
@@ -59,5 +56,6 @@ export type GenerateTextOptions = Parameters<typeof _generateText>[0] & {
|
|
|
59
56
|
*
|
|
60
57
|
* Type parameters are inferred from the options, preserving AI SDK's type inference.
|
|
61
58
|
*/
|
|
59
|
+
export declare function generateText<TOOLS extends ToolSet, RUNTIME_CONTEXT extends Context = Context, OUTPUT extends OutputInterface = OutputInterface<string, string>>(options: GenerateTextOptions<TOOLS, RUNTIME_CONTEXT, OUTPUT>): Promise<GenerateTextResult<ToolSet, RUNTIME_CONTEXT, OUTPUT>>;
|
|
62
60
|
export declare function generateText(options: GenerateTextOptions): Promise<Awaited<ReturnType<typeof _generateText>>>;
|
|
63
61
|
//# sourceMappingURL=generate-text.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-text.d.ts","sourceRoot":"","sources":["../../src/functions/generate-text.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"generate-text.d.ts","sourceRoot":"","sources":["../../src/functions/generate-text.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EACL,YAAY,IAAI,aAAa,EAE7B,KAAK,kBAAkB,EAEvB,KAAK,eAAe,EACpB,KAAK,OAAO,EACb,MAAM,IAAI,CAAC;AA+BZ;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;;OAGG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAE9B;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAE3B;;;;;;;;OAQG;IACH,+BAA+B,CAAC,EAAE,OAAO,CAAC;CAC3C;AAED;;GAEG;AACH,MAAM,MAAM,mBAAmB,CAC7B,KAAK,SAAS,OAAO,GAAG,OAAO,EAC/B,eAAe,SAAS,OAAO,GAAG,OAAO,EACzC,MAAM,SAAS,eAAe,GAAG,eAAe,IAC9C,UAAU,CAAC,OAAO,aAAa,CAAC,KAAK,EAAE,eAAe,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG;IACxE;;OAEG;IACH,eAAe,CAAC,EAAE,eAAe,CAAC;CACnC,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAsB,YAAY,CAChC,KAAK,SAAS,OAAO,EACrB,eAAe,SAAS,OAAO,GAAG,OAAO,EACzC,MAAM,SAAS,eAAe,GAAG,eAAe,CAAC,MAAM,EAAE,MAAM,CAAC,EAEhE,OAAO,EAAE,mBAAmB,CAAC,KAAK,EAAE,eAAe,EAAE,MAAM,CAAC,GAC3D,OAAO,CAAC,kBAAkB,CAAC,OAAO,EAAE,eAAe,EAAE,MAAM,CAAC,CAAC,CAAC;AAGjE,wBAAsB,YAAY,CAChC,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type
|
|
3
|
-
|
|
1
|
+
import type { Context } from '@ai-sdk/provider-utils';
|
|
2
|
+
import { streamText as _streamText, type OutputInterface, type StreamTextResult, type ToolSet } from 'ai';
|
|
3
|
+
type AIStreamTextOptions<TOOLS extends ToolSet, RUNTIME_CONTEXT extends Context, OUTPUT extends OutputInterface> = Parameters<typeof _streamText<TOOLS, RUNTIME_CONTEXT, OUTPUT>>[0];
|
|
4
|
+
export type StreamTextOptions<TOOLS extends ToolSet = ToolSet, RUNTIME_CONTEXT extends Context = Context, OUTPUT extends OutputInterface = OutputInterface> = AIStreamTextOptions<TOOLS, RUNTIME_CONTEXT, OUTPUT> & {
|
|
4
5
|
enhancedOptions?: {
|
|
5
6
|
/**
|
|
6
|
-
* @
|
|
7
|
+
* @deprecated Has no effect.
|
|
7
8
|
*/
|
|
8
9
|
enableToolLogging?: boolean;
|
|
9
10
|
/**
|
|
@@ -15,11 +16,12 @@ export type StreamTextOptions = AIStreamTextOptions & {
|
|
|
15
16
|
*/
|
|
16
17
|
minStreamLength?: number;
|
|
17
18
|
/**
|
|
18
|
-
* @
|
|
19
|
+
* @deprecated Has no effect: synthesis needs the finished stream.
|
|
19
20
|
*/
|
|
20
21
|
synthesisTimeout?: number;
|
|
21
22
|
};
|
|
22
23
|
};
|
|
24
|
+
export declare function streamText<TOOLS extends ToolSet, RUNTIME_CONTEXT extends Context = Context, OUTPUT extends OutputInterface = OutputInterface<string, string, never>>(options: StreamTextOptions<TOOLS, RUNTIME_CONTEXT, OUTPUT>): Promise<StreamTextResult<ToolSet, RUNTIME_CONTEXT, OUTPUT>>;
|
|
23
25
|
export declare function streamText(options: StreamTextOptions): Promise<Awaited<ReturnType<typeof _streamText>>>;
|
|
24
26
|
export {};
|
|
25
27
|
//# sourceMappingURL=stream-text.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-text.d.ts","sourceRoot":"","sources":["../../src/functions/stream-text.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,IAAI,WAAW,
|
|
1
|
+
{"version":3,"file":"stream-text.d.ts","sourceRoot":"","sources":["../../src/functions/stream-text.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EACL,UAAU,IAAI,WAAW,EAGzB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EAErB,KAAK,OAAO,EACb,MAAM,IAAI,CAAC;AASZ,KAAK,mBAAmB,CACtB,KAAK,SAAS,OAAO,EACrB,eAAe,SAAS,OAAO,EAC/B,MAAM,SAAS,eAAe,IAC5B,UAAU,CAAC,OAAO,WAAW,CAAC,KAAK,EAAE,eAAe,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAuEtE,MAAM,MAAM,iBAAiB,CAC3B,KAAK,SAAS,OAAO,GAAG,OAAO,EAC/B,eAAe,SAAS,OAAO,GAAG,OAAO,EACzC,MAAM,SAAS,eAAe,GAAG,eAAe,IAC9C,mBAAmB,CAAC,KAAK,EAAE,eAAe,EAAE,MAAM,CAAC,GAAG;IACxD,eAAe,CAAC,EAAE;QAChB;;WAEG;QACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;QAC5B;;WAEG;QACH,wBAAwB,CAAC,EAAE,OAAO,CAAC;QACnC;;WAEG;QACH,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB;;WAEG;QACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;KAC3B,CAAC;CACH,CAAC;AAEF,wBAAsB,UAAU,CAC9B,KAAK,SAAS,OAAO,EACrB,eAAe,SAAS,OAAO,GAAG,OAAO,EACzC,MAAM,SAAS,eAAe,GAAG,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAEvE,OAAO,EAAE,iBAAiB,CAAC,KAAK,EAAE,eAAe,EAAE,MAAM,CAAC,GACzD,OAAO,CAAC,gBAAgB,CAAC,OAAO,EAAE,eAAe,EAAE,MAAM,CAAC,CAAC,CAAC;AAG/D,wBAAsB,UAAU,CAC9B,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Synthesis: when a run ends with tool results but no answer, one more model
|
|
3
|
+
* call writes the answer from those results. This is the policy that
|
|
4
|
+
* `generateText` and `streamText` share.
|
|
5
|
+
*/
|
|
6
|
+
import type { ModelMessage, ToolChoice, ToolSet } from 'ai';
|
|
7
|
+
export declare const DEFAULT_SYNTHESIS_PROMPT = "Based on the tool results above, please provide a comprehensive response to the original question.";
|
|
8
|
+
interface FinishedStep {
|
|
9
|
+
toolCalls: unknown[];
|
|
10
|
+
toolResults: Array<{
|
|
11
|
+
toolName: string;
|
|
12
|
+
input?: unknown;
|
|
13
|
+
output?: unknown;
|
|
14
|
+
}>;
|
|
15
|
+
}
|
|
16
|
+
export declare function forcesTool(toolChoice?: ToolChoice<ToolSet>): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* A forced tool applies to every step, so a step that answers in text would
|
|
19
|
+
* fail. With only our default `stopWhen`, force the first step alone.
|
|
20
|
+
*/
|
|
21
|
+
export declare function prepareStepFor<PREPARE_STEP>(options: {
|
|
22
|
+
toolChoice?: ToolChoice<ToolSet>;
|
|
23
|
+
stopWhen?: unknown;
|
|
24
|
+
prepareStep?: PREPARE_STEP;
|
|
25
|
+
}): (({ stepNumber }: {
|
|
26
|
+
stepNumber: number;
|
|
27
|
+
}) => {
|
|
28
|
+
toolChoice?: undefined;
|
|
29
|
+
} | {
|
|
30
|
+
toolChoice: 'auto';
|
|
31
|
+
}) | NonNullable<PREPARE_STEP> | undefined;
|
|
32
|
+
export declare function needsSynthesis({ steps, text, minLength, toolChoice, }: {
|
|
33
|
+
steps: FinishedStep[];
|
|
34
|
+
text: string;
|
|
35
|
+
minLength: number;
|
|
36
|
+
toolChoice?: ToolChoice<ToolSet>;
|
|
37
|
+
}): boolean;
|
|
38
|
+
/** Options for the synthesis call: the caller's, without anything tool-related. */
|
|
39
|
+
export declare function buildSynthesisOptions<OPTIONS extends {
|
|
40
|
+
tools?: unknown;
|
|
41
|
+
toolChoice?: unknown;
|
|
42
|
+
prepareStep?: (options: never) => unknown;
|
|
43
|
+
prompt?: string | ModelMessage[];
|
|
44
|
+
messages?: ModelMessage[];
|
|
45
|
+
}>(options: OPTIONS, steps: FinishedStep[], instruction: string): (Omit<OPTIONS, "messages" | "prepareStep" | "prompt" | "toolChoice" | "tools"> & {
|
|
46
|
+
prepareStep?: ((options: never) => Promise<unknown>) | undefined;
|
|
47
|
+
messages: ModelMessage[];
|
|
48
|
+
}) | (Omit<OPTIONS, "messages" | "prepareStep" | "prompt" | "toolChoice" | "tools"> & {
|
|
49
|
+
prepareStep?: ((options: never) => Promise<unknown>) | undefined;
|
|
50
|
+
prompt: string;
|
|
51
|
+
});
|
|
52
|
+
export {};
|
|
53
|
+
//# sourceMappingURL=synthesis.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"synthesis.d.ts","sourceRoot":"","sources":["../../src/functions/synthesis.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAG5D,eAAO,MAAM,wBAAwB,uGACiE,CAAC;AAEvG,UAAU,YAAY;IACpB,SAAS,EAAE,OAAO,EAAE,CAAC;IACrB,WAAW,EAAE,KAAK,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAC;QAAC,MAAM,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;CAC7E;AAED,wBAAgB,UAAU,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,OAAO,CAEpE;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,YAAY,EAAE,OAAO,EAAE;IACpD,UAAU,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC;IACjC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,YAAY,CAAC;CAC5B,qBAGyB;IAAE,UAAU,EAAE,MAAM,CAAA;CAAE;;;gBACN,MAAM;2CAC/C;AAED,wBAAgB,cAAc,CAAC,EAC7B,KAAK,EACL,IAAI,EACJ,SAAS,EACT,UAAU,GACX,EAAE;IACD,KAAK,EAAE,YAAY,EAAE,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC;CAClC,GAAG,OAAO,CASV;AAgBD,mFAAmF;AACnF,wBAAgB,qBAAqB,CACnC,OAAO,SAAS;IACd,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,WAAW,CAAC,EAAE,CAAC,OAAO,EAAE,KAAK,KAAK,OAAO,CAAC;IAC1C,MAAM,CAAC,EAAE,MAAM,GAAG,YAAY,EAAE,CAAC;IACjC,QAAQ,CAAC,EAAE,YAAY,EAAE,CAAC;CAC3B,EACD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,EAAE,WAAW,EAAE,MAAM;6BArBrC,KAAK;;;;;GAsD7B"}
|