modelfusion 0.53.2 → 0.55.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 (110) hide show
  1. package/README.md +71 -4
  2. package/browser/convertAudioChunksToBase64.cjs +8 -0
  3. package/browser/convertAudioChunksToBase64.d.ts +4 -0
  4. package/browser/convertAudioChunksToBase64.js +4 -0
  5. package/browser/convertBlobToBase64.cjs +23 -0
  6. package/browser/convertBlobToBase64.d.ts +1 -0
  7. package/browser/convertBlobToBase64.js +19 -0
  8. package/{event-source → browser}/index.cjs +4 -1
  9. package/browser/index.d.ts +6 -0
  10. package/browser/index.js +6 -0
  11. package/browser/invokeFlow.cjs +23 -0
  12. package/browser/invokeFlow.d.ts +8 -0
  13. package/browser/invokeFlow.js +19 -0
  14. package/{event-source → browser}/readEventSource.cjs +8 -3
  15. package/{event-source → browser}/readEventSource.d.ts +3 -1
  16. package/{event-source → browser}/readEventSource.js +8 -3
  17. package/{event-source → browser}/readEventSourceStream.cjs +1 -1
  18. package/{event-source → browser}/readEventSourceStream.js +1 -1
  19. package/index.cjs +0 -2
  20. package/index.d.ts +0 -2
  21. package/index.js +0 -2
  22. package/model-provider/anthropic/AnthropicTextGenerationModel.cjs +1 -1
  23. package/model-provider/anthropic/AnthropicTextGenerationModel.js +1 -1
  24. package/model-provider/cohere/CohereTextGenerationModel.cjs +31 -50
  25. package/model-provider/cohere/CohereTextGenerationModel.js +31 -50
  26. package/model-provider/index.cjs +1 -0
  27. package/model-provider/index.d.ts +1 -0
  28. package/model-provider/index.js +1 -0
  29. package/model-provider/llamacpp/LlamaCppTextGenerationModel.cjs +1 -1
  30. package/model-provider/llamacpp/LlamaCppTextGenerationModel.js +1 -1
  31. package/model-provider/ollama/OllamaApiConfiguration.cjs +15 -0
  32. package/model-provider/ollama/OllamaApiConfiguration.d.ts +10 -0
  33. package/model-provider/ollama/OllamaApiConfiguration.js +11 -0
  34. package/model-provider/ollama/OllamaError.cjs +29 -0
  35. package/model-provider/ollama/OllamaError.d.ts +22 -0
  36. package/model-provider/ollama/OllamaError.js +24 -0
  37. package/model-provider/ollama/OllamaTextGenerationModel.cjs +216 -0
  38. package/model-provider/ollama/OllamaTextGenerationModel.d.ts +134 -0
  39. package/model-provider/ollama/OllamaTextGenerationModel.js +212 -0
  40. package/model-provider/ollama/index.cjs +21 -0
  41. package/model-provider/ollama/index.d.ts +3 -0
  42. package/model-provider/ollama/index.js +3 -0
  43. package/model-provider/openai/OpenAICompletionModel.cjs +2 -2
  44. package/model-provider/openai/OpenAICompletionModel.js +2 -2
  45. package/model-provider/openai/chat/OpenAIChatStreamIterable.cjs +1 -1
  46. package/model-provider/openai/chat/OpenAIChatStreamIterable.js +1 -1
  47. package/package.json +13 -4
  48. package/server/fastify/AssetStorage.cjs +2 -0
  49. package/server/fastify/AssetStorage.d.ts +17 -0
  50. package/server/fastify/AssetStorage.js +1 -0
  51. package/server/fastify/DefaultFlow.cjs +22 -0
  52. package/server/fastify/DefaultFlow.d.ts +16 -0
  53. package/server/fastify/DefaultFlow.js +18 -0
  54. package/server/fastify/FileSystemAssetStorage.cjs +60 -0
  55. package/server/fastify/FileSystemAssetStorage.d.ts +19 -0
  56. package/server/fastify/FileSystemAssetStorage.js +56 -0
  57. package/server/fastify/FileSystemLogger.cjs +48 -0
  58. package/server/fastify/FileSystemLogger.d.ts +18 -0
  59. package/server/fastify/FileSystemLogger.js +44 -0
  60. package/server/fastify/Flow.cjs +2 -0
  61. package/server/fastify/Flow.d.ts +9 -0
  62. package/server/fastify/Flow.js +1 -0
  63. package/server/fastify/FlowRun.cjs +71 -0
  64. package/server/fastify/FlowRun.d.ts +28 -0
  65. package/server/fastify/FlowRun.js +67 -0
  66. package/server/fastify/FlowSchema.cjs +2 -0
  67. package/server/fastify/FlowSchema.d.ts +5 -0
  68. package/server/fastify/FlowSchema.js +1 -0
  69. package/server/fastify/Logger.cjs +2 -0
  70. package/server/fastify/Logger.d.ts +13 -0
  71. package/server/fastify/Logger.js +1 -0
  72. package/server/fastify/PathProvider.cjs +34 -0
  73. package/server/fastify/PathProvider.d.ts +12 -0
  74. package/server/fastify/PathProvider.js +30 -0
  75. package/server/fastify/index.cjs +24 -0
  76. package/server/fastify/index.d.ts +8 -0
  77. package/server/fastify/index.js +8 -0
  78. package/server/fastify/modelFusionFlowPlugin.cjs +102 -0
  79. package/server/fastify/modelFusionFlowPlugin.d.ts +12 -0
  80. package/server/fastify/modelFusionFlowPlugin.js +98 -0
  81. package/util/index.cjs +1 -0
  82. package/util/index.d.ts +1 -0
  83. package/util/index.js +1 -0
  84. package/{event-source → util/streaming}/createEventSourceStream.cjs +7 -3
  85. package/util/streaming/createEventSourceStream.js +15 -0
  86. package/{ui → util/streaming}/index.cjs +1 -1
  87. package/util/streaming/index.d.ts +1 -0
  88. package/util/streaming/index.js +1 -0
  89. package/util/streaming/parseJsonStream.cjs +35 -0
  90. package/util/streaming/parseJsonStream.d.ts +6 -0
  91. package/util/streaming/parseJsonStream.js +31 -0
  92. package/event-source/createEventSourceStream.js +0 -11
  93. package/event-source/index.d.ts +0 -3
  94. package/event-source/index.js +0 -3
  95. package/ui/index.d.ts +0 -1
  96. package/ui/index.js +0 -1
  97. /package/{ui → browser}/MediaSourceAppender.cjs +0 -0
  98. /package/{ui → browser}/MediaSourceAppender.d.ts +0 -0
  99. /package/{ui → browser}/MediaSourceAppender.js +0 -0
  100. /package/{event-source → browser}/readEventSourceStream.d.ts +0 -0
  101. /package/{event-source → util/streaming}/EventSourceParserStream.cjs +0 -0
  102. /package/{event-source → util/streaming}/EventSourceParserStream.d.ts +0 -0
  103. /package/{event-source → util/streaming}/EventSourceParserStream.js +0 -0
  104. /package/{event-source → util/streaming}/convertReadableStreamToAsyncIterable.cjs +0 -0
  105. /package/{event-source → util/streaming}/convertReadableStreamToAsyncIterable.d.ts +0 -0
  106. /package/{event-source → util/streaming}/convertReadableStreamToAsyncIterable.js +0 -0
  107. /package/{event-source → util/streaming}/createEventSourceStream.d.ts +0 -0
  108. /package/{event-source → util/streaming}/parseEventSourceStream.cjs +0 -0
  109. /package/{event-source → util/streaming}/parseEventSourceStream.d.ts +0 -0
  110. /package/{event-source → util/streaming}/parseEventSourceStream.js +0 -0
