modelfusion 0.99.0 → 0.100.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.
- package/README.md +9 -15
- package/guard/fixStructure.cjs +3 -3
- package/guard/fixStructure.d.ts +3 -3
- package/guard/fixStructure.js +3 -3
- package/model-function/generate-structure/generateStructure.d.ts +2 -2
- package/model-function/generate-structure/streamStructure.d.ts +1 -1
- package/model-provider/mistral/{MistralTextGenerationModel.cjs → MistralChatModel.cjs} +13 -13
- package/model-provider/mistral/{MistralTextGenerationModel.d.ts → MistralChatModel.d.ts} +21 -20
- package/model-provider/mistral/{MistralTextGenerationModel.js → MistralChatModel.js} +11 -11
- package/model-provider/mistral/MistralFacade.cjs +5 -5
- package/model-provider/mistral/MistralFacade.d.ts +3 -2
- package/model-provider/mistral/MistralFacade.js +3 -3
- package/model-provider/mistral/MistralPromptTemplate.d.ts +4 -4
- package/model-provider/mistral/index.cjs +1 -1
- package/model-provider/mistral/index.d.ts +1 -1
- package/model-provider/mistral/index.js +1 -1
- package/model-provider/ollama/OllamaApiConfiguration.d.ts +6 -5
- package/model-provider/ollama/OllamaChatModel.cjs +303 -0
- package/model-provider/ollama/OllamaChatModel.d.ts +171 -0
- package/model-provider/ollama/OllamaChatModel.js +299 -0
- package/model-provider/ollama/OllamaChatPromptTemplate.cjs +76 -0
- package/model-provider/ollama/OllamaChatPromptTemplate.d.ts +20 -0
- package/model-provider/ollama/OllamaChatPromptTemplate.js +69 -0
- package/model-provider/ollama/{OllamaTextGenerationModel.cjs → OllamaCompletionModel.cjs} +13 -11
- package/model-provider/ollama/OllamaCompletionModel.d.ts +159 -0
- package/model-provider/ollama/{OllamaTextGenerationModel.js → OllamaCompletionModel.js} +11 -9
- package/model-provider/ollama/{OllamaTextGenerationModel.test.cjs → OllamaCompletionModel.test.cjs} +3 -3
- package/model-provider/ollama/{OllamaTextGenerationModel.test.js → OllamaCompletionModel.test.js} +3 -3
- package/model-provider/ollama/OllamaFacade.cjs +15 -5
- package/model-provider/ollama/OllamaFacade.d.ts +7 -2
- package/model-provider/ollama/OllamaFacade.js +11 -3
- package/model-provider/ollama/OllamaTextGenerationSettings.cjs +2 -0
- package/model-provider/ollama/OllamaTextGenerationSettings.d.ts +87 -0
- package/model-provider/ollama/OllamaTextGenerationSettings.js +1 -0
- package/model-provider/ollama/index.cjs +4 -1
- package/model-provider/ollama/index.d.ts +4 -1
- package/model-provider/ollama/index.js +4 -1
- package/model-provider/openai/OpenAIFacade.cjs +4 -2
- package/model-provider/openai/OpenAIFacade.d.ts +3 -1
- package/model-provider/openai/OpenAIFacade.js +2 -1
- package/model-provider/openai/chat/AbstractOpenAIChatModel.d.ts +1 -1
- package/model-provider/openai/chat/OpenAIChatFunctionCallStructureGenerationModel.d.ts +3 -3
- package/model-provider/openai/chat/OpenAIChatModel.cjs +1 -1
- package/model-provider/openai/chat/OpenAIChatModel.d.ts +2 -2
- package/model-provider/openai/chat/OpenAIChatModel.js +1 -1
- package/model-provider/openai/chat/OpenAIChatPromptTemplate.d.ts +5 -5
- package/model-provider/openai/chat/OpenAIChatPromptTemplate.js +1 -1
- package/model-provider/openai-compatible/OpenAICompatibleFacade.cjs +1 -1
- package/model-provider/openai-compatible/OpenAICompatibleFacade.d.ts +1 -1
- package/model-provider/openai-compatible/OpenAICompatibleFacade.js +1 -1
- package/package.json +1 -1
- package/model-provider/ollama/OllamaTextGenerationModel.d.ts +0 -230
- /package/model-provider/ollama/{OllamaTextGenerationModel.test.d.ts → OllamaCompletionModel.test.d.ts} +0 -0
@@ -0,0 +1,303 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.OllamaChatResponseFormat = exports.OllamaChatModel = void 0;
|
4
|
+
const zod_1 = require("zod");
|
5
|
+
const ApiCallError_js_1 = require("../../core/api/ApiCallError.cjs");
|
6
|
+
const callWithRetryAndThrottle_js_1 = require("../../core/api/callWithRetryAndThrottle.cjs");
|
7
|
+
const postToApi_js_1 = require("../../core/api/postToApi.cjs");
|
8
|
+
const ZodSchema_js_1 = require("../../core/schema/ZodSchema.cjs");
|
9
|
+
const parseJSON_js_1 = require("../../core/schema/parseJSON.cjs");
|
10
|
+
const AbstractModel_js_1 = require("../../model-function/AbstractModel.cjs");
|
11
|
+
const PromptTemplateTextStreamingModel_js_1 = require("../../model-function/generate-text/PromptTemplateTextStreamingModel.cjs");
|
12
|
+
const TextGenerationToolCallModel_js_1 = require("../../tool/generate-tool-call/TextGenerationToolCallModel.cjs");
|
13
|
+
const TextGenerationToolCallsOrGenerateTextModel_js_1 = require("../../tool/generate-tool-calls-or-text/TextGenerationToolCallsOrGenerateTextModel.cjs");
|
14
|
+
const AsyncQueue_js_1 = require("../../util/AsyncQueue.cjs");
|
15
|
+
const parseJsonStream_js_1 = require("../../util/streaming/parseJsonStream.cjs");
|
16
|
+
const OllamaApiConfiguration_js_1 = require("./OllamaApiConfiguration.cjs");
|
17
|
+
const OllamaChatPromptTemplate_js_1 = require("./OllamaChatPromptTemplate.cjs");
|
18
|
+
const OllamaError_js_1 = require("./OllamaError.cjs");
|
19
|
+
/**
|
20
|
+
* Text generation model that uses the Ollama chat API.
|
21
|
+
*/
|
22
|
+
class OllamaChatModel extends AbstractModel_js_1.AbstractModel {
|
23
|
+
constructor(settings) {
|
24
|
+
super({ settings });
|
25
|
+
Object.defineProperty(this, "provider", {
|
26
|
+
enumerable: true,
|
27
|
+
configurable: true,
|
28
|
+
writable: true,
|
29
|
+
value: "ollama"
|
30
|
+
});
|
31
|
+
Object.defineProperty(this, "tokenizer", {
|
32
|
+
enumerable: true,
|
33
|
+
configurable: true,
|
34
|
+
writable: true,
|
35
|
+
value: undefined
|
36
|
+
});
|
37
|
+
Object.defineProperty(this, "countPromptTokens", {
|
38
|
+
enumerable: true,
|
39
|
+
configurable: true,
|
40
|
+
writable: true,
|
41
|
+
value: undefined
|
42
|
+
});
|
43
|
+
Object.defineProperty(this, "contextWindowSize", {
|
44
|
+
enumerable: true,
|
45
|
+
configurable: true,
|
46
|
+
writable: true,
|
47
|
+
value: undefined
|
48
|
+
});
|
49
|
+
}
|
50
|
+
get modelName() {
|
51
|
+
return this.settings.model;
|
52
|
+
}
|
53
|
+
async callAPI(prompt, options) {
|
54
|
+
const { responseFormat } = options;
|
55
|
+
const api = this.settings.api ?? new OllamaApiConfiguration_js_1.OllamaApiConfiguration();
|
56
|
+
const abortSignal = options.run?.abortSignal;
|
57
|
+
return (0, callWithRetryAndThrottle_js_1.callWithRetryAndThrottle)({
|
58
|
+
retry: api.retry,
|
59
|
+
throttle: api.throttle,
|
60
|
+
call: async () => (0, postToApi_js_1.postJsonToApi)({
|
61
|
+
url: api.assembleUrl(`/api/chat`),
|
62
|
+
headers: api.headers,
|
63
|
+
body: {
|
64
|
+
stream: responseFormat.stream,
|
65
|
+
model: this.settings.model,
|
66
|
+
messages: prompt,
|
67
|
+
format: this.settings.format,
|
68
|
+
options: {
|
69
|
+
mirostat: this.settings.mirostat,
|
70
|
+
mirostat_eta: this.settings.mirostatEta,
|
71
|
+
mirostat_tau: this.settings.mirostatTau,
|
72
|
+
num_gpu: this.settings.numGpu,
|
73
|
+
num_gqa: this.settings.numGqa,
|
74
|
+
num_predict: this.settings.maxGenerationTokens,
|
75
|
+
num_threads: this.settings.numThreads,
|
76
|
+
repeat_last_n: this.settings.repeatLastN,
|
77
|
+
repeat_penalty: this.settings.repeatPenalty,
|
78
|
+
seed: this.settings.seed,
|
79
|
+
stop: this.settings.stopSequences,
|
80
|
+
temperature: this.settings.temperature,
|
81
|
+
tfs_z: this.settings.tfsZ,
|
82
|
+
top_k: this.settings.topK,
|
83
|
+
top_p: this.settings.topP,
|
84
|
+
},
|
85
|
+
template: this.settings.template,
|
86
|
+
},
|
87
|
+
failedResponseHandler: OllamaError_js_1.failedOllamaCallResponseHandler,
|
88
|
+
successfulResponseHandler: responseFormat.handler,
|
89
|
+
abortSignal,
|
90
|
+
}),
|
91
|
+
});
|
92
|
+
}
|
93
|
+
get settingsForEvent() {
|
94
|
+
const eventSettingProperties = [
|
95
|
+
"maxGenerationTokens",
|
96
|
+
"stopSequences",
|
97
|
+
"temperature",
|
98
|
+
"mirostat",
|
99
|
+
"mirostatEta",
|
100
|
+
"mirostatTau",
|
101
|
+
"numGqa",
|
102
|
+
"numGpu",
|
103
|
+
"numThreads",
|
104
|
+
"repeatLastN",
|
105
|
+
"repeatPenalty",
|
106
|
+
"seed",
|
107
|
+
"tfsZ",
|
108
|
+
"topK",
|
109
|
+
"topP",
|
110
|
+
"template",
|
111
|
+
"format",
|
112
|
+
];
|
113
|
+
return Object.fromEntries(Object.entries(this.settings).filter(([key]) => eventSettingProperties.includes(key)));
|
114
|
+
}
|
115
|
+
async doGenerateTexts(prompt, options) {
|
116
|
+
const response = await this.callAPI(prompt, {
|
117
|
+
...options,
|
118
|
+
responseFormat: exports.OllamaChatResponseFormat.json,
|
119
|
+
});
|
120
|
+
return {
|
121
|
+
response,
|
122
|
+
texts: [response.message.content],
|
123
|
+
};
|
124
|
+
}
|
125
|
+
doStreamText(prompt, options) {
|
126
|
+
return this.callAPI(prompt, {
|
127
|
+
...options,
|
128
|
+
responseFormat: exports.OllamaChatResponseFormat.deltaIterable,
|
129
|
+
});
|
130
|
+
}
|
131
|
+
asToolCallGenerationModel(promptTemplate) {
|
132
|
+
return new TextGenerationToolCallModel_js_1.TextGenerationToolCallModel({
|
133
|
+
model: this,
|
134
|
+
format: promptTemplate,
|
135
|
+
});
|
136
|
+
}
|
137
|
+
asToolCallsOrTextGenerationModel(promptTemplate) {
|
138
|
+
return new TextGenerationToolCallsOrGenerateTextModel_js_1.TextGenerationToolCallsOrGenerateTextModel({
|
139
|
+
model: this,
|
140
|
+
template: promptTemplate,
|
141
|
+
});
|
142
|
+
}
|
143
|
+
/**
|
144
|
+
* Returns this model with a text prompt template.
|
145
|
+
*/
|
146
|
+
withTextPrompt() {
|
147
|
+
return this.withPromptTemplate((0, OllamaChatPromptTemplate_js_1.text)());
|
148
|
+
}
|
149
|
+
/**
|
150
|
+
* Returns this model with an instruction prompt template.
|
151
|
+
*/
|
152
|
+
withInstructionPrompt() {
|
153
|
+
return this.withPromptTemplate((0, OllamaChatPromptTemplate_js_1.instruction)());
|
154
|
+
}
|
155
|
+
/**
|
156
|
+
* Returns this model with a chat prompt template.
|
157
|
+
*/
|
158
|
+
withChatPrompt() {
|
159
|
+
return this.withPromptTemplate((0, OllamaChatPromptTemplate_js_1.chat)());
|
160
|
+
}
|
161
|
+
withPromptTemplate(promptTemplate) {
|
162
|
+
return new PromptTemplateTextStreamingModel_js_1.PromptTemplateTextStreamingModel({
|
163
|
+
model: this.withSettings({
|
164
|
+
stopSequences: [
|
165
|
+
...(this.settings.stopSequences ?? []),
|
166
|
+
...promptTemplate.stopSequences,
|
167
|
+
],
|
168
|
+
}),
|
169
|
+
promptTemplate,
|
170
|
+
});
|
171
|
+
}
|
172
|
+
withSettings(additionalSettings) {
|
173
|
+
return new OllamaChatModel(Object.assign({}, this.settings, additionalSettings));
|
174
|
+
}
|
175
|
+
}
|
176
|
+
exports.OllamaChatModel = OllamaChatModel;
|
177
|
+
const ollamaChatResponseSchema = zod_1.z.object({
|
178
|
+
model: zod_1.z.string(),
|
179
|
+
created_at: zod_1.z.string(),
|
180
|
+
done: zod_1.z.literal(true),
|
181
|
+
message: zod_1.z.object({
|
182
|
+
role: zod_1.z.string(),
|
183
|
+
content: zod_1.z.string(),
|
184
|
+
}),
|
185
|
+
total_duration: zod_1.z.number(),
|
186
|
+
load_duration: zod_1.z.number().optional(),
|
187
|
+
prompt_eval_count: zod_1.z.number(),
|
188
|
+
prompt_eval_duration: zod_1.z.number().optional(),
|
189
|
+
eval_count: zod_1.z.number(),
|
190
|
+
eval_duration: zod_1.z.number(),
|
191
|
+
});
|
192
|
+
const ollamaChatStreamSchema = new ZodSchema_js_1.ZodSchema(zod_1.z.discriminatedUnion("done", [
|
193
|
+
zod_1.z.object({
|
194
|
+
done: zod_1.z.literal(false),
|
195
|
+
model: zod_1.z.string(),
|
196
|
+
created_at: zod_1.z.string(),
|
197
|
+
message: zod_1.z.object({
|
198
|
+
role: zod_1.z.string(),
|
199
|
+
content: zod_1.z.string(),
|
200
|
+
}),
|
201
|
+
}),
|
202
|
+
zod_1.z.object({
|
203
|
+
done: zod_1.z.literal(true),
|
204
|
+
model: zod_1.z.string(),
|
205
|
+
created_at: zod_1.z.string(),
|
206
|
+
total_duration: zod_1.z.number(),
|
207
|
+
load_duration: zod_1.z.number().optional(),
|
208
|
+
prompt_eval_count: zod_1.z.number(),
|
209
|
+
prompt_eval_duration: zod_1.z.number().optional(),
|
210
|
+
eval_count: zod_1.z.number(),
|
211
|
+
eval_duration: zod_1.z.number(),
|
212
|
+
}),
|
213
|
+
]));
|
214
|
+
async function createOllamaFullDeltaIterableQueue(stream) {
|
215
|
+
const queue = new AsyncQueue_js_1.AsyncQueue();
|
216
|
+
let accumulatedText = "";
|
217
|
+
// process the stream asynchonously (no 'await' on purpose):
|
218
|
+
(0, parseJsonStream_js_1.parseJsonStream)({
|
219
|
+
stream,
|
220
|
+
schema: ollamaChatStreamSchema,
|
221
|
+
process(event) {
|
222
|
+
if (event.done === true) {
|
223
|
+
queue.push({
|
224
|
+
type: "delta",
|
225
|
+
fullDelta: {
|
226
|
+
content: accumulatedText,
|
227
|
+
isComplete: true,
|
228
|
+
delta: "",
|
229
|
+
},
|
230
|
+
valueDelta: "",
|
231
|
+
});
|
232
|
+
}
|
233
|
+
else {
|
234
|
+
const deltaText = event.message.content;
|
235
|
+
accumulatedText += deltaText;
|
236
|
+
queue.push({
|
237
|
+
type: "delta",
|
238
|
+
fullDelta: {
|
239
|
+
content: accumulatedText,
|
240
|
+
isComplete: false,
|
241
|
+
delta: deltaText,
|
242
|
+
},
|
243
|
+
valueDelta: deltaText,
|
244
|
+
});
|
245
|
+
}
|
246
|
+
},
|
247
|
+
onDone() {
|
248
|
+
queue.close();
|
249
|
+
},
|
250
|
+
});
|
251
|
+
return queue;
|
252
|
+
}
|
253
|
+
exports.OllamaChatResponseFormat = {
|
254
|
+
/**
|
255
|
+
* Returns the response as a JSON object.
|
256
|
+
*/
|
257
|
+
json: {
|
258
|
+
stream: false,
|
259
|
+
handler: (async ({ response, url, requestBodyValues }) => {
|
260
|
+
const responseBody = await response.text();
|
261
|
+
const parsedResult = (0, parseJSON_js_1.safeParseJSON)({
|
262
|
+
text: responseBody,
|
263
|
+
schema: new ZodSchema_js_1.ZodSchema(zod_1.z.union([
|
264
|
+
ollamaChatResponseSchema,
|
265
|
+
zod_1.z.object({
|
266
|
+
done: zod_1.z.literal(false),
|
267
|
+
model: zod_1.z.string(),
|
268
|
+
created_at: zod_1.z.string(),
|
269
|
+
}),
|
270
|
+
])),
|
271
|
+
});
|
272
|
+
if (!parsedResult.success) {
|
273
|
+
throw new ApiCallError_js_1.ApiCallError({
|
274
|
+
message: "Invalid JSON response",
|
275
|
+
cause: parsedResult.error,
|
276
|
+
statusCode: response.status,
|
277
|
+
responseBody,
|
278
|
+
url,
|
279
|
+
requestBodyValues,
|
280
|
+
});
|
281
|
+
}
|
282
|
+
if (parsedResult.data.done === false) {
|
283
|
+
throw new ApiCallError_js_1.ApiCallError({
|
284
|
+
message: "Incomplete Ollama response received",
|
285
|
+
statusCode: response.status,
|
286
|
+
responseBody,
|
287
|
+
url,
|
288
|
+
requestBodyValues,
|
289
|
+
isRetryable: true,
|
290
|
+
});
|
291
|
+
}
|
292
|
+
return parsedResult.data;
|
293
|
+
}),
|
294
|
+
},
|
295
|
+
/**
|
296
|
+
* Returns an async iterable over the full deltas (all choices, including full current state at time of event)
|
297
|
+
* of the response stream.
|
298
|
+
*/
|
299
|
+
deltaIterable: {
|
300
|
+
stream: true,
|
301
|
+
handler: async ({ response }) => createOllamaFullDeltaIterableQueue(response.body),
|
302
|
+
},
|
303
|
+
};
|
@@ -0,0 +1,171 @@
|
|
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 { PromptTemplateTextStreamingModel } from "../../model-function/generate-text/PromptTemplateTextStreamingModel.js";
|
8
|
+
import { TextStreamingModel } from "../../model-function/generate-text/TextGenerationModel.js";
|
9
|
+
import { TextGenerationPromptTemplate } from "../../model-function/generate-text/TextGenerationPromptTemplate.js";
|
10
|
+
import { TextGenerationToolCallModel, ToolCallPromptTemplate } from "../../tool/generate-tool-call/TextGenerationToolCallModel.js";
|
11
|
+
import { TextGenerationToolCallsOrGenerateTextModel, ToolCallsOrGenerateTextPromptTemplate } from "../../tool/generate-tool-calls-or-text/TextGenerationToolCallsOrGenerateTextModel.js";
|
12
|
+
import { OllamaTextGenerationSettings } from "./OllamaTextGenerationSettings.js";
|
13
|
+
export type OllamaChatMessage = {
|
14
|
+
role: "system" | "user" | "assistant";
|
15
|
+
content: string;
|
16
|
+
/**
|
17
|
+
Images. Supports base64-encoded `png` and `jpeg` images up to 100MB in size.
|
18
|
+
*/
|
19
|
+
images?: Array<string>;
|
20
|
+
};
|
21
|
+
export type OllamaChatPrompt = Array<OllamaChatMessage>;
|
22
|
+
export interface OllamaChatModelSettings extends OllamaTextGenerationSettings {
|
23
|
+
api?: ApiConfiguration;
|
24
|
+
}
|
25
|
+
/**
|
26
|
+
* Text generation model that uses the Ollama chat API.
|
27
|
+
*/
|
28
|
+
export declare class OllamaChatModel extends AbstractModel<OllamaChatModelSettings> implements TextStreamingModel<OllamaChatPrompt, OllamaChatModelSettings> {
|
29
|
+
constructor(settings: OllamaChatModelSettings);
|
30
|
+
readonly provider = "ollama";
|
31
|
+
get modelName(): string;
|
32
|
+
readonly tokenizer: undefined;
|
33
|
+
readonly countPromptTokens: undefined;
|
34
|
+
readonly contextWindowSize: undefined;
|
35
|
+
callAPI<RESPONSE>(prompt: OllamaChatPrompt, options: {
|
36
|
+
responseFormat: OllamaChatResponseFormatType<RESPONSE>;
|
37
|
+
} & FunctionOptions): Promise<RESPONSE>;
|
38
|
+
get settingsForEvent(): Partial<OllamaChatModelSettings>;
|
39
|
+
doGenerateTexts(prompt: OllamaChatPrompt, options?: FunctionOptions): Promise<{
|
40
|
+
response: {
|
41
|
+
model: string;
|
42
|
+
message: {
|
43
|
+
role: string;
|
44
|
+
content: string;
|
45
|
+
};
|
46
|
+
done: true;
|
47
|
+
created_at: string;
|
48
|
+
total_duration: number;
|
49
|
+
prompt_eval_count: number;
|
50
|
+
eval_count: number;
|
51
|
+
eval_duration: number;
|
52
|
+
load_duration?: number | undefined;
|
53
|
+
prompt_eval_duration?: number | undefined;
|
54
|
+
};
|
55
|
+
texts: string[];
|
56
|
+
}>;
|
57
|
+
doStreamText(prompt: OllamaChatPrompt, options?: FunctionOptions): Promise<AsyncIterable<Delta<string>>>;
|
58
|
+
asToolCallGenerationModel<INPUT_PROMPT>(promptTemplate: ToolCallPromptTemplate<INPUT_PROMPT, OllamaChatPrompt>): TextGenerationToolCallModel<INPUT_PROMPT, OllamaChatPrompt, this>;
|
59
|
+
asToolCallsOrTextGenerationModel<INPUT_PROMPT>(promptTemplate: ToolCallsOrGenerateTextPromptTemplate<INPUT_PROMPT, OllamaChatPrompt>): TextGenerationToolCallsOrGenerateTextModel<INPUT_PROMPT, OllamaChatPrompt, this>;
|
60
|
+
/**
|
61
|
+
* Returns this model with a text prompt template.
|
62
|
+
*/
|
63
|
+
withTextPrompt(): PromptTemplateTextStreamingModel<string, OllamaChatPrompt, OllamaChatModelSettings, this>;
|
64
|
+
/**
|
65
|
+
* Returns this model with an instruction prompt template.
|
66
|
+
*/
|
67
|
+
withInstructionPrompt(): PromptTemplateTextStreamingModel<import("../../index.js").MultiModalInstructionPrompt | import("../../index.js").TextInstructionPrompt, OllamaChatPrompt, OllamaChatModelSettings, this>;
|
68
|
+
/**
|
69
|
+
* Returns this model with a chat prompt template.
|
70
|
+
*/
|
71
|
+
withChatPrompt(): PromptTemplateTextStreamingModel<import("../../index.js").TextChatPrompt | import("../../index.js").MultiModalChatPrompt, OllamaChatPrompt, OllamaChatModelSettings, this>;
|
72
|
+
withPromptTemplate<INPUT_PROMPT>(promptTemplate: TextGenerationPromptTemplate<INPUT_PROMPT, OllamaChatPrompt>): PromptTemplateTextStreamingModel<INPUT_PROMPT, OllamaChatPrompt, OllamaChatModelSettings, this>;
|
73
|
+
withSettings(additionalSettings: Partial<OllamaChatModelSettings>): this;
|
74
|
+
}
|
75
|
+
declare const ollamaChatResponseSchema: z.ZodObject<{
|
76
|
+
model: z.ZodString;
|
77
|
+
created_at: z.ZodString;
|
78
|
+
done: z.ZodLiteral<true>;
|
79
|
+
message: z.ZodObject<{
|
80
|
+
role: z.ZodString;
|
81
|
+
content: z.ZodString;
|
82
|
+
}, "strip", z.ZodTypeAny, {
|
83
|
+
role: string;
|
84
|
+
content: string;
|
85
|
+
}, {
|
86
|
+
role: string;
|
87
|
+
content: string;
|
88
|
+
}>;
|
89
|
+
total_duration: z.ZodNumber;
|
90
|
+
load_duration: z.ZodOptional<z.ZodNumber>;
|
91
|
+
prompt_eval_count: z.ZodNumber;
|
92
|
+
prompt_eval_duration: z.ZodOptional<z.ZodNumber>;
|
93
|
+
eval_count: z.ZodNumber;
|
94
|
+
eval_duration: z.ZodNumber;
|
95
|
+
}, "strip", z.ZodTypeAny, {
|
96
|
+
model: string;
|
97
|
+
message: {
|
98
|
+
role: string;
|
99
|
+
content: string;
|
100
|
+
};
|
101
|
+
done: true;
|
102
|
+
created_at: string;
|
103
|
+
total_duration: number;
|
104
|
+
prompt_eval_count: number;
|
105
|
+
eval_count: number;
|
106
|
+
eval_duration: number;
|
107
|
+
load_duration?: number | undefined;
|
108
|
+
prompt_eval_duration?: number | undefined;
|
109
|
+
}, {
|
110
|
+
model: string;
|
111
|
+
message: {
|
112
|
+
role: string;
|
113
|
+
content: string;
|
114
|
+
};
|
115
|
+
done: true;
|
116
|
+
created_at: string;
|
117
|
+
total_duration: number;
|
118
|
+
prompt_eval_count: number;
|
119
|
+
eval_count: number;
|
120
|
+
eval_duration: number;
|
121
|
+
load_duration?: number | undefined;
|
122
|
+
prompt_eval_duration?: number | undefined;
|
123
|
+
}>;
|
124
|
+
export type OllamaChatResponse = z.infer<typeof ollamaChatResponseSchema>;
|
125
|
+
export type OllamaChatDelta = {
|
126
|
+
content: string;
|
127
|
+
isComplete: boolean;
|
128
|
+
delta: string;
|
129
|
+
};
|
130
|
+
export type OllamaChatResponseFormatType<T> = {
|
131
|
+
stream: boolean;
|
132
|
+
handler: ResponseHandler<T>;
|
133
|
+
};
|
134
|
+
export declare const OllamaChatResponseFormat: {
|
135
|
+
/**
|
136
|
+
* Returns the response as a JSON object.
|
137
|
+
*/
|
138
|
+
json: {
|
139
|
+
stream: false;
|
140
|
+
handler: ({ response, url, requestBodyValues }: {
|
141
|
+
url: string;
|
142
|
+
requestBodyValues: unknown;
|
143
|
+
response: Response;
|
144
|
+
}) => Promise<{
|
145
|
+
model: string;
|
146
|
+
message: {
|
147
|
+
role: string;
|
148
|
+
content: string;
|
149
|
+
};
|
150
|
+
done: true;
|
151
|
+
created_at: string;
|
152
|
+
total_duration: number;
|
153
|
+
prompt_eval_count: number;
|
154
|
+
eval_count: number;
|
155
|
+
eval_duration: number;
|
156
|
+
load_duration?: number | undefined;
|
157
|
+
prompt_eval_duration?: number | undefined;
|
158
|
+
}>;
|
159
|
+
};
|
160
|
+
/**
|
161
|
+
* Returns an async iterable over the full deltas (all choices, including full current state at time of event)
|
162
|
+
* of the response stream.
|
163
|
+
*/
|
164
|
+
deltaIterable: {
|
165
|
+
stream: true;
|
166
|
+
handler: ({ response }: {
|
167
|
+
response: Response;
|
168
|
+
}) => Promise<AsyncIterable<Delta<string>>>;
|
169
|
+
};
|
170
|
+
};
|
171
|
+
export {};
|