@@ -5,7 +5,7 @@ const zod_1 = require("zod");
5
5
  const callWithRetryAndThrottle_js_1 = require("../../core/api/callWithRetryAndThrottle.cjs");
6
6
  const postToApi_js_1 = require("../../core/api/postToApi.cjs");
7
7
  const AsyncQueue_js_1 = require("../../util/AsyncQueue.cjs");
8
- const parseEventSourceStream_js_1 = require("../../event-source/parseEventSourceStream.cjs");
8
+ const parseEventSourceStream_js_1 = require("../../util/streaming/parseEventSourceStream.cjs");
9
9
  const AbstractModel_js_1 = require("../../model-function/AbstractModel.cjs");
10
10
  const PromptFormatTextStreamingModel_js_1 = require("../../model-function/generate-text/PromptFormatTextStreamingModel.cjs");
11
11
  const parseJSON_js_1 = require("../../util/parseJSON.cjs");
@@ -2,7 +2,7 @@ import { z } from "zod";
2
2
  import { callWithRetryAndThrottle } from "../../core/api/callWithRetryAndThrottle.js";
3
3
  import { createJsonResponseHandler, postJsonToApi, } from "../../core/api/postToApi.js";
4
4
  import { AsyncQueue } from "../../util/AsyncQueue.js";
5
- import { parseEventSourceStream } from "../../event-source/parseEventSourceStream.js";
5
+ import { parseEventSourceStream } from "../../util/streaming/parseEventSourceStream.js";
6
6
  import { AbstractModel } from "../../model-function/AbstractModel.js";
7
7
  import { PromptFormatTextStreamingModel } from "../../model-function/generate-text/PromptFormatTextStreamingModel.js";
8
8
  import { parseJsonWithZod } from "../../util/parseJSON.js";
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OllamaApiConfiguration = void 0;
4
+ const BaseUrlApiConfiguration_js_1 = require("../../core/api/BaseUrlApiConfiguration.cjs");
5
+ class OllamaApiConfiguration extends BaseUrlApiConfiguration_js_1.BaseUrlApiConfiguration {
6
+ constructor({ baseUrl = "http://127.0.0.1:11434", retry, throttle, } = {}) {
7
+ super({
8
+ baseUrl,
9
+ headers: {},
10
+ retry,
11
+ throttle,
12
+ });
13
+ }
14
+ }
15
+ exports.OllamaApiConfiguration = OllamaApiConfiguration;
@@ -0,0 +1,10 @@
1
+ import { BaseUrlApiConfiguration } from "../../core/api/BaseUrlApiConfiguration.js";
2
+ import { RetryFunction } from "../../core/api/RetryFunction.js";
3
+ import { ThrottleFunction } from "../../core/api/ThrottleFunction.js";
4
+ export declare class OllamaApiConfiguration extends BaseUrlApiConfiguration {
5
+ constructor({ baseUrl, retry, throttle, }?: {
6
+ baseUrl?: string;
7
+ retry?: RetryFunction;
8
+ throttle?: ThrottleFunction;
9
+ });
10
+ }
@@ -0,0 +1,11 @@
1
+ import { BaseUrlApiConfiguration } from "../../core/api/BaseUrlApiConfiguration.js";
2
+ export class OllamaApiConfiguration extends BaseUrlApiConfiguration {
3
+ constructor({ baseUrl = "http://127.0.0.1:11434", retry, throttle, } = {}) {
4
+ super({
5
+ baseUrl,
6
+ headers: {},
7
+ retry,
8
+ throttle,
9
+ });
10
+ }
11
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.failedOllamaCallResponseHandler = exports.OllamaError = exports.ollamaErrorDataSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ const ApiCallError_js_1 = require("../../core/api/ApiCallError.cjs");
6
+ const parseJSON_js_1 = require("../../util/parseJSON.cjs");
7
+ exports.ollamaErrorDataSchema = zod_1.z.object({
8
+ error: zod_1.z.string(),
9
+ });
10
+ class OllamaError extends ApiCallError_js_1.ApiCallError {
11
+ constructor({ data, statusCode, url, requestBodyValues, message = data.error, }) {
12
+ super({ message, statusCode, requestBodyValues, url });
13
+ Object.defineProperty(this, "data", {
14
+ enumerable: true,
15
+ configurable: true,
16
+ writable: true,
17
+ value: void 0
18
+ });
19
+ this.data = data;
20
+ }
21
+ }
22
+ exports.OllamaError = OllamaError;
23
+ const failedOllamaCallResponseHandler = async ({ response, url, requestBodyValues }) => new OllamaError({
24
+ url,
25
+ requestBodyValues,
26
+ statusCode: response.status,
27
+ data: (0, parseJSON_js_1.parseJsonWithZod)(await response.text(), exports.ollamaErrorDataSchema),
28
+ });
29
+ exports.failedOllamaCallResponseHandler = failedOllamaCallResponseHandler;
@@ -0,0 +1,22 @@
1
+ import { z } from "zod";
2
+ import { ApiCallError } from "../../core/api/ApiCallError.js";
3
+ import { ResponseHandler } from "../../core/api/postToApi.js";
4
+ export declare const ollamaErrorDataSchema: z.ZodObject<{
5
+ error: z.ZodString;
6
+ }, "strip", z.ZodTypeAny, {
7
+ error: string;
8
+ }, {
9
+ error: string;
10
+ }>;
11
+ export type OllamaErrorData = z.infer<typeof ollamaErrorDataSchema>;
12
+ export declare class OllamaError extends ApiCallError {
13
+ readonly data: OllamaErrorData;
14
+ constructor({ data, statusCode, url, requestBodyValues, message, }: {
15
+ message?: string;
16
+ statusCode: number;
17
+ url: string;
18
+ requestBodyValues: unknown;
19
+ data: OllamaErrorData;
20
+ });
21
+ }
22
+ export declare const failedOllamaCallResponseHandler: ResponseHandler<ApiCallError>;
@@ -0,0 +1,24 @@
1
+ import { z } from "zod";
2
+ import { ApiCallError } from "../../core/api/ApiCallError.js";
3
+ import { parseJsonWithZod } from "../../util/parseJSON.js";
4
+ export const ollamaErrorDataSchema = z.object({
5
+ error: z.string(),
6
+ });
7
+ export class OllamaError extends ApiCallError {
8
+ constructor({ data, statusCode, url, requestBodyValues, message = data.error, }) {
9
+ super({ message, statusCode, requestBodyValues, url });
10
+ Object.defineProperty(this, "data", {
11
+ enumerable: true,
12
+ configurable: true,
13
+ writable: true,
14
+ value: void 0
15
+ });
16
+ this.data = data;
17
+ }
18
+ }
19
+ export const failedOllamaCallResponseHandler = async ({ response, url, requestBodyValues }) => new OllamaError({
20
+ url,
21
+ requestBodyValues,
22
+ statusCode: response.status,
23
+ data: parseJsonWithZod(await response.text(), ollamaErrorDataSchema),
24
+ });
@@ -0,0 +1,216 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OllamaTextGenerationResponseFormat = exports.OllamaTextGenerationModel = void 0;
4
+ const zod_1 = require("zod");
5
+ const callWithRetryAndThrottle_js_1 = require("../../core/api/callWithRetryAndThrottle.cjs");
6
+ const postToApi_js_1 = require("../../core/api/postToApi.cjs");
7
+ const AbstractModel_js_1 = require("../../model-function/AbstractModel.cjs");
8
+ const PromptFormatTextStreamingModel_js_1 = require("../../model-function/generate-text/PromptFormatTextStreamingModel.cjs");
9
+ const AsyncQueue_js_1 = require("../../util/AsyncQueue.cjs");
10
+ const parseJsonStream_js_1 = require("../../util/streaming/parseJsonStream.cjs");
11
+ const OllamaApiConfiguration_js_1 = require("./OllamaApiConfiguration.cjs");
12
+ const OllamaError_js_1 = require("./OllamaError.cjs");
13
+ class OllamaTextGenerationModel extends AbstractModel_js_1.AbstractModel {
14
+ constructor(settings) {
15
+ super({ settings });
16
+ Object.defineProperty(this, "provider", {
17
+ enumerable: true,
18
+ configurable: true,
19
+ writable: true,
20
+ value: "ollama"
21
+ });
22
+ Object.defineProperty(this, "tokenizer", {
23
+ enumerable: true,
24
+ configurable: true,
25
+ writable: true,
26
+ value: undefined
27
+ });
28
+ Object.defineProperty(this, "countPromptTokens", {
29
+ enumerable: true,
30
+ configurable: true,
31
+ writable: true,
32
+ value: undefined
33
+ });
34
+ }
35
+ get modelName() {
36
+ return this.settings.model;
37
+ }
38
+ get contextWindowSize() {
39
+ return this.settings.contextWindowSize;
40
+ }
41
+ async callAPI(prompt, options) {
42
+ return (0, callWithRetryAndThrottle_js_1.callWithRetryAndThrottle)({
43
+ retry: this.settings.api?.retry,
44
+ throttle: this.settings.api?.throttle,
45
+ call: async () => callOllamaTextGenerationAPI({
46
+ ...this.settings,
47
+ // other
48
+ abortSignal: options.run?.abortSignal,
49
+ prompt,
50
+ responseFormat: options.responseFormat,
51
+ }),
52
+ });
53
+ }
54
+ get settingsForEvent() {
55
+ const eventSettingProperties = [
56
+ // "maxCompletionTokens",
57
+ // "stopSequences",
58
+ "contextWindowSize",
59
+ ];
60
+ return Object.fromEntries(Object.entries(this.settings).filter(([key]) => eventSettingProperties.includes(key)));
61
+ }
62
+ async doGenerateText(prompt, options) {
63
+ const response = await this.callAPI(prompt, {
64
+ ...options,
65
+ responseFormat: exports.OllamaTextGenerationResponseFormat.json,
66
+ });
67
+ return {
68
+ response,
69
+ text: response.response,
70
+ };
71
+ }
72
+ doStreamText(prompt, options) {
73
+ return this.callAPI(prompt, {
74
+ ...options,
75
+ responseFormat: exports.OllamaTextGenerationResponseFormat.deltaIterable,
76
+ });
77
+ }
78
+ withPromptFormat(promptFormat) {
79
+ return new PromptFormatTextStreamingModel_js_1.PromptFormatTextStreamingModel({
80
+ model: this.withSettings({
81
+ stopSequences: [
82
+ ...(this.settings.stopSequences ?? []),
83
+ ...promptFormat.stopSequences,
84
+ ],
85
+ }),
86
+ promptFormat,
87
+ });
88
+ }
89
+ withSettings(additionalSettings) {
90
+ return new OllamaTextGenerationModel(Object.assign({}, this.settings, additionalSettings));
91
+ }
92
+ }
93
+ exports.OllamaTextGenerationModel = OllamaTextGenerationModel;
94
+ const ollamaTextGenerationResponseSchema = zod_1.z.object({
95
+ done: zod_1.z.literal(true),
96
+ model: zod_1.z.string(),
97
+ response: zod_1.z.string(),
98
+ total_duration: zod_1.z.number(),
99
+ load_duration: zod_1.z.number(),
100
+ prompt_eval_count: zod_1.z.number(),
101
+ eval_count: zod_1.z.number(),
102
+ eval_duration: zod_1.z.number(),
103
+ context: zod_1.z.array(zod_1.z.number()),
104
+ });
105
+ const ollamaTextStreamingResponseSchema = zod_1.z.discriminatedUnion("done", [
106
+ zod_1.z.object({
107
+ done: zod_1.z.literal(false),
108
+ model: zod_1.z.string(),
109
+ created_at: zod_1.z.string(),
110
+ response: zod_1.z.string(),
111
+ }),
112
+ zod_1.z.object({
113
+ done: zod_1.z.literal(true),
114
+ model: zod_1.z.string(),
115
+ created_at: zod_1.z.string(),
116
+ total_duration: zod_1.z.number(),
117
+ load_duration: zod_1.z.number(),
118
+ sample_count: zod_1.z.number().optional(),
119
+ sample_duration: zod_1.z.number().optional(),
120
+ prompt_eval_count: zod_1.z.number(),
121
+ prompt_eval_duration: zod_1.z.number().optional(),
122
+ eval_count: zod_1.z.number(),
123
+ eval_duration: zod_1.z.number(),
124
+ context: zod_1.z.array(zod_1.z.number()),
125
+ }),
126
+ ]);
127
+ async function callOllamaTextGenerationAPI({ api = new OllamaApiConfiguration_js_1.OllamaApiConfiguration(), abortSignal, responseFormat, prompt, model, contextWindowSize, maxCompletionTokens, mirostat, mirostat_eta, mirostat_tau, num_gpu, num_gqa, num_threads, repeat_last_n, repeat_penalty, seed, stopSequences, temperature, tfs_z, top_k, top_p, system, template, context, }) {
128
+ return (0, postToApi_js_1.postJsonToApi)({
129
+ url: api.assembleUrl(`/api/generate`),
130
+ headers: api.headers,
131
+ body: {
132
+ stream: responseFormat.stream,
133
+ model,
134
+ prompt,
135
+ options: {
136
+ mirostat,
137
+ mirostat_eta,
138
+ mirostat_tau,
139
+ num_ctx: contextWindowSize,
140
+ num_gpu,
141
+ num_gqa,
142
+ num_predict: maxCompletionTokens,
143
+ num_threads,
144
+ repeat_last_n,
145
+ repeat_penalty,
146
+ seed,
147
+ stop: stopSequences,
148
+ temperature,
149
+ tfs_z,
150
+ top_k,
151
+ top_p,
152
+ },
153
+ system,
154
+ template,
155
+ context,
156
+ },
157
+ failedResponseHandler: OllamaError_js_1.failedOllamaCallResponseHandler,
158
+ successfulResponseHandler: responseFormat.handler,
159
+ abortSignal,
160
+ });
161
+ }
162
+ async function createOllamaFullDeltaIterableQueue(stream) {
163
+ const queue = new AsyncQueue_js_1.AsyncQueue();
164
+ let accumulatedText = "";
165
+ // process the stream asynchonously (no 'await' on purpose):
166
+ (0, parseJsonStream_js_1.parseJsonStream)({
167
+ stream,
168
+ schema: ollamaTextStreamingResponseSchema,
169
+ process(event) {
170
+ if (event.done === true) {
171
+ queue.push({
172
+ type: "delta",
173
+ fullDelta: {
174
+ content: accumulatedText,
175
+ isComplete: true,
176
+ delta: "",
177
+ },
178
+ valueDelta: "",
179
+ });
180
+ }
181
+ else {
182
+ accumulatedText += event.response;
183
+ queue.push({
184
+ type: "delta",
185
+ fullDelta: {
186
+ content: accumulatedText,
187
+ isComplete: false,
188
+ delta: event.response,
189
+ },
190
+ valueDelta: event.response,
191
+ });
192
+ }
193
+ },
194
+ onDone() {
195
+ queue.close();
196
+ },
197
+ });
198
+ return queue;
199
+ }
200
+ exports.OllamaTextGenerationResponseFormat = {
201
+ /**
202
+ * Returns the response as a JSON object.
203
+ */
204
+ json: {
205
+ stream: false,
206
+ handler: (0, postToApi_js_1.createJsonResponseHandler)(ollamaTextGenerationResponseSchema),
207
+ },
208
+ /**
209
+ * Returns an async iterable over the full deltas (all choices, including full current state at time of event)
210
+ * of the response stream.
211
+ */
212
+ deltaIterable: {
213
+ stream: true,
214
+ handler: async ({ response }) => createOllamaFullDeltaIterableQueue(response.body),
215
+ },
216
+ };
@@ -0,0 +1,134 @@
1
+ import { z } from "zod";
2
+ import { FunctionOptions } from "../../core/FunctionOptions.js";
3
+ import { ApiConfiguration } from "../../core/api/ApiConfiguration.js";
4
+ import { ResponseHandler } from "../../core/api/postToApi.js";
5
+ import { AbstractModel } from "../../model-function/AbstractModel.js";
6
+ import { Delta } from "../../model-function/Delta.js";
7
+ import { PromptFormatTextStreamingModel } from "../../model-function/generate-text/PromptFormatTextStreamingModel.js";
8
+ import { TextGenerationModelSettings, TextStreamingModel } from "../../model-function/generate-text/TextGenerationModel.js";
9
+ import { TextGenerationPromptFormat } from "../../model-function/generate-text/TextGenerationPromptFormat.js";
10
+ export interface OllamaTextGenerationModelSettings<CONTEXT_WINDOW_SIZE extends number | undefined> extends TextGenerationModelSettings {
11
+ api?: ApiConfiguration;
12
+ model: string;
13
+ temperature?: number;
14
+ /**
15
+ * Specify the context window size of the model that you have loaded in your
16
+ * Ollama server.
17
+ */
18
+ contextWindowSize?: CONTEXT_WINDOW_SIZE;
19
+ mirostat?: number;
20
+ mirostat_eta?: number;
21
+ mirostat_tau?: number;
22
+ num_gqa?: number;
23
+ num_gpu?: number;
24
+ num_threads?: number;
25
+ repeat_last_n?: number;
26
+ repeat_penalty?: number;
27
+ seed?: number;
28
+ tfs_z?: number;
29
+ top_k?: number;
30
+ top_p?: number;
31
+ system?: string;
32
+ template?: string;
33
+ context?: number[];
34
+ }
35
+ export declare class OllamaTextGenerationModel<CONTEXT_WINDOW_SIZE extends number | undefined> extends AbstractModel<OllamaTextGenerationModelSettings<CONTEXT_WINDOW_SIZE>> implements TextStreamingModel<string, OllamaTextGenerationModelSettings<CONTEXT_WINDOW_SIZE>> {
36
+ constructor(settings: OllamaTextGenerationModelSettings<CONTEXT_WINDOW_SIZE>);
37
+ readonly provider = "ollama";
38
+ get modelName(): string;
39
+ readonly tokenizer: undefined;
40
+ readonly countPromptTokens: undefined;
41
+ get contextWindowSize(): CONTEXT_WINDOW_SIZE;
42
+ callAPI<RESPONSE>(prompt: string, options: {
43
+ responseFormat: OllamaTextGenerationResponseFormatType<RESPONSE>;
44
+ } & FunctionOptions): Promise<RESPONSE>;
45
+ get settingsForEvent(): Partial<OllamaTextGenerationModelSettings<CONTEXT_WINDOW_SIZE>>;
46
+ doGenerateText(prompt: string, options?: FunctionOptions): Promise<{
47
+ response: {
48
+ response: string;
49
+ model: string;
50
+ done: true;
51
+ context: number[];
52
+ total_duration: number;
53
+ load_duration: number;
54
+ prompt_eval_count: number;
55
+ eval_count: number;
56
+ eval_duration: number;
57
+ };
58
+ text: string;
59
+ }>;
60
+ doStreamText(prompt: string, options?: FunctionOptions): Promise<AsyncIterable<Delta<string>>>;
61
+ withPromptFormat<INPUT_PROMPT>(promptFormat: TextGenerationPromptFormat<INPUT_PROMPT, string>): PromptFormatTextStreamingModel<INPUT_PROMPT, string, OllamaTextGenerationModelSettings<CONTEXT_WINDOW_SIZE>, this>;
62
+ withSettings(additionalSettings: Partial<OllamaTextGenerationModelSettings<CONTEXT_WINDOW_SIZE>>): this;
63
+ }
64
+ declare const ollamaTextGenerationResponseSchema: z.ZodObject<{
65
+ done: z.ZodLiteral<true>;
66
+ model: z.ZodString;
67
+ response: z.ZodString;
68
+ total_duration: z.ZodNumber;
69
+ load_duration: z.ZodNumber;
70
+ prompt_eval_count: z.ZodNumber;
71
+ eval_count: z.ZodNumber;
72
+ eval_duration: z.ZodNumber;
73
+ context: z.ZodArray<z.ZodNumber, "many">;
74
+ }, "strip", z.ZodTypeAny, {
75
+ response: string;
76
+ model: string;
77
+ done: true;
78
+ context: number[];
79
+ total_duration: number;
80
+ load_duration: number;
81
+ prompt_eval_count: number;
82
+ eval_count: number;
83
+ eval_duration: number;
84
+ }, {
85
+ response: string;
86
+ model: string;
87
+ done: true;
88
+ context: number[];
89
+ total_duration: number;
90
+ load_duration: number;
91
+ prompt_eval_count: number;
92
+ eval_count: number;
93
+ eval_duration: number;
94
+ }>;
95
+ export type OllamaTextGenerationResponse = z.infer<typeof ollamaTextGenerationResponseSchema>;
96
+ export type OllamaTextGenerationDelta = {
97
+ content: string;
98
+ isComplete: boolean;
99
+ delta: string;
100
+ };
101
+ export type OllamaTextGenerationResponseFormatType<T> = {
102
+ stream: boolean;
103
+ handler: ResponseHandler<T>;
104
+ };
105
+ export declare const OllamaTextGenerationResponseFormat: {
106
+ /**
107
+ * Returns the response as a JSON object.
108
+ */
109
+ json: {
110
+ stream: false;
111
+ handler: ResponseHandler<{
112
+ response: string;
113
+ model: string;
114
+ done: true;
115
+ context: number[];
116
+ total_duration: number;
117
+ load_duration: number;
118
+ prompt_eval_count: number;
119
+ eval_count: number;
120
+ eval_duration: number;
121
+ }>;
122
+ };
123
+ /**
124
+ * Returns an async iterable over the full deltas (all choices, including full current state at time of event)
125
+ * of the response stream.
126
+ */
127
+ deltaIterable: {
128
+ stream: true;
129
+ handler: ({ response }: {
130
+ response: Response;
131
+ }) => Promise<AsyncIterable<Delta<string>>>;
132
+ };
133
+ };
134
+ export {};