modelfusion 0.136.0 → 0.137.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/CHANGELOG.md ADDED
@@ -0,0 +1,2359 @@
1
+ # Changelog
2
+
3
+ ## v0.137.0 - 2024-02-24
4
+
5
+ ### Changed
6
+
7
+ - Moved cost calculation into `@modelfusion/cost-calculation` package. Thanks [@jakedetels](https://github.com/jakedetels) for the refactoring!
8
+
9
+ ## v0.136.0 - 2024-02-07
10
+
11
+ ### Added
12
+
13
+ - `FileCache` for caching responses to disk. Thanks [@jakedetels](https://github.com/jakedetels) for the feature! Example:
14
+
15
+ ```ts
16
+ import { generateText, openai } from "modelfusion";
17
+ import { FileCache } from "modelfusion/node";
18
+
19
+ const cache = new FileCache();
20
+
21
+ const text1 = await generateText({
22
+ model: openai
23
+ .ChatTextGenerator({ model: "gpt-3.5-turbo", temperature: 1 })
24
+ .withTextPrompt(),
25
+ prompt: "Write a short story about a robot learning to love",
26
+ logging: "basic-text",
27
+ cache,
28
+ });
29
+
30
+ console.log({ text1 });
31
+
32
+ const text2 = await generateText({
33
+ model: openai
34
+ .ChatTextGenerator({ model: "gpt-3.5-turbo", temperature: 1 })
35
+ .withTextPrompt(),
36
+ prompt: "Write a short story about a robot learning to love",
37
+ logging: "basic-text",
38
+ cache,
39
+ });
40
+
41
+ console.log({ text2 }); // same text
42
+ ```
43
+
44
+ ## v0.135.1 - 2024-02-04
45
+
46
+ ### Fixed
47
+
48
+ - Try both dynamic imports and require for loading libraries on demand.
49
+
50
+ ## v0.135.0 - 2024-01-29
51
+
52
+ ### Added
53
+
54
+ - `ObjectGeneratorTool`: a tool to create synthetic or fictional structured data using `generateObject`. [Docs](https://modelfusion.dev/guide/tools/available-tools/object-generator)
55
+ - `jsonToolCallPrompt.instruction()`: Create a instruction prompt for tool calls that uses JSON.
56
+
57
+ ### Changed
58
+
59
+ - `jsonToolCallPrompt` automatically enables JSON mode or grammars when supported by the model.
60
+
61
+ ## v0.134.0 - 2024-01-28
62
+
63
+ ### Added
64
+
65
+ - Added prompt function support to `generateText`, `streamText`, `generateObject`, and `streamObject`. You can create prompt functions for text, instruction, and chat prompts using `createTextPrompt`, `createInstructionPrompt`, and `createChatPrompt`. Prompt functions allow you to load prompts from external sources and improve the prompt logging. Example:
66
+
67
+ ```ts
68
+ const storyPrompt = createInstructionPrompt(
69
+ async ({ protagonist }: { protagonist: string }) => ({
70
+ system: "You are an award-winning author.",
71
+ instruction: `Write a short story about ${protagonist} learning to love.`,
72
+ })
73
+ );
74
+
75
+ const text = await generateText({
76
+ model: openai
77
+ .ChatTextGenerator({ model: "gpt-3.5-turbo" })
78
+ .withInstructionPrompt(),
79
+
80
+ prompt: storyPrompt({
81
+ protagonist: "a robot",
82
+ }),
83
+ });
84
+ ```
85
+
86
+ ### Changed
87
+
88
+ - Refactored build to use `tsup`.
89
+
90
+ ## v0.133.0 - 2024-01-26
91
+
92
+ ### Added
93
+
94
+ - Support for OpenAI embedding custom dimensions.
95
+
96
+ ### Changed
97
+
98
+ - **breaking change**: renamed `embeddingDimensions` setting to `dimensions`
99
+
100
+ ## v0.132.0 - 2024-01-25
101
+
102
+ ### Added
103
+
104
+ - Support for OpenAI `text-embedding-3-small` and `text-embedding-3-large` embedding models.
105
+ - Support for OpenAI `gpt-4-turbo-preview`, `gpt-4-0125-preview`, and `gpt-3.5-turbo-0125` chat models.
106
+
107
+ ## v0.131.1 - 2024-01-25
108
+
109
+ ### Fixed
110
+
111
+ - Add `type-fest` as dependency to fix type inference errors.
112
+
113
+ ## v0.131.0 - 2024-01-23
114
+
115
+ ### Added
116
+
117
+ - `ObjectStreamResponse` and `ObjectStreamFromResponse` serialization functions for using server-generated object streams in web applications.
118
+
119
+ Server example:
120
+
121
+ ```ts
122
+ export async function POST(req: Request) {
123
+ const { myArgs } = await req.json();
124
+
125
+ const objectStream = await streamObject({
126
+ // ...
127
+ });
128
+
129
+ // serialize the object stream to a response:
130
+ return new ObjectStreamResponse(objectStream);
131
+ }
132
+ ```
133
+
134
+ Client example:
135
+
136
+ ```ts
137
+ const response = await fetch("/api/stream-object-openai", {
138
+ method: "POST",
139
+ body: JSON.stringify({ myArgs }),
140
+ });
141
+
142
+ // deserialize (result object is simpler than the full response)
143
+ const stream = ObjectStreamFromResponse({
144
+ schema: itinerarySchema,
145
+ response,
146
+ });
147
+
148
+ for await (const { partialObject } of stream) {
149
+ // do something, e.g. setting a React state
150
+ }
151
+ ```
152
+
153
+ ### Changed
154
+
155
+ - **breaking change**: rename `generateStructure` to `generateObject` and `streamStructure` to `streamObject`. Related names have been changed accordingly.
156
+ - **breaking change**: the `streamObject` result stream contains additional data. You need to use `stream.partialObject` or destructuring to access it:
157
+
158
+ ```ts
159
+ const objectStream = await streamObject({
160
+ // ...
161
+ });
162
+
163
+ for await (const { partialObject } of objectStream) {
164
+ console.clear();
165
+ console.log(partialObject);
166
+ }
167
+ ```
168
+
169
+ - **breaking change**: the result from successful `Schema` validations is stored in the `value` property (before: `data`).
170
+
171
+ ## v0.130.1 - 2024-01-22
172
+
173
+ ### Fixed
174
+
175
+ - Duplex speech streaming works in Vercel Edge Functions.
176
+
177
+ ## v0.130.0 - 2024-01-21
178
+
179
+ ### Changed
180
+
181
+ - **breaking change**: updated `generateTranscription` interface. The function now takes a `mimeType` and `audioData` (base64-encoded string, `Uint8Array`, `Buffer` or `ArrayBuffer`). Example:
182
+
183
+ ```ts
184
+ import { generateTranscription, openai } from "modelfusion";
185
+ import fs from "node:fs";
186
+
187
+ const transcription = await generateTranscription({
188
+ model: openai.Transcriber({ model: "whisper-1" }),
189
+ mimeType: "audio/mp3",
190
+ audioData: await fs.promises.readFile("data/test.mp3"),
191
+ });
192
+ ```
193
+
194
+ - Images in instruction and chat prompts can be `Buffer` or `ArrayBuffer` instances (in addition to base64-encoded strings and `Uint8Array` instances).
195
+
196
+ ## v0.129.0 - 2024-01-20
197
+
198
+ ### Changed
199
+
200
+ - **breaking change**: Usage of Node `async_hooks` has been renamed from `node:async_hooks` to `async_hooks` for easier Webpack configuration. To exclude the `async_hooks` from client-side bundling, you can use the following config for Next.js (`next.config.mjs` or `next.config.js`):
201
+
202
+ ```js
203
+ /**
204
+ * @type {import('next').NextConfig}
205
+ */
206
+ const nextConfig = {
207
+ webpack: (config, { isServer }) => {
208
+ if (isServer) {
209
+ return config;
210
+ }
211
+
212
+ config.resolve = config.resolve ?? {};
213
+ config.resolve.fallback = config.resolve.fallback ?? {};
214
+
215
+ // async hooks is not available in the browser:
216
+ config.resolve.fallback.async_hooks = false;
217
+
218
+ return config;
219
+ },
220
+ };
221
+ ```
222
+
223
+ ## v0.128.0 - 2024-01-20
224
+
225
+ ### Changed
226
+
227
+ - **breaking change**: ModelFusion uses `Uint8Array` instead of `Buffer` for better cross-platform compatibility (see also ["Goodbye, Node.js Buffer"](https://sindresorhus.com/blog/goodbye-nodejs-buffer)). This can lead to breaking changes in your code if you use `Buffer`-specific methods.
228
+ - **breaking change**: Image content in multi-modal instruction and chat inputs (e.g. for GPT Vision) is passed in the `image` property (instead of `base64Image`) and supports both base64 strings and `Uint8Array` inputs:
229
+
230
+ ```ts
231
+ const image = fs.readFileSync(path.join("data", "example-image.png"));
232
+
233
+ const textStream = await streamText({
234
+ model: openai.ChatTextGenerator({
235
+ model: "gpt-4-vision-preview",
236
+ maxGenerationTokens: 1000,
237
+ }),
238
+
239
+ prompt: [
240
+ openai.ChatMessage.user([
241
+ { type: "text", text: "Describe the image in detail:\n\n" },
242
+ { type: "image", image, mimeType: "image/png" },
243
+ ]),
244
+ ],
245
+ });
246
+ ```
247
+
248
+ - OpenAI-compatible providers with predefined API configurations have a customized provider name that shows up in the events.
249
+
250
+ ## v0.127.0 - 2024-01-15
251
+
252
+ ### Changed
253
+
254
+ - **breaking change**: `streamStructure` returns an async iterable over deep partial objects. If you need to get the fully validated final result, you can use the `fullResponse: true` option and await the `structurePromise` value. Example:
255
+
256
+ ```ts
257
+ const { structureStream, structurePromise } = await streamStructure({
258
+ model: ollama
259
+ .ChatTextGenerator({
260
+ model: "openhermes2.5-mistral",
261
+ maxGenerationTokens: 1024,
262
+ temperature: 0,
263
+ })
264
+ .asStructureGenerationModel(jsonStructurePrompt.text()),
265
+
266
+ schema: zodSchema(
267
+ z.object({
268
+ characters: z.array(
269
+ z.object({
270
+ name: z.string(),
271
+ class: z
272
+ .string()
273
+ .describe("Character class, e.g. warrior, mage, or thief."),
274
+ description: z.string(),
275
+ })
276
+ ),
277
+ })
278
+ ),
279
+
280
+ prompt:
281
+ "Generate 3 character descriptions for a fantasy role playing game.",
282
+
283
+ fullResponse: true,
284
+ });
285
+
286
+ for await (const partialStructure of structureStream) {
287
+ console.clear();
288
+ console.log(partialStructure);
289
+ }
290
+
291
+ const structure = await structurePromise;
292
+
293
+ console.clear();
294
+ console.log("FINAL STRUCTURE");
295
+ console.log(structure);
296
+ ```
297
+
298
+ - **breaking change**: Renamed `text` value in `streamText` with `fullResponse: true` to `textPromise`.
299
+
300
+ ### Fixed
301
+
302
+ - Ollama streaming.
303
+ - Ollama structure generation and streaming.
304
+
305
+ ## v0.126.0 - 2024-01-15
306
+
307
+ ### Changed
308
+
309
+ - **breaking change**: rename `useTool` to `runTool` and `useTools` to `runTools` to avoid confusion with React hooks.
310
+
311
+ ## v0.125.0 - 2024-01-14
312
+
313
+ ### Added
314
+
315
+ - Perplexity AI chat completion support. Example:
316
+
317
+ ```ts
318
+ import { openaicompatible, streamText } from "modelfusion";
319
+
320
+ const textStream = await streamText({
321
+ model: openaicompatible
322
+ .ChatTextGenerator({
323
+ api: openaicompatible.PerplexityApi(),
324
+ provider: "openaicompatible-perplexity",
325
+ model: "pplx-70b-online", // online model with access to web search
326
+ maxGenerationTokens: 500,
327
+ })
328
+ .withTextPrompt(),
329
+
330
+ prompt: "What is RAG in AI?",
331
+ });
332
+ ```
333
+
334
+ ## v0.124.0 - 2024-01-13
335
+
336
+ ### Added
337
+
338
+ - [Embedding-support for OpenAI-compatible providers](https://modelfusion.dev/integration/model-provider/openaicompatible/#embed-text). You can for example use the Together AI embedding endpoint:
339
+
340
+ ```ts
341
+ import { embed, openaicompatible } from "modelfusion";
342
+
343
+ const embedding = await embed({
344
+ model: openaicompatible.TextEmbedder({
345
+ api: openaicompatible.TogetherAIApi(),
346
+ provider: "openaicompatible-togetherai",
347
+ model: "togethercomputer/m2-bert-80M-8k-retrieval",
348
+ }),
349
+ value: "At first, Nox didn't know what to do with the pup.",
350
+ });
351
+ ```
352
+
353
+ ## v0.123.0 - 2024-01-13
354
+
355
+ ### Added
356
+
357
+ - `classify` model function ([docs](https://modelfusion.dev/guide/function/classify)) for classifying values. The `SemanticClassifier` has been renamed to `EmbeddingSimilarityClassifier` and can be used in conjunction with `classify`:
358
+
359
+ ```ts
360
+ import { classify, EmbeddingSimilarityClassifier, openai } from "modelfusion";
361
+
362
+ const classifier = new EmbeddingSimilarityClassifier({
363
+ embeddingModel: openai.TextEmbedder({ model: "text-embedding-ada-002" }),
364
+ similarityThreshold: 0.82,
365
+ clusters: [
366
+ {
367
+ name: "politics" as const,
368
+ values: [
369
+ "they will save the country!",
370
+ // ...
371
+ ],
372
+ },
373
+ {
374
+ name: "chitchat" as const,
375
+ values: [
376
+ "how's the weather today?",
377
+ // ...
378
+ ],
379
+ },
380
+ ],
381
+ });
382
+
383
+ // strongly typed result:
384
+ const result = await classify({
385
+ model: classifier,
386
+ value: "don't you love politics?",
387
+ });
388
+ ```
389
+
390
+ ## v0.122.0 - 2024-01-13
391
+
392
+ ### Changed
393
+
394
+ - **breaking change**: Switch from positional parameters to named parameters (parameter object) for all model and tool functions. The parameter object is the first and only parameter of the function. Additional options (last parameter before) are now part of the parameter object. Example:
395
+
396
+ ```ts
397
+ // old:
398
+ const text = await generateText(
399
+ openai
400
+ .ChatTextGenerator({
401
+ model: "gpt-3.5-turbo",
402
+ maxGenerationTokens: 1000,
403
+ })
404
+ .withTextPrompt(),
405
+
406
+ "Write a short story about a robot learning to love",
407
+
408
+ {
409
+ functionId: "example-function",
410
+ }
411
+ );
412
+
413
+ // new:
414
+ const text = await generateText({
415
+ model: openai
416
+ .ChatTextGenerator({
417
+ model: "gpt-3.5-turbo",
418
+ maxGenerationTokens: 1000,
419
+ })
420
+ .withTextPrompt(),
421
+
422
+ prompt: "Write a short story about a robot learning to love",
423
+
424
+ functionId: "example-function",
425
+ });
426
+ ```
427
+
428
+ This change was made to make the API more flexible and to allow for future extensions.
429
+
430
+ ## v0.121.2 - 2024-01-11
431
+
432
+ ### Fixed
433
+
434
+ - Ollama response schema for repeated calls with Ollama 0.1.19 completion models. Thanks [@Necmttn](https://github.com/Necmttn) for the bugfix!
435
+
436
+ ## v0.121.1 - 2024-01-10
437
+
438
+ ### Fixed
439
+
440
+ - Ollama response schema for repeated calls with Ollama 0.1.19 chat models. Thanks [@jakedetels](https://github.com/jakedetels) for the bug report!
441
+
442
+ ## v0.121.0 - 2024-01-09
443
+
444
+ ### Added
445
+
446
+ - Synthia prompt template
447
+
448
+ ### Changed
449
+
450
+ - **breaking change**: Renamed `parentCallId` function parameter to `callId` to enable options pass-through.
451
+ - Better output filtering for `detailed-object` log format (e.g. via `modelfusion.setLogFormat("detailed-object")`)
452
+
453
+ ## v0.120.0 - 2024-01-09
454
+
455
+ ### Added
456
+
457
+ - `OllamaCompletionModel` supports setting the prompt template in the settings. Prompt formats are available under `ollama.prompt.*`. You can then call `.withTextPrompt()`, `.withInstructionPrompt()` or `.withChatPrompt()` to use a standardized prompt.
458
+
459
+ ```ts
460
+ const model = ollama
461
+ .CompletionTextGenerator({
462
+ model: "mistral",
463
+ promptTemplate: ollama.prompt.Mistral,
464
+ raw: true, // required when using custom prompt template
465
+ maxGenerationTokens: 120,
466
+ })
467
+ .withTextPrompt();
468
+ ```
469
+
470
+ ### Removed
471
+
472
+ - **breaking change**: removed `.withTextPromptTemplate` on `OllamaCompletionModel`.
473
+
474
+ ## v0.119.1 - 2024-01-08
475
+
476
+ ### Fixed
477
+
478
+ - Incorrect export. Thanks [@mloenow](https://github.com/mloenow) for the fix!
479
+
480
+ ## v0.119.0 - 2024-01-07
481
+
482
+ ### Added
483
+
484
+ - Schema-specific GBNF grammar generator for `LlamaCppCompletionModel`. When using `jsonStructurePrompt`, it automatically uses a GBNF grammar for the JSON schema that you provide. Example:
485
+
486
+ ```ts
487
+ const structure = await generateStructure(
488
+ llamacpp
489
+ .CompletionTextGenerator({
490
+ // run openhermes-2.5-mistral-7b.Q4_K_M.gguf in llama.cpp
491
+ promptTemplate: llamacpp.prompt.ChatML,
492
+ maxGenerationTokens: 1024,
493
+ temperature: 0,
494
+ })
495
+ // automatically restrict the output to your schema using GBNF:
496
+ .asStructureGenerationModel(jsonStructurePrompt.text()),
497
+
498
+ zodSchema(
499
+ z.array(
500
+ z.object({
501
+ name: z.string(),
502
+ class: z
503
+ .string()
504
+ .describe("Character class, e.g. warrior, mage, or thief."),
505
+ description: z.string(),
506
+ })
507
+ )
508
+ ),
509
+
510
+ "Generate 3 character descriptions for a fantasy role playing game. "
511
+ );
512
+ ```
513
+
514
+ ## v0.118.0 - 2024-01-07
515
+
516
+ ### Added
517
+
518
+ - `LlamaCppCompletionModel` supports setting the prompt template in the settings. Prompt formats are available under `llamacpp.prompt.*`. You can then call `.withTextPrompt()`, `.withInstructionPrompt()` or `.withChatPrompt()` to use a standardized prompt.
519
+
520
+ ```ts
521
+ const model = llamacpp
522
+ .CompletionTextGenerator({
523
+ // run https://huggingface.co/TheBloke/OpenHermes-2.5-Mistral-7B-GGUF with llama.cpp
524
+ promptTemplate: llamacpp.prompt.ChatML,
525
+ contextWindowSize: 4096,
526
+ maxGenerationTokens: 512,
527
+ })
528
+ .withChatPrompt();
529
+ ```
530
+
531
+ ### Changed
532
+
533
+ - **breaking change**: renamed `response` to `rawResponse` when using `fullResponse: true` setting.
534
+ - **breaking change**: renamed `llamacpp.TextGenerator` to `llamacpp.CompletionTextGenerator`.
535
+
536
+ ### Removed
537
+
538
+ - **breaking change**: removed `.withTextPromptTemplate` on `LlamaCppCompletionModel`.
539
+
540
+ ## v0.117.0 - 2024-01-06
541
+
542
+ ### Added
543
+
544
+ - Predefined Llama.cpp GBNF grammars:
545
+
546
+ - `llamacpp.grammar.json`: Restricts the output to JSON.
547
+ - `llamacpp.grammar.jsonArray`: Restricts the output to a JSON array.
548
+ - `llamacpp.grammar.list`: Restricts the output to a newline-separated list where each line starts with `- `.
549
+
550
+ - Llama.cpp structure generation support:
551
+
552
+ ```ts
553
+ const structure = await generateStructure(
554
+ llamacpp
555
+ .TextGenerator({
556
+ // run openhermes-2.5-mistral-7b.Q4_K_M.gguf in llama.cpp
557
+ maxGenerationTokens: 1024,
558
+ temperature: 0,
559
+ })
560
+ .withTextPromptTemplate(ChatMLPrompt.instruction()) // needed for jsonStructurePrompt.text()
561
+ .asStructureGenerationModel(jsonStructurePrompt.text()), // automatically restrict the output to JSON
562
+
563
+ zodSchema(
564
+ z.object({
565
+ characters: z.array(
566
+ z.object({
567
+ name: z.string(),
568
+ class: z
569
+ .string()
570
+ .describe("Character class, e.g. warrior, mage, or thief."),
571
+ description: z.string(),
572
+ })
573
+ ),
574
+ })
575
+ ),
576
+
577
+ "Generate 3 character descriptions for a fantasy role playing game. "
578
+ );
579
+ ```
580
+
581
+ ## v0.116.0 - 2024-01-05
582
+
583
+ ### Added
584
+
585
+ - Semantic classifier. An easy way to determine a class of a text using embeddings. Example:
586
+
587
+ ```ts
588
+ import { SemanticClassifier, openai } from "modelfusion";
589
+
590
+ const classifier = new SemanticClassifier({
591
+ embeddingModel: openai.TextEmbedder({
592
+ model: "text-embedding-ada-002",
593
+ }),
594
+ similarityThreshold: 0.82,
595
+ clusters: [
596
+ {
597
+ name: "politics" as const,
598
+ values: [
599
+ "isn't politics the best thing ever",
600
+ "why don't you tell me about your political opinions",
601
+ "don't you just love the president",
602
+ "don't you just hate the president",
603
+ "they're going to destroy this country!",
604
+ "they will save the country!",
605
+ ],
606
+ },
607
+ {
608
+ name: "chitchat" as const,
609
+ values: [
610
+ "how's the weather today?",
611
+ "how are things going?",
612
+ "lovely weather today",
613
+ "the weather is horrendous",
614
+ "let's go to the chippy",
615
+ ],
616
+ },
617
+ ],
618
+ });
619
+
620
+ console.log(await classifier.classify("don't you love politics?")); // politics
621
+ console.log(await classifier.classify("how's the weather today?")); // chitchat
622
+ console.log(
623
+ await classifier.classify("I'm interested in learning about llama 2")
624
+ ); // null
625
+ ```
626
+
627
+ ## v0.115.0 - 2024-01-05
628
+
629
+ ### Removed
630
+
631
+ - Anthropic support. Anthropic has a strong stance against open-source models and against non-US AI. I will not support them by providing a ModelFusion integration.
632
+
633
+ ## v0.114.1 - 2024-01-05
634
+
635
+ ### Fixed
636
+
637
+ - Together AI text generation and text streaming using OpenAI-compatible chat models.
638
+
639
+ ## v0.114.0 - 2024-01-05
640
+
641
+ ### Added
642
+
643
+ - Custom call header support for APIs. You can pass a `customCallHeaders` function into API configurations to add custom headers. The function is called with `functionType`, `functionId`, `run`, and `callId` parameters. Example for Helicone:
644
+
645
+ ```ts
646
+ const text = await generateText(
647
+ openai
648
+ .ChatTextGenerator({
649
+ api: new HeliconeOpenAIApiConfiguration({
650
+ customCallHeaders: ({ functionId, callId }) => ({
651
+ "Helicone-Property-FunctionId": functionId,
652
+ "Helicone-Property-CallId": callId,
653
+ }),
654
+ }),
655
+ model: "gpt-3.5-turbo",
656
+ temperature: 0.7,
657
+ maxGenerationTokens: 500,
658
+ })
659
+ .withTextPrompt(),
660
+
661
+ "Write a short story about a robot learning to love",
662
+
663
+ { functionId: "example-function" }
664
+ );
665
+ ```
666
+
667
+ - Rudimentary caching support for `generateText`. You can use a `MemoryCache` to store the response of a `generateText` call. Example:
668
+
669
+ ```ts
670
+ import { MemoryCache, generateText, ollama } from "modelfusion";
671
+
672
+ const model = ollama
673
+ .ChatTextGenerator({ model: "llama2:chat", maxGenerationTokens: 100 })
674
+ .withTextPrompt();
675
+
676
+ const cache = new MemoryCache();
677
+
678
+ const text1 = await generateText(
679
+ model,
680
+ "Write a short story about a robot learning to love:",
681
+ { cache }
682
+ );
683
+
684
+ console.log(text1);
685
+
686
+ // 2nd call will use cached response:
687
+ const text2 = await generateText(
688
+ model,
689
+ "Write a short story about a robot learning to love:", // same text
690
+ { cache }
691
+ );
692
+
693
+ console.log(text2);
694
+ ```
695
+
696
+ - `validateTypes` and `safeValidateTypes` helpers that perform type checking of an object against a `Schema` (e.g., a `zodSchema`).
697
+
698
+ ## v0.113.0 - 2024-01-03
699
+
700
+ [Structure generation](https://modelfusion.dev/guide/function/generate-structure) improvements.
701
+
702
+ ### Added
703
+
704
+ - `.asStructureGenerationModel(...)` function to `OpenAIChatModel` and `OllamaChatModel` to create structure generation models from chat models.
705
+ - `jsonStructurePrompt` helper function to create structure generation models.
706
+
707
+ ### Example
708
+
709
+ ```ts
710
+ import {
711
+ generateStructure,
712
+ jsonStructurePrompt,
713
+ ollama,
714
+ zodSchema,
715
+ } from "modelfusion";
716
+
717
+ const structure = await generateStructure(
718
+ ollama
719
+ .ChatTextGenerator({
720
+ model: "openhermes2.5-mistral",
721
+ maxGenerationTokens: 1024,
722
+ temperature: 0,
723
+ })
724
+ .asStructureGenerationModel(jsonStructurePrompt.text()),
725
+
726
+ zodSchema(
727
+ z.object({
728
+ characters: z.array(
729
+ z.object({
730
+ name: z.string(),
731
+ class: z
732
+ .string()
733
+ .describe("Character class, e.g. warrior, mage, or thief."),
734
+ description: z.string(),
735
+ })
736
+ ),
737
+ })
738
+ ),
739
+
740
+ "Generate 3 character descriptions for a fantasy role playing game. "
741
+ );
742
+ ```
743
+
744
+ ## v0.112.0 - 2024-01-02
745
+
746
+ ### Changed
747
+
748
+ - **breaking change**: renamed `useToolsOrGenerateText` to `useTools`
749
+ - **breaking change**: renamed `generateToolCallsOrText` to `generateToolCalls`
750
+
751
+ ### Removed
752
+
753
+ - Restriction on tool names. OpenAI tool calls do not have such a restriction.
754
+
755
+ ## v0.111.0 - 2024-01-01
756
+
757
+ Reworked API configuration support.
758
+
759
+ ### Added
760
+
761
+ - All providers now have an `Api` function that you can call to create custom API configurations. The base URL set up is more flexible and allows you to override parts of the base URL selectively.
762
+ - `api` namespace with retry and throttle configurations
763
+
764
+ ### Changed
765
+
766
+ - Updated Cohere models.
767
+ - Updated LMNT API calls to LMNT `v1` API.
768
+ - **breaking change**: Renamed `throttleUnlimitedConcurrency` to `throttleOff`.
769
+
770
+ ## v0.110.0 - 2023-12-30
771
+
772
+ ### Changed
773
+
774
+ - **breaking change**: renamed `modelfusion/extension` to `modelfusion/internal`. This requires updating `modelfusion-experimental` (if used) to `v0.3.0`
775
+
776
+ ### Removed
777
+
778
+ - Deprecated OpenAI completion models that will be deactivated on January 4, 2024.
779
+
780
+ ## v0.109.0 - 2023-12-30
781
+
782
+ ### Added
783
+
784
+ - [Open AI compatible completion model](https://modelfusion.dev/integration/model-provider/openaicompatible/). It e.g. works with Fireworks AI.
785
+ - Together AI API configuration (for Open AI compatible chat models):
786
+
787
+ ```ts
788
+ import {
789
+ TogetherAIApiConfiguration,
790
+ openaicompatible,
791
+ streamText,
792
+ } from "modelfusion";
793
+
794
+ const textStream = await streamText(
795
+ openaicompatible
796
+ .ChatTextGenerator({
797
+ api: new TogetherAIApiConfiguration(),
798
+ model: "mistralai/Mixtral-8x7B-Instruct-v0.1",
799
+ })
800
+ .withTextPrompt(),
801
+
802
+ "Write a story about a robot learning to love"
803
+ );
804
+ ```
805
+
806
+ - Updated Llama.cpp model settings. GBNF grammars can be passed into the `grammar` setting:
807
+
808
+ ```ts
809
+ const text = await generateText(
810
+ llamacpp
811
+ .TextGenerator({
812
+ maxGenerationTokens: 512,
813
+ temperature: 0,
814
+ // simple list grammar:
815
+ grammar: `root ::= ("- " item)+
816
+ item ::= [^\\n]+ "\\n"`,
817
+ })
818
+ .withTextPromptTemplate(MistralInstructPrompt.text()),
819
+
820
+ "List 5 ingredients for a lasagna:\n\n"
821
+ );
822
+ ```
823
+
824
+ ## v0.107.0 - 2023-12-29
825
+
826
+ ### Added
827
+
828
+ - Mistral instruct prompt template
829
+
830
+ ### Changed
831
+
832
+ - **breaking change**: Renamed `LlamaCppTextGenerationModel` to `LlamaCppCompletionModel`.
833
+
834
+ ### Fixed
835
+
836
+ - Updated `LlamaCppCompletionModel` to the latest llama.cpp version.
837
+ - Fixed formatting of system prompt for chats in Llama2 2 prompt template.
838
+
839
+ ## v0.106.0 - 2023-12-28
840
+
841
+ Experimental features that are unlikely to become stable before v1.0 have been moved to a separate `modelfusion-experimental` package.
842
+
843
+ ### Removed
844
+
845
+ - Cost calculation
846
+ - `guard` function
847
+ - Browser and server features (incl. flow)
848
+ - `summarizeRecursively` function
849
+
850
+ ## v0.105.0 - 2023-12-26
851
+
852
+ ### Added
853
+
854
+ - Tool call support for chat prompts. Assistant messages can contain tool calls, and tool messages can contain tool call results. Tool calls can be used to implement e.g. agents:
855
+
856
+ ```ts
857
+ const chat: ChatPrompt = {
858
+ system: "You are ...",
859
+ messages: [ChatMessage.user({ text: instruction })],
860
+ };
861
+
862
+ while (true) {
863
+ const { text, toolResults } = await useToolsOrGenerateText(
864
+ openai
865
+ .ChatTextGenerator({ model: "gpt-4-1106-preview" })
866
+ .withChatPrompt(),
867
+ tools, // array of tools
868
+ chat
869
+ );
870
+
871
+ // add the assistant and tool messages to the chat:
872
+ chat.messages.push(
873
+ ChatMessage.assistant({ text, toolResults }),
874
+ ChatMessage.tool({ toolResults })
875
+ );
876
+
877
+ if (toolResults == null) {
878
+ return; // no more actions, break loop
879
+ }
880
+
881
+ // ... (handle tool results)
882
+ }
883
+ ```
884
+
885
+ - `streamText` returns a `text` promise when invoked with `fullResponse: true`. After the streaming has finished, the promise resolves with the full text.
886
+
887
+ ```ts
888
+ const { text, textStream } = await streamText(
889
+ openai.ChatTextGenerator({ model: "gpt-3.5-turbo" }).withTextPrompt(),
890
+ "Write a short story about a robot learning to love:",
891
+ { fullResponse: true }
892
+ );
893
+
894
+ // ... (handle streaming)
895
+
896
+ console.log(await text); // full text
897
+ ```
898
+
899
+ ## v0.104.0 - 2023-12-24
900
+
901
+ ### Changed
902
+
903
+ - **breaking change**: Unified text and multimodal prompt templates. `[Text/MultiModal]InstructionPrompt` is now `InstructionPrompt`, and `[Text/MultiModalChatPrompt]` is now `ChatPrompt`.
904
+ - More flexible chat prompts: The chat prompt validation is now chat template specific and validated at runtime. E.g. the Llama2 prompt template only supports turns of user and assistant messages, whereas other formats are more flexible.
905
+
906
+ ## v0.103.0 - 2023-12-23
907
+
908
+ ### Added
909
+
910
+ - `finishReason` support for `generateText`.
911
+
912
+ The finish reason can be `stop` (the model stopped because it generated a stop sequence), `length` (the model stopped because it generated the maximum number of tokens), `content-filter` (the model stopped because the content filter detected a violation), `tool-calls` (the model stopped because it triggered a tool call), `error` (the model stopped because of an error), `other` (the model stopped for another reason), or `unknown` (the model stop reason is not know or the model does not support finish reasons).
913
+
914
+ You can extract it from the full response when using `fullResponse: true`:
915
+
916
+ ```ts
917
+ const { text, finishReason } = await generateText(
918
+ openai
919
+ .ChatTextGenerator({ model: "gpt-3.5-turbo", maxGenerationTokens: 200 })
920
+ .withTextPrompt(),
921
+ "Write a short story about a robot learning to love:",
922
+ { fullResponse: true }
923
+ );
924
+ ```
925
+
926
+ ## v0.102.0 - 2023-12-22
927
+
928
+ ### Added
929
+
930
+ - You can specify `numberOfGenerations` on image generation models and create multiple images by using the `fullResponse: true` option. Example:
931
+
932
+ ```ts
933
+ // generate 2 images:
934
+ const { images } = await generateImage(
935
+ openai.ImageGenerator({
936
+ model: "dall-e-3",
937
+ numberOfGenerations: 2,
938
+ size: "1024x1024",
939
+ }),
940
+ "the wicked witch of the west in the style of early 19th century painting",
941
+ { fullResponse: true }
942
+ );
943
+ ```
944
+
945
+ - **breaking change**: Image generation models use a generalized `numberOfGenerations` parameter (instead of model specific parameters) to specify the number of generations.
946
+
947
+ ## v0.101.0 - 2023-12-22
948
+
949
+ ### Changed
950
+
951
+ - Automatic1111 Stable Diffusion Web UI configuration has separate configuration of host, port, and path.
952
+
953
+ ### Fixed
954
+
955
+ - Automatic1111 Stable Diffusion Web UI uses negative prompt and seed.
956
+
957
+ ## v0.100.0 - 2023-12-17
958
+
959
+ ### Added
960
+
961
+ - `ollama.ChatTextGenerator` model that calls the Ollama chat API.
962
+ - Ollama chat messages and prompts are exposed through `ollama.ChatMessage` and `ollama.ChatPrompt`
963
+ - OpenAI chat messages and prompts are exposed through `openai.ChatMessage` and `openai.ChatPrompt`
964
+ - Mistral chat messages and prompts are exposed through `mistral.ChatMessage` and `mistral.ChatPrompt`
965
+
966
+ ### Changed
967
+
968
+ - **breaking change**: renamed `ollama.TextGenerator` to `ollama.CompletionTextGenerator`
969
+ - **breaking change**: renamed `mistral.TextGenerator` to `mistral.ChatTextGenerator`
970
+
971
+ ## v0.99.0 - 2023-12-16
972
+
973
+ ### Added
974
+
975
+ - You can specify `numberOfGenerations` on text generation models and access multiple generations by using the `fullResponse: true` option. Example:
976
+
977
+ ```ts
978
+ // generate 2 texts:
979
+ const { texts } = await generateText(
980
+ openai.CompletionTextGenerator({
981
+ model: "gpt-3.5-turbo-instruct",
982
+ numberOfGenerations: 2,
983
+ maxGenerationTokens: 1000,
984
+ }),
985
+ "Write a short story about a robot learning to love:\n\n",
986
+ { fullResponse: true }
987
+ );
988
+ ```
989
+
990
+ - **breaking change**: Text generation models use a generalized `numberOfGenerations` parameter (instead of model specific parameters) to specify the number of generations.
991
+
992
+ ### Changed
993
+
994
+ - **breaking change**: Renamed `maxCompletionTokens` text generation model setting to `maxGenerationTokens`.
995
+
996
+ ## v0.98.0 - 2023-12-16
997
+
998
+ ### Changed
999
+
1000
+ - **breaking change**: `responseType` option was changed into `fullResponse` option and uses a boolean value to make discovery easy. The response values from the full response have been renamed for clarity. For base64 image generation, you can use the `imageBase64` value from the full response:
1001
+
1002
+ ```ts
1003
+ const { imageBase64 } = await generateImage(model, prompt, {
1004
+ fullResponse: true,
1005
+ });
1006
+ ```
1007
+
1008
+ ### Improved
1009
+
1010
+ - Better docs for the OpenAI chat settings. Thanks [@bearjaws](https://github.com/bearjaws) for the contribution!
1011
+
1012
+ ### Fixed
1013
+
1014
+ - Streaming OpenAI chat text generation when setting `n:2` or higher returns only the stream from the first choice.
1015
+
1016
+ ## v0.97.0 - 2023-12-14
1017
+
1018
+ ### Added
1019
+
1020
+ - **breaking change**: Ollama image (vision) support. This changes the Ollama prompt format. You can add `.withTextPrompt()` to existing Ollama text generators to get a text prompt like before.
1021
+
1022
+ Vision example:
1023
+
1024
+ ```ts
1025
+ import { ollama, streamText } from "modelfusion";
1026
+
1027
+ const textStream = await streamText(
1028
+ ollama.TextGenerator({
1029
+ model: "bakllava",
1030
+ maxCompletionTokens: 1024,
1031
+ temperature: 0,
1032
+ }),
1033
+ {
1034
+ prompt: "Describe the image in detail",
1035
+ images: [image], // base-64 encoded png or jpeg
1036
+ }
1037
+ );
1038
+ ```
1039
+
1040
+ ### Changed
1041
+
1042
+ - **breaking change**: Switch Ollama settings to camelCase to align with the rest of the library.
1043
+
1044
+ ## v0.96.0 - 2023-12-14
1045
+
1046
+ ### Added
1047
+
1048
+ - [Mistral platform support](https://modelfusion.dev/integration/model-provider/mistral)
1049
+
1050
+ ## v0.95.0 - 2023-12-10
1051
+
1052
+ ### Added
1053
+
1054
+ - `cachePrompt` parameter for llama.cpp models. Thanks [@djwhitt](https://github.com/djwhitt) for the contribution!
1055
+
1056
+ ## v0.94.0 - 2023-12-10
1057
+
1058
+ ### Added
1059
+
1060
+ - Prompt template for neural-chat models.
1061
+
1062
+ ## v0.93.0 - 2023-12-10
1063
+
1064
+ ### Added
1065
+
1066
+ - Optional response prefix for instruction prompts to guide the LLM response.
1067
+
1068
+ ### Changed
1069
+
1070
+ - **breaking change**: Renamed prompt format to prompt template to align with the commonly used language (e.g. from model cards).
1071
+
1072
+ ## v0.92.1 - 2023-12-10
1073
+
1074
+ ### Changed
1075
+
1076
+ - Improved Ollama error handling.
1077
+
1078
+ ## v0.92.0 - 2023-12-09
1079
+
1080
+ ### Changed
1081
+
1082
+ - **breaking change**: setting global function observers and global logging has changed.
1083
+ You can call methods on a `modelfusion` import:
1084
+
1085
+ ```ts
1086
+ import { modelfusion } from "modelfusion";
1087
+
1088
+ modelfusion.setLogFormat("basic-text");
1089
+ ```
1090
+
1091
+ - Cleaned output when using `detailed-object` log format.
1092
+
1093
+ ## v0.91.0 - 2023-12-09
1094
+
1095
+ ### Added
1096
+
1097
+ - `Whisper.cpp` [transcription (speech-to-text) model](https://modelfusion.dev/integration/model-provider/whispercpp) support.
1098
+
1099
+ ```ts
1100
+ import { generateTranscription, whispercpp } from "modelfusion";
1101
+
1102
+ const data = await fs.promises.readFile("data/test.wav");
1103
+
1104
+ const transcription = await generateTranscription(whispercpp.Transcriber(), {
1105
+ type: "wav",
1106
+ data,
1107
+ });
1108
+ ```
1109
+
1110
+ ### Improved
1111
+
1112
+ - Better error reporting.
1113
+
1114
+ ## v0.90.0 - 2023-12-03
1115
+
1116
+ ### Added
1117
+
1118
+ - Temperature and language settings to OpenAI transcription model.
1119
+
1120
+ ## v0.89.0 - 2023-11-30
1121
+
1122
+ ### Added
1123
+
1124
+ - `maxValuesPerCall` setting for `OpenAITextEmbeddingModel` to enable different configurations, e.g. for Azure. Thanks [@nanotronic](https://github.com/nanotronic) for the contribution!
1125
+
1126
+ ## v0.88.0 - 2023-11-28
1127
+
1128
+ ### Added
1129
+
1130
+ - Multi-modal chat prompts. Supported by OpenAI vision chat models and by BakLLaVA prompt format.
1131
+
1132
+ ### Changed
1133
+
1134
+ - **breaking change**: renamed `ChatPrompt` to `TextChatPrompt` to distinguish it from multi-modal chat prompts.
1135
+
1136
+ ## v0.87.0 - 2023-11-27
1137
+
1138
+ ### Added
1139
+
1140
+ - **experimental**: `modelfusion/extension` export with functions and classes that are necessary to implement providers in 3rd party node modules. See [lgrammel/modelfusion-example-provider](https://github.com/lgrammel/modelfusion-example-provider) for an example.
1141
+
1142
+ ## v0.85.0 - 2023-11-26
1143
+
1144
+ ### Added
1145
+
1146
+ - `OpenAIChatMessage` function call support.
1147
+
1148
+ ## v0.84.0 - 2023-11-26
1149
+
1150
+ ### Added
1151
+
1152
+ - Support for OpenAI-compatible chat APIs. See [OpenAI Compatible](https://modelfusion.dev/integration/model-provider/openaicompatible) for details.
1153
+
1154
+ ```ts
1155
+ import {
1156
+ BaseUrlApiConfiguration,
1157
+ openaicompatible,
1158
+ generateText,
1159
+ } from "modelfusion";
1160
+
1161
+ const text = await generateText(
1162
+ openaicompatible
1163
+ .ChatTextGenerator({
1164
+ api: new BaseUrlApiConfiguration({
1165
+ baseUrl: "https://api.fireworks.ai/inference/v1",
1166
+ headers: {
1167
+ Authorization: `Bearer ${process.env.FIREWORKS_API_KEY}`,
1168
+ },
1169
+ }),
1170
+ model: "accounts/fireworks/models/mistral-7b",
1171
+ })
1172
+ .withTextPrompt(),
1173
+
1174
+ "Write a story about a robot learning to love"
1175
+ );
1176
+ ```
1177
+
1178
+ ## v0.83.0 - 2023-11-26
1179
+
1180
+ ### Added
1181
+
1182
+ - Introduce `uncheckedSchema()` facade function as an easier way to create unchecked ModelFusion schemas. This aligns the API with `zodSchema()`.
1183
+
1184
+ ### Changed
1185
+
1186
+ - **breaking change**: Renamed `InstructionPrompt` interface to `MultiModalInstructionPrompt` to clearly distinguish it from `TextInstructionPrompt`.
1187
+ - **breaking change**: Renamed `.withBasicPrompt` methods for image generation models to `.withTextPrompt` to align with text generation models.
1188
+
1189
+ ## v0.82.0 - 2023-11-25
1190
+
1191
+ ### Added
1192
+
1193
+ - Introduce `zodSchema()` facade function as an easier way to create new ModelFusion Zod schemas. This clearly distinguishes it from `ZodSchema` that is also part of the zod library.
1194
+
1195
+ ## v0.81.0 - 2023-11-25
1196
+
1197
+ **breaking change**: `generateStructure` and `streamStructure` redesign. The new API does not require function calling and `StructureDefinition` objects any more. This makes it more flexible and it can be used in 3 ways:
1198
+
1199
+ - with OpenAI function calling:
1200
+
1201
+ ```ts
1202
+ const model = openai
1203
+ .ChatTextGenerator({ model: "gpt-3.5-turbo" })
1204
+ .asFunctionCallStructureGenerationModel({
1205
+ fnName: "...",
1206
+ fnDescription: "...",
1207
+ });
1208
+ ```
1209
+
1210
+ - with OpenAI JSON format:
1211
+
1212
+ ```ts
1213
+ const model = openai
1214
+ .ChatTextGenerator({
1215
+ model: "gpt-4-1106-preview",
1216
+ temperature: 0,
1217
+ maxCompletionTokens: 1024,
1218
+ responseFormat: { type: "json_object" },
1219
+ })
1220
+ .asStructureGenerationModel(
1221
+ jsonStructurePrompt((instruction: string, schema) => [
1222
+ OpenAIChatMessage.system(
1223
+ "JSON schema: \n" +
1224
+ JSON.stringify(schema.getJsonSchema()) +
1225
+ "\n\n" +
1226
+ "Respond only using JSON that matches the above schema."
1227
+ ),
1228
+ OpenAIChatMessage.user(instruction),
1229
+ ])
1230
+ );
1231
+ ```
1232
+
1233
+ - with Ollama (and a capable model, e.g., OpenHermes 2.5):
1234
+ ```ts
1235
+ const model = ollama
1236
+ .TextGenerator({
1237
+ model: "openhermes2.5-mistral",
1238
+ maxCompletionTokens: 1024,
1239
+ temperature: 0,
1240
+ format: "json",
1241
+ raw: true,
1242
+ stopSequences: ["\n\n"], // prevent infinite generation
1243
+ })
1244
+ .withPromptFormat(ChatMLPromptFormat.instruction())
1245
+ .asStructureGenerationModel(
1246
+ jsonStructurePrompt((instruction: string, schema) => ({
1247
+ system:
1248
+ "JSON schema: \n" +
1249
+ JSON.stringify(schema.getJsonSchema()) +
1250
+ "\n\n" +
1251
+ "Respond only using JSON that matches the above schema.",
1252
+ instruction,
1253
+ }))
1254
+ );
1255
+ ```
1256
+
1257
+ See [generateStructure](https://modelfusion.dev/guide/function/generate-structure) for details on the new API.
1258
+
1259
+ ## v0.80.0 - 2023-11-24
1260
+
1261
+ ### Changed
1262
+
1263
+ - **breaking change**: Restructured multi-modal instruction prompts and `OpenAIChatMessage.user()`
1264
+
1265
+ ## v0.79.0 - 2023-11-23
1266
+
1267
+ ### Added
1268
+
1269
+ - Multi-tool usage from open source models
1270
+
1271
+ Use `TextGenerationToolCallsOrGenerateTextModel` and related helper methods `.asToolCallsOrTextGenerationModel()` to create custom prompts & parsers.
1272
+
1273
+ Examples:
1274
+
1275
+ - `examples/basic/src/model-provider/ollama/ollama-use-tools-or-generate-text-openhermes-example.ts`
1276
+ - `examples/basic/src/model-provider/llamacpp/llamacpp-use-tools-or-generate-text-openhermes-example.ts`
1277
+
1278
+ Example prompt format:
1279
+
1280
+ - `examples/basic/src/tool/prompts/open-hermes.ts` for OpenHermes 2.5
1281
+
1282
+ ## v0.78.0 - 2023-11-23
1283
+
1284
+ ### Removed
1285
+
1286
+ - **breaking change**: Removed `FunctionListToolCallPromptFormat`. See `examples/basic/src/model-provide/ollama/ollama-use-tool-mistral-example.ts` for how to implement a `ToolCallPromptFormat` for your tool.
1287
+
1288
+ ## v0.77.0 - 2023-11-23
1289
+
1290
+ ### Changed
1291
+
1292
+ - **breaking change**: Rename `Speech` to `SpeechGenerator` in facades
1293
+ - **breaking change**: Rename `Transcription` to `Transcriber` in facades
1294
+
1295
+ ## v0.76.0 - 2023-11-23
1296
+
1297
+ ### Added
1298
+
1299
+ - Anthropic Claude 2.1 support
1300
+
1301
+ ## v0.75.0 - 2023-11-22
1302
+
1303
+ Introducing model provider facades:
1304
+
1305
+ ```ts
1306
+ const image = await generateImage(
1307
+ openai.ImageGenerator({ model: "dall-e-3", size: "1024x1024" }),
1308
+ "the wicked witch of the west in the style of early 19th century painting"
1309
+ );
1310
+ ```
1311
+
1312
+ ### Added
1313
+
1314
+ - Model provider facades. You can e.g. use `ollama.TextGenerator(...)` instead of `new OllamaTextGenerationModel(...)`.
1315
+
1316
+ ### Changed
1317
+
1318
+ - **breaking change**: Fixed method name `isParallizable` to `isParallelizable` in `EmbeddingModel`.
1319
+
1320
+ ### Removed
1321
+
1322
+ - **breaking change**: removed `HuggingFaceImageDescriptionModel`. Image description models will be replaced by multi-modal vision models.
1323
+
1324
+ ## v0.74.1 - 2023-11-22
1325
+
1326
+ ### Improved
1327
+
1328
+ - Increase OpenAI chat streaming resilience.
1329
+
1330
+ ## v0.74.0 - 2023-11-21
1331
+
1332
+ Prompt format and tool calling improvements.
1333
+
1334
+ ### Added
1335
+
1336
+ - text prompt format. Use simple text prompts, e.g. with `OpenAIChatModel`:
1337
+ ```ts
1338
+ const textStream = await streamText(
1339
+ new OpenAIChatModel({
1340
+ model: "gpt-3.5-turbo",
1341
+ }).withTextPrompt(),
1342
+ "Write a short story about a robot learning to love."
1343
+ );
1344
+ ```
1345
+ - `.withTextPromptFormat` to `LlamaCppTextGenerationModel` for simplified prompt construction:
1346
+ ```ts
1347
+ const textStream = await streamText(
1348
+ new LlamaCppTextGenerationModel({
1349
+ // ...
1350
+ }).withTextPromptFormat(Llama2PromptFormat.text()),
1351
+ "Write a short story about a robot learning to love."
1352
+ );
1353
+ ```
1354
+ - `.asToolCallGenerationModel()` to `OllamaTextGenerationModel` to simplify tool calls.
1355
+
1356
+ ### Improved
1357
+
1358
+ - better error reporting when using exponent backoff retries
1359
+
1360
+ ### Removed
1361
+
1362
+ - **breaking change**: removed `input` from `InstructionPrompt` (was Alpaca-specific, `AlpacaPromptFormat` still supports it)
1363
+
1364
+ ## v0.73.1 - 2023-11-19
1365
+
1366
+ Remove section newlines from Llama 2 prompt format.
1367
+
1368
+ ## v0.73.0 - 2023-11-19
1369
+
1370
+ Ollama edge case and error handling improvements.
1371
+
1372
+ ## v0.72.0 - 2023-11-19
1373
+
1374
+ **Breaking change**: the tool calling API has been reworked to support multiple parallel tool calls. This required multiple breaking changes (see below). Check out the updated [tools documentation](https://modelfusion.dev/guide/tools/) for details.
1375
+
1376
+ ### Changed
1377
+
1378
+ - `Tool` has `parameters` and `returnType` schemas (instead of `inputSchema` and `outputSchema`).
1379
+ - `useTool` uses `generateToolCall` under the hood. The return value and error handling has changed.
1380
+ - `useToolOrGenerateText` has been renamed to `useToolsOrGenerateText`. It uses `generateToolCallsOrText` under the hood. The return value and error handling has changed. It can invoke several tools in parallel and returns an array of tool results.
1381
+ - The `maxRetries` parameter in `guard` has been replaced by a `maxAttempt` parameter.
1382
+
1383
+ ### Removed
1384
+
1385
+ - `generateStructureOrText` has been removed.
1386
+
1387
+ ## v0.71.0 - 2023-11-17
1388
+
1389
+ ### Added
1390
+
1391
+ - Experimental generateToolCallsOrText function for generating a multiple parallel tool call using the OpenAI chat/tools API.
1392
+
1393
+ ## v0.70.0 - 2023-11-16
1394
+
1395
+ ### Added
1396
+
1397
+ - ChatML prompt format.
1398
+
1399
+ ### Changed
1400
+
1401
+ - **breaking change**: `ChatPrompt` structure and terminology has changed to align more closely with OpenAI and similar chat prompts. This is also in preparation for integrating images and function calls results into chat prompts.
1402
+ - **breaking change**: Prompt formats are namespaced. Use e.g. `Llama2PromptFormat.chat()` instead of `mapChatPromptToLlama2Format()`. See [Prompt Format](https://modelfusion.dev/guide/function/generate-text#prompt-styles) for documentation of the new prompt formats.
1403
+
1404
+ ## v0.69.0 - 2023-11-15
1405
+
1406
+ ### Added
1407
+
1408
+ - Experimental generateToolCall function for generating a single tool call using the OpenAI chat/tools API.
1409
+
1410
+ ## v0.68.0 - 2023-11-14
1411
+
1412
+ ### Changed
1413
+
1414
+ - Refactored JSON parsing to use abstracted schemas. You can use `parseJSON` and `safeParseJSON` to securely parse JSON objects and optionally type-check them using any schema (e.g. a Zod schema).
1415
+
1416
+ ## v0.67.0 - 2023-11-12
1417
+
1418
+ ### Added
1419
+
1420
+ - Ollama 0.1.9 support: `format` (for forcing JSON output) and `raw` settings
1421
+ - Improved Ollama settings documentation
1422
+
1423
+ ## v0.66.0 - 2023-11-12
1424
+
1425
+ ### Added
1426
+
1427
+ - Support for fine-tuned OpenAI `gpt-4-0613` models
1428
+ - Support for `trimWhitespace` model setting in `streamText` calls
1429
+
1430
+ ## v0.65.0 - 2023-11-12
1431
+
1432
+ ### Added
1433
+
1434
+ - Image support for `OpenAIChatMessage.user`
1435
+ - `mapInstructionPromptToBakLLaVA1ForLlamaCppFormat` prompt format
1436
+
1437
+ ### Changed
1438
+
1439
+ - **breaking change**: `VisionInstructionPrompt` was replaced by an optional `image` field in `InstructionPrompt`.
1440
+
1441
+ ## v0.64.0 - 2023-11-11
1442
+
1443
+ ### Added
1444
+
1445
+ - Support for OpenAI vision model.
1446
+ - Example: `examples/basic/src/model-provider/openai/openai-chat-stream-text-vision-example.ts`
1447
+
1448
+ ## v0.63.0 - 2023-11-08
1449
+
1450
+ ### Added
1451
+
1452
+ - Support for OpenAI chat completion `seed` and `responseFormat` options.
1453
+
1454
+ ## v0.62.0 - 2023-11-08
1455
+
1456
+ ### Added
1457
+
1458
+ - OpenAI speech generation support. Shoutout to [@bjsi](https://github.com/bjsi) for the awesome contribution!
1459
+
1460
+ ## v0.61.0 - 2023-11-07
1461
+
1462
+ ### Added
1463
+
1464
+ - OpenAI `gpt-3.5-turbo-1106`, `gpt-4-1106-preview`, `gpt-4-vision-preview` chat models.
1465
+ - OpenAI `Dalle-E-3` image model.
1466
+
1467
+ ### Changed
1468
+
1469
+ - **breaking change**: `OpenAIImageGenerationModel` requires a `model` parameter.
1470
+
1471
+ ## v0.60.0 - 2023-11-06
1472
+
1473
+ ### Added
1474
+
1475
+ - Support image input for multi-modal Llama.cpp models (e.g. Llava, Bakllava).
1476
+
1477
+ ### Changed
1478
+
1479
+ - **breaking change**: Llama.cpp prompt format has changed to support images. Use `.withTextPrompt()` to get a text prompt format.
1480
+
1481
+ ## v0.59.0 - 2023-11-06
1482
+
1483
+ ### Added
1484
+
1485
+ - ElevenLabs `eleven_turbo_v2` support.
1486
+
1487
+ ## v0.58 - 2023-11-05
1488
+
1489
+ ### Fixed
1490
+
1491
+ - **breaking change**: Uncaught errors were caused by custom Promises. ModelFusion uses only standard Promises. To get full responses from model function, you need to use the `{ returnType: "full" }` option instead of calling `.asFullResponse()` on the result.
1492
+
1493
+ ## v0.57.1 - 2023-11-05
1494
+
1495
+ ### Improved
1496
+
1497
+ - ModelFusion server error logging and reporting.
1498
+
1499
+ ### Fixed
1500
+
1501
+ - ModelFusion server creates directory for runs automatically when errors are thrown.
1502
+
1503
+ ## v0.57.0 - 2023-11-04
1504
+
1505
+ ### Added
1506
+
1507
+ - Support for [Cohere v3 embeddings](https://txt.cohere.com/introducing-embed-v3/).
1508
+
1509
+ ## v0.56.0 - 2023-11-04
1510
+
1511
+ ### Added
1512
+
1513
+ - [Ollama model provider](https://modelfusion.dev/integration/model-provider/ollama) for text embeddings.
1514
+
1515
+ ## v0.55.1 - 2023-11-04
1516
+
1517
+ ### Fixed
1518
+
1519
+ - Llama.cpp embeddings are invoked sequentially to avoid rejection by the server.
1520
+
1521
+ ## v0.55.0 - 2023-11-04
1522
+
1523
+ ### Added
1524
+
1525
+ - [Ollama model provider](https://modelfusion.dev/integration/model-provider/ollama) for text generation and text streaming.
1526
+
1527
+ ## v0.54.0 - 2023-10-29
1528
+
1529
+ Adding experimental ModelFusion server, flows, and browser utils.
1530
+
1531
+ ### Added
1532
+
1533
+ - ModelFusion server (separate export 'modelfusion/server') with a Fastify plugin for running ModelFusion flows on a server.
1534
+ - ModelFusion flows.
1535
+ - ModelFusion browser utils (separate export 'modelfusion/browser') for dealing with audio data and invoking ModelFusion flows on the server (`invokeFlow`).
1536
+
1537
+ ### Changed
1538
+
1539
+ - **breaking change**: `readEventSource` and `readEventSourceStream` are part of 'modelfusion/browser'.
1540
+
1541
+ ## v0.53.2 - 2023-10-26
1542
+
1543
+ ### Added
1544
+
1545
+ - Prompt callback option for `streamStructure`
1546
+
1547
+ ### Improved
1548
+
1549
+ - Inline JSDoc comments for the model functions.
1550
+
1551
+ ## v0.53.1 - 2023-10-25
1552
+
1553
+ ### Fixed
1554
+
1555
+ - Abort signals and errors during streaming are caught and forwarded correctly.
1556
+
1557
+ ## v0.53.0 - 2023-10-23
1558
+
1559
+ ### Added
1560
+
1561
+ - `executeFunction` utility function for tracing execution time, parameters, and result of composite functions and non-ModelFusion functions.
1562
+
1563
+ ## v0.52.0 - 2023-10-23
1564
+
1565
+ ### Changed
1566
+
1567
+ - Streaming results and `AsyncQueue` objects can be used by several consumers. Each consumer will receive all values. This means that you can e.g. forward the same text stream to speech generation and the client.
1568
+
1569
+ ## v0.51.0 - 2023-10-23
1570
+
1571
+ ElevenLabs improvements.
1572
+
1573
+ ### Added
1574
+
1575
+ - ElevenLabs model settings `outputFormat` and `optimizeStreamingLatency`.
1576
+
1577
+ ### Fixed
1578
+
1579
+ - Default ElevenLabs model is `eleven_monolingual_v1`.
1580
+
1581
+ ## v0.50.0 - 2023-10-22
1582
+
1583
+ ### Added
1584
+
1585
+ - `parentCallId` event property
1586
+ - Tracing for `useTool`, `useToolOrGenerateText`, `upsertIntoVectorIndex`, and `guard`
1587
+
1588
+ ### Changed
1589
+
1590
+ - **breaking change**: rename `embedding` event type to `embed`
1591
+ - **breaking change**: rename `image-generation` event type to `generate-image`
1592
+ - **breaking change**: rename `speech-generation` event type to `generate-speech`
1593
+ - **breaking change**: rename `speech-streaming` event type to `stream-speech`
1594
+ - **breaking change**: rename `structure-generation` event type to `generate-structure`
1595
+ - **breaking change**: rename `structure-or-text-generation` event type to `generate-structure-or-text`
1596
+ - **breaking change**: rename `structure-streaming` event type to `stream-structure`
1597
+ - **breaking change**: rename `text-generation` event type to `generate-text`
1598
+ - **breaking change**: rename `text-streaming` event type to `stream-text`
1599
+ - **breaking change**: rename `transcription` event type to `generate-transcription`
1600
+
1601
+ ## v0.49.0 - 2023-10-21
1602
+
1603
+ ### Added
1604
+
1605
+ - Speech synthesis streaming supports string inputs.
1606
+ - Observability for speech synthesis streaming.
1607
+
1608
+ ### Changed
1609
+
1610
+ - **breaking change**: split `synthesizeSpeech` into `generateSpeech` and `streamSpeech` functions
1611
+ - **breaking change**: renamed `speech-synthesis` event to `speech-generation`
1612
+ - **breaking change**: renamed `transcribe` to `generateTranscription`
1613
+ - **breaking change**: renamed `LmntSpeechSynthesisModel` to `LmntSpeechModel`
1614
+ - **breaking change**: renamed `ElevenLabesSpeechSynthesisModel` to `ElevenLabsSpeechModel`
1615
+ - **breaking change**: renamed `OpenAITextGenerationModel` to `OpenAICompletionModel`
1616
+
1617
+ ### Removed
1618
+
1619
+ - **breaking change**: `describeImage` model function. Use `generateText` instead (with e.g. `HuggingFaceImageDescriptionModel`).
1620
+
1621
+ ## v0.48.0 - 2023-10-20
1622
+
1623
+ ### Added
1624
+
1625
+ - Duplex streaming for speech synthesis.
1626
+ - Elevenlabs duplex streaming support.
1627
+
1628
+ ### Changed
1629
+
1630
+ - Schema is using data in return type (breaking change for tools).
1631
+
1632
+ ## v0.47.0 - 2023-10-14
1633
+
1634
+ ### Added
1635
+
1636
+ - Prompt formats for image generation. You can use `.withPromptFormat()` or `.withBasicPrompt()` to apply a prompt format to an image generation model.
1637
+
1638
+ ### Changed
1639
+
1640
+ - **breaking change**: `generateImage` returns a Buffer with the binary image data instead of a base-64 encoded string. You can call `.asBase64Text()` on the response to get a base64 encoded string.
1641
+
1642
+ ## v0.46.0 - 2023-10-14
1643
+
1644
+ ### Added
1645
+
1646
+ - `.withChatPrompt()` and `.withInstructionPrompt()` shorthand methods.
1647
+
1648
+ ## v0.45.0 - 2023-10-14
1649
+
1650
+ ### Changed
1651
+
1652
+ - Updated Zod to 3.22.4. You need to use Zod 3.22.4 or higher in your project.
1653
+
1654
+ ## v0.44.0 - 2023-10-13
1655
+
1656
+ ### Added
1657
+
1658
+ - Store runs in AsyncLocalStorage for convienience (Node.js only).
1659
+
1660
+ ## v0.43.0 - 2023-10-12
1661
+
1662
+ ### Added
1663
+
1664
+ - Guard function.
1665
+
1666
+ ## v0.42.0 - 2023-10-11
1667
+
1668
+ ### Added
1669
+
1670
+ - Anthropic model support (Claude 2, Claude instant).
1671
+
1672
+ ## v0.41.0 - 2023-10-05
1673
+
1674
+ ### Changed
1675
+
1676
+ **breaking change**: generics simplification to enable dynamic model usage. Models can be used more easily as function parameters.
1677
+
1678
+ - `output` renamed to `value` in `asFullResponse()`
1679
+ - model settings can no longer be configured as a model options parameter. Use `.withSettings()` instead.
1680
+
1681
+ ## v0.40.0 - 2023-10-04
1682
+
1683
+ ### Changed
1684
+
1685
+ **breaking change**: moved Pinecone integration into `@modelfusion/pinecone` module.
1686
+
1687
+ ## v0.39.0 - 2023-10-03
1688
+
1689
+ ### Added
1690
+
1691
+ - `readEventSource` for parsing a server-sent event stream using the JavaScript EventSource.
1692
+
1693
+ ### Changed
1694
+
1695
+ **breaking change**: generalization to use Schema instead of Zod.
1696
+
1697
+ - `MemoryVectorIndex.deserialize` requires a `Schema`, e.g. `new ZodSchema` (from ModelFusion).
1698
+ - `readEventSourceStream` requires a `Schema`.
1699
+ - `UncheckedJsonSchema[Schema/StructureDefinition]` renamed to `Unchecked[Schema/StructureDefinition]`.
1700
+
1701
+ ## v0.38.0 - 2023-10-02
1702
+
1703
+ ### Changed
1704
+
1705
+ **breaking change**: Generalized embeddings beyond text embedding.
1706
+
1707
+ - `embedText` renamed to `embed`.
1708
+ - `embedTexts` renamed to `embedMany`
1709
+ - Removed filtering from `VectorIndexRetriever` query (still available as a setting).
1710
+
1711
+ ## v0.37.0 - 2023-10-02
1712
+
1713
+ ### Added
1714
+
1715
+ - `VectorIndexRetriever` supports a filter option that is passed to the vector index.
1716
+ - `MemoryVectorIndex` supports filter functions that are applied to the objects before calculating the embeddings.
1717
+
1718
+ ## v0.36.0 - 2023-10-02
1719
+
1720
+ ### Added
1721
+
1722
+ - `basic-text` logger logs function ids when available.
1723
+ - `retrieve` produces events for logging and observability.
1724
+
1725
+ ## v0.35.2 - 2023-09-27
1726
+
1727
+ ### Fixed
1728
+
1729
+ - Support empty stop sequences when calling OpenAI text and chat models.
1730
+
1731
+ ## v0.35.1 - 2023-09-27
1732
+
1733
+ ### Fixed
1734
+
1735
+ - Fixed bugs in `streamStructure` partial JSON parsing.
1736
+
1737
+ ## v0.35.0 - 2023-09-26
1738
+
1739
+ ### Added
1740
+
1741
+ - `streamStructure` for streaming structured responses, e.g. from OpenAI function calls. Thanks [@bjsi](https://github.com/bjsi) for the input!
1742
+
1743
+ ## v0.34.0 - 2023-09-25
1744
+
1745
+ ### Added
1746
+
1747
+ - First version of event source utilities: `AsyncQueue`, `createEventSourceStream`, `readEventSourceStream`.
1748
+
1749
+ ## v0.33.1 - 2023-09-24
1750
+
1751
+ ### Fixed
1752
+
1753
+ - Remove resolution part from type definitions.
1754
+
1755
+ ## v0.33.0 - 2023-09-19
1756
+
1757
+ ### Changed
1758
+
1759
+ **breaking change**: Generalized vector store upsert/retrieve beyond text chunks:
1760
+
1761
+ - `upsertTextChunks` renamed to `upsertIntoVectorStore`. Syntax has changed.
1762
+ - `retrieveTextChunks` renamed to `retrieve`
1763
+ - `SimilarTextChunksFromVectorIndexRetriever` renamed to `VectorIndexRetriever`
1764
+
1765
+ ## v0.32.0 - 2023-09-19
1766
+
1767
+ ### Added
1768
+
1769
+ - OpenAI gpt-3.5-turbo-instruct model support.
1770
+ - Autocomplete for Stability AI models (thanks [@Danielwinkelmann](https://github.com/Danielwinkelmann)!)
1771
+
1772
+ ### Changed
1773
+
1774
+ - Downgrade Zod version to 3.21.4 because of https://github.com/colinhacks/zod/issues/2697
1775
+
1776
+ ## v0.31.0 - 2023-09-13
1777
+
1778
+ ### Changed
1779
+
1780
+ - **breaking change**: Renamed chat format construction functions to follow the pattern `map[Chat|Instruction]PromptTo[FORMAT]Format()`, e.g. `mapInstructionPromptToAlpacaFormat()`, for easy auto-completion.
1781
+
1782
+ ### Removed
1783
+
1784
+ - **breaking change**: The prompts for `generateStructure` and `generateStructureOrText` have been simplified. You can remove the `OpenAIChatPrompt.forStructureCurried` (and similar) parts.
1785
+
1786
+ ## v0.30.0 - 2023-09-10
1787
+
1788
+ ### Added
1789
+
1790
+ - You can directly pass JSON schemas into `generateStructure` and `generateStructureOrText` calls without validation using `UncheckedJsonSchemaStructureDefinition`. This is useful when you need more flexility and don't require type inference. See `examples/basic/src/util/schema/generate-structure-unchecked-json-schema-example.ts`.
1791
+
1792
+ ### Changed
1793
+
1794
+ - **BREAKING CHANGE**: renamed `generateJson` and `generateJsonOrText` to `generateStructure` and `generateStructureOrText`.
1795
+ - **BREAKING CHANGE**: introduced `ZodSchema` and `ZodStructureDefinition`. These are required for `generateStructure` and `generateStructureOrText` calls and in tools.
1796
+ - **BREAKING CHANGE**: renamed the corresponding methods and objects.
1797
+
1798
+ Why this breaking change?
1799
+
1800
+ ModelFusion is currently tied to Zod, but there are many other type checking libraries out there, and Zod does not map perfectly to JSON Schema (which is used in OpenAI function calling).
1801
+ Enabling you to use JSON Schema directly in ModelFusion is a first step towards decoupling ModelFusion from Zod.
1802
+ You can also configure your own schema adapters that e.g. use Ajv or another library.
1803
+ Since this change already affected all JSON generation calls and tools, I included other changes that I had planned in the same area (e.g., renaming to generateStructure and making it more consistent).
1804
+
1805
+ ## v0.29.0 - 2023-09-09
1806
+
1807
+ ### Added
1808
+
1809
+ - `describeImage` model function for image captioning and OCR. HuggingFace provider available.
1810
+
1811
+ ## v0.28.0 - 2023-09-09
1812
+
1813
+ ### Added
1814
+
1815
+ - BaseUrlApiConfiguration class for setting up API configurations with custom base URLs and headers.
1816
+
1817
+ ## v0.27.0 - 2023-09-07
1818
+
1819
+ ### Added
1820
+
1821
+ - Support for running OpenAI on Microsoft Azure.
1822
+
1823
+ ### Changed
1824
+
1825
+ - **Breaking change**: Introduce API configuration. This affects setting the baseUrl, throttling, and retries.
1826
+ - Improved Helicone support via `HeliconeOpenAIApiConfiguration`.
1827
+
1828
+ ## v0.26.0 - 2023-09-06
1829
+
1830
+ ### Added
1831
+
1832
+ - LMNT speech synthesis support.
1833
+
1834
+ ## v0.25.0 - 2023-09-05
1835
+
1836
+ ### Changed
1837
+
1838
+ - Separated cost calculation from Run.
1839
+
1840
+ ## v0.24.1 - 2023-09-04
1841
+
1842
+ ### Added
1843
+
1844
+ - Exposed `logitBias` setting for OpenAI chat and text generation models.
1845
+
1846
+ ## v0.24.0 - 2023-09-02
1847
+
1848
+ ### Added
1849
+
1850
+ - Support for fine-tuned OpenAI models (for the `davinci-002`, `babbage-002`, and `gpt-3.5-turbo` base models).
1851
+
1852
+ ## v0.23.0 - 2023-08-31
1853
+
1854
+ ### Added
1855
+
1856
+ - Function logging support.
1857
+ - Usage information for events.
1858
+ - Filtering of model settings for events.
1859
+
1860
+ ## v0.22.0 - 2023-08-28
1861
+
1862
+ ### Changed
1863
+
1864
+ - **Breaking change**: Restructured the function call events.
1865
+
1866
+ ## v0.21.0 - 2023-08-26
1867
+
1868
+ ### Changed
1869
+
1870
+ - **Breaking change**: Reworked the function observer system. See [Function observers](https://modelfusion.dev/guide/util/observer) for details on how to use the new system.
1871
+
1872
+ ## v0.20.0 - 2023-08-24
1873
+
1874
+ ### Changed
1875
+
1876
+ - **Breaking change**: Use `.asFullResponse()` to get full responses from model functions (replaces the `fullResponse: true` option).
1877
+
1878
+ ## v0.19.0 - 2023-08-23
1879
+
1880
+ ### Added
1881
+
1882
+ - Support for "babbage-002" and "davinci-002" OpenAI base models.
1883
+
1884
+ ### Fixed
1885
+
1886
+ - Choose correct tokenizer for older OpenAI text models.
1887
+
1888
+ ## v0.18.0 - 2023-08-22
1889
+
1890
+ ### Added
1891
+
1892
+ - Support for ElevenLabs speech synthesis parameters.
1893
+
1894
+ ## v0.17.0 - 2023-08-21
1895
+
1896
+ ### Added
1897
+
1898
+ - `generateSpeech` function to generate speech from text.
1899
+ - ElevenLabs support.
1900
+
1901
+ ## v0.15.0 - 2023-08-21
1902
+
1903
+ ### Changed
1904
+
1905
+ - Introduced unified `stopSequences` and `maxCompletionTokens` properties for all text generation models. **Breaking change**: `maxCompletionTokens` and `stopSequences` are part of the base TextGenerationModel. Specific names for these properties in models have been replaced by this, e.g. `maxTokens` in OpenAI models is `maxCompletionTokens`.
1906
+
1907
+ ## v0.14.0 - 2023-08-17
1908
+
1909
+ ### Changed
1910
+
1911
+ - **Breaking change**: Renamed prompt mappings (and related code) to prompt format.
1912
+ - Improved type inference for WebSearchTool and executeTool.
1913
+
1914
+ ## v0.12.0 - 2023-08-15
1915
+
1916
+ ### Added
1917
+
1918
+ - JsonTextGenerationModel and InstructionWithSchemaPrompt to support generateJson on text generation models.
1919
+
1920
+ ## v0.11.0 - 2023-08-14
1921
+
1922
+ ### Changed
1923
+
1924
+ - WebSearchTool signature updated.
1925
+
1926
+ ## v0.10.0 - 2023-08-13
1927
+
1928
+ ### Added
1929
+
1930
+ - Convenience functions to create OpenAI chat messages from tool calls and results.
1931
+
1932
+ ## v0.9.0 - 2023-08-13
1933
+
1934
+ ### Added
1935
+
1936
+ - `WebSearchTool` definition to support the SerpAPI tool (separate package: `@modelfusion/serpapi-tools`)
1937
+
1938
+ ## v0.8.0 - 2023-08-12
1939
+
1940
+ ### Added
1941
+
1942
+ - `executeTool` function that directly executes a single tool and records execution metadata.
1943
+
1944
+ ### Changed
1945
+
1946
+ - Reworked event system and introduced RunFunctionEvent.
1947
+
1948
+ ## v0.7.0 - 2023-08-10
1949
+
1950
+ ### Changed
1951
+
1952
+ - **Breaking change**: Model functions return a simple object by default to make the 95% use case easier. You can use the `fullResponse` option to get a richer response object that includes the original model response and metadata.
1953
+
1954
+ ## v0.6.0 - 2023-08-07
1955
+
1956
+ ### Added
1957
+
1958
+ - `splitTextChunk` function.
1959
+
1960
+ ### Changed
1961
+
1962
+ - **Breaking change**: Restructured text splitter functions.
1963
+
1964
+ ## v0.5.0 - 2023-08-07
1965
+
1966
+ ### Added
1967
+
1968
+ - `splitTextChunks` function.
1969
+ - Chat with PDF demo.
1970
+
1971
+ ### Changed
1972
+
1973
+ - **Breaking change**: Renamed VectorIndexSimilarTextChunkRetriever to SimilarTextChunksFromVectorIndexRetriever.
1974
+ - **Breaking change**: Renamed 'content' property in TextChunk to 'text.
1975
+
1976
+ ### Removed
1977
+
1978
+ - `VectorIndexTextChunkStore`
1979
+
1980
+ ## v0.4.1 - 2023-08-06
1981
+
1982
+ ### Fixed
1983
+
1984
+ - Type inference bug in `trimChatPrompt`.
1985
+
1986
+ ## v0.4.0 - 2023-08-06
1987
+
1988
+ ### Added
1989
+
1990
+ - HuggingFace text embedding support.
1991
+
1992
+ ## v0.3.0 - 2023-08-05
1993
+
1994
+ ### Added
1995
+
1996
+ - Helicone observability integration.
1997
+
1998
+ ## v0.2.0 - 2023-08-04
1999
+
2000
+ ### Added
2001
+
2002
+ - Instruction prompts can contain optional `input` property.
2003
+ - Alpaca instruction prompt mapping.
2004
+ - Vicuna chat prompt mapping.
2005
+
2006
+ ## v0.1.1 - 2023-08-02
2007
+
2008
+ ### Changed
2009
+
2010
+ - Docs updated to ModelFusion.
2011
+
2012
+ ## v0.1.0 - 2023-08-01
2013
+
2014
+ ### Changed
2015
+
2016
+ - **Breaking Change**: Renamed to `modelfusion` (from `ai-utils.js`).
2017
+
2018
+ ## v0.0.43 - 2023-08-01
2019
+
2020
+ ### Changed
2021
+
2022
+ - **Breaking Change**: model functions return rich objects that include the result, the model response and metadata. This enables you to access the original model response easily when you need it and also use the metadata outside of runs.
2023
+
2024
+ ## v0.0.42 - 2023-07-31
2025
+
2026
+ ### Added
2027
+
2028
+ - `trimChatPrompt()` function to fit chat prompts into the context window and leave enough space for the completion.
2029
+ - `maxCompletionTokens` property on TextGenerationModels.
2030
+
2031
+ ### Changed
2032
+
2033
+ - Renamed `withMaxTokens` to `withMaxCompletionTokens` on TextGenerationModels.
2034
+
2035
+ ### Removed
2036
+
2037
+ - `composeRecentMessagesOpenAIChatPrompt` function (use `trimChatPrompt` instead).
2038
+
2039
+ ## v0.0.41 - 2023-07-30
2040
+
2041
+ ### Added
2042
+
2043
+ - ChatPrompt concept (with chat prompt mappings for text, OpenAI chat, and Llama 2 prompts).
2044
+
2045
+ ### Changed
2046
+
2047
+ - Renamed prompt mappings and changed into functions.
2048
+
2049
+ ## v0.0.40 - 2023-07-30
2050
+
2051
+ ### Added
2052
+
2053
+ - Prompt mapping support for text generation and streaming.
2054
+ - Added instruction prompt concept and mapping.
2055
+ - Option to specify context window size for Llama.cpp text generation models.
2056
+
2057
+ ### Changed
2058
+
2059
+ - Renamed 'maxTokens' to 'contextWindowSize' where applicable.
2060
+ - Restructured how tokenizers are exposed by text generation models.
2061
+
2062
+ ## v0.0.39 - 2023-07-26
2063
+
2064
+ ### Added
2065
+
2066
+ - llama.cpp embedding support.
2067
+
2068
+ ## v0.0.38 - 2023-07-24
2069
+
2070
+ ### Changed
2071
+
2072
+ - `zod` and `zod-to-json-schema` are peer dependencies and no longer included in the package.
2073
+
2074
+ ## v0.0.37 - 2023-07-23
2075
+
2076
+ ### Changed
2077
+
2078
+ - `generateJsonOrText`, `useToolOrGenerateText`, `useTool` return additional information in the response (e.g. the parameters and additional text).
2079
+
2080
+ ## v0.0.36 - 2023-07-23
2081
+
2082
+ ### Changed
2083
+
2084
+ - Renamed `callTool` to `useTool` and `callToolOrGenerateText` to `useToolOrGenerateText`.
2085
+
2086
+ ## v0.0.35 - 2023-07-22
2087
+
2088
+ ### Added
2089
+
2090
+ - `generateJsonOrText`
2091
+ - Tools: `Tool` class, `callTool`, `callToolOrGenerateText`
2092
+
2093
+ ### Changed
2094
+
2095
+ - Restructured "generateJson" arguments.
2096
+
2097
+ ## v0.0.34 - 2023-07-18
2098
+
2099
+ ### Removed
2100
+
2101
+ - `asFunction` model function variants. Use JavaScript lamba functions instead.
2102
+
2103
+ ## v0.0.33 - 2023-07-18
2104
+
2105
+ ### Added
2106
+
2107
+ - OpenAIChatAutoFunctionPrompt to call the OpenAI functions API with multiple functions in 'auto' mode.
2108
+
2109
+ ## v0.0.32 - 2023-07-15
2110
+
2111
+ ### Changed
2112
+
2113
+ - Changed the prompt format of the generateJson function.
2114
+
2115
+ ## v0.0.31 - 2023-07-14
2116
+
2117
+ ### Changed
2118
+
2119
+ - Reworked interaction with vectors stores. Removed VectorDB, renamed VectorStore to VectorIndex, and introduced upsertTextChunks and retrieveTextChunks functions.
2120
+
2121
+ ## v0.0.30 - 2023-07-13
2122
+
2123
+ ### Fixed
2124
+
2125
+ - Bugs related to performance. not being available.
2126
+
2127
+ ## v0.0.29 - 2023-07-13
2128
+
2129
+ ### Added
2130
+
2131
+ - Llama.cpp tokenization support.
2132
+
2133
+ ### Changed
2134
+
2135
+ - Split Tokenizer API into BasicTokenizer and FullTokenizer.
2136
+ - Introduce countTokens function (replacing Tokenizer.countTokens).
2137
+
2138
+ ## v0.0.28 - 2023-07-12
2139
+
2140
+ ### Added
2141
+
2142
+ - Events for streamText.
2143
+
2144
+ ## v0.0.27 - 2023-07-11
2145
+
2146
+ ### Added
2147
+
2148
+ - TextDeltaEventSource for Client/Server streaming support.
2149
+
2150
+ ### Fixed
2151
+
2152
+ - End-of-stream bug in Llama.cpp text streaming.
2153
+
2154
+ ## v0.0.26 - 2023-07-11
2155
+
2156
+ ### Added
2157
+
2158
+ - Streaming support for Cohere text generation models.
2159
+
2160
+ ## v0.0.25 - 2023-07-10
2161
+
2162
+ ### Added
2163
+
2164
+ - Streaming support for OpenAI text completion models.
2165
+ - OpenAI function streaming support (in low-level API).
2166
+
2167
+ ## v0.0.24 - 2023-07-09
2168
+
2169
+ ### Added
2170
+
2171
+ - Generalized text streaming (async string iterable, useful for command line streaming).
2172
+ - Streaming support for Llama.cpp text generation.
2173
+
2174
+ ## v0.0.23 - 2023-07-08
2175
+
2176
+ ### Added
2177
+
2178
+ - Llama.cpp text generation support.
2179
+
2180
+ ## v0.0.22 - 2023-07-08
2181
+
2182
+ ### Changed
2183
+
2184
+ - Convert all main methods (e.g. `model.generateText(...)`) to a functional API (i.e., `generateText(model, ...)`).
2185
+
2186
+ ## v0.0.21 - 2023-07-07
2187
+
2188
+ ### New
2189
+
2190
+ - JSON generation model.
2191
+
2192
+ ## v0.0.20 - 2023-07-02
2193
+
2194
+ ### New
2195
+
2196
+ - Automatic1111 image generation provider.
2197
+
2198
+ ## v0.0.19 - 2023-06-30
2199
+
2200
+ ### New
2201
+
2202
+ - Cost calculation for OpenAI image generation and transcription models.
2203
+
2204
+ ## v0.0.18 - 2023-06-28
2205
+
2206
+ ### New
2207
+
2208
+ - Cost calculation for Open AI text generation, chat and embedding models.
2209
+
2210
+ ### Changed
2211
+
2212
+ - Renamed RunContext to Run. Introduced DefaultRun.
2213
+ - Changed events and observers.
2214
+
2215
+ ## v0.0.17 - 2023-06-14
2216
+
2217
+ ### New
2218
+
2219
+ 1. Updated OpenAI models.
2220
+ 1. Low-level support for OpenAI chat functions API (via `OpenAIChatModel.callApi`).
2221
+ 1. TranscriptionModel and OpenAITranscriptionModel (using `whisper`)
2222
+
2223
+ ### Changed
2224
+
2225
+ 1. Single optional parameter for functions/method that contains run, functionId, etc.
2226
+
2227
+ ## v0.0.16 - 2023-06-13
2228
+
2229
+ ### Fixed
2230
+
2231
+ 1. Retry is not attempted when you ran out of OpenAI credits.
2232
+ 1. Vercel edge function support (switched to nanoid for unique IDs).
2233
+
2234
+ ### Changed
2235
+
2236
+ 1. Improved OpenAI chat streaming API.
2237
+ 1. Changed `asFunction` variants from namespaced functions into stand-alone functions.
2238
+
2239
+ ## v0.0.15 - 2023-06-12
2240
+
2241
+ ### Changed
2242
+
2243
+ 1. Documentation update.
2244
+
2245
+ ## v0.0.14 - 2023-06-11
2246
+
2247
+ ### Changed
2248
+
2249
+ 1. Major rework of embedding APIs.
2250
+
2251
+ ## v0.0.13 - 2023-06-10
2252
+
2253
+ ### Changed
2254
+
2255
+ 1. Major rework of text and image generation APIs.
2256
+
2257
+ ## v0.0.12 - 2023-06-06
2258
+
2259
+ ## v0.0.11 - 2023-06-05
2260
+
2261
+ ### Changed
2262
+
2263
+ 1. Various renames.
2264
+
2265
+ ## v0.0.10 - 2023-06-04
2266
+
2267
+ ### New
2268
+
2269
+ 1. Pinecone VectorDB support
2270
+ 1. Cohere tokenization support
2271
+
2272
+ ## v0.0.9 - 2023-06-03
2273
+
2274
+ ### New
2275
+
2276
+ 1. OpenAI DALL-E image generation support
2277
+ 1. `generateImage` function
2278
+ 1. Throttling and retries on model level
2279
+
2280
+ ## v0.0.8 - 2023-06-02
2281
+
2282
+ ### New
2283
+
2284
+ 1. Stability AI image generation support
2285
+ 1. Image generation Next.js example
2286
+
2287
+ ### Changed
2288
+
2289
+ 1. Updated PDF to tweet example with style transfer
2290
+
2291
+ ## v0.0.7 - 2023-06-01
2292
+
2293
+ ### New
2294
+
2295
+ 1. Hugging Face text generation support
2296
+ 1. Memory vector DB
2297
+
2298
+ ## v0.0.6 - 2023-05-31
2299
+
2300
+ ### New
2301
+
2302
+ 1. Cohere embedding API support
2303
+
2304
+ ### Changes
2305
+
2306
+ 1. Restructured retry logic
2307
+ 1. `embed` embeds many texts at once
2308
+
2309
+ ## v0.0.5 - 2023-05-30
2310
+
2311
+ ### New
2312
+
2313
+ 1. Cohere text generation support
2314
+ 1. OpenAI chat streams can be returned as delta async iterables
2315
+ 1. Documentation of integration APIs and models
2316
+
2317
+ ## v0.0.4 - 2023-05-29
2318
+
2319
+ ### New
2320
+
2321
+ 1. OpenAI embedding support
2322
+ 1. Text embedding functions
2323
+ 1. Chat streams can be returned as ReadableStream or AsyncIterable
2324
+ 1. Basic examples under `examples/basic`
2325
+ 1. Initial documentation available at [modelfusion.dev](https://modelfusion.dev)
2326
+
2327
+ ## v0.0.3 - 2023-05-28
2328
+
2329
+ ### New
2330
+
2331
+ 1. Voice recording and transcription Next.js app example.
2332
+ 1. OpenAI transcription support (Whisper).
2333
+
2334
+ ## v0.0.2 - 2023-05-27
2335
+
2336
+ ### New
2337
+
2338
+ 1. BabyAGI Example in TypeScript
2339
+ 1. TikToken for OpenAI: We've added tiktoken to aid in tokenization and token counting, including those for message and prompt overhead tokens in chat.
2340
+ 1. Tokenization-based Recursive Splitter: A new splitter that operates recursively using tokenization.
2341
+ 1. Prompt Management Utility: An enhancement to fit recent chat messages into the context window.
2342
+
2343
+ ## v0.0.1 - 2023-05-26
2344
+
2345
+ ### New
2346
+
2347
+ 1. AI Chat Example using Next.js: An example demonstrating AI chat implementation using Next.js.
2348
+ 1. PDF to Twitter Thread Example: This shows how a PDF can be converted into a Twitter thread.
2349
+ 1. OpenAI Chat Completion Streaming Support: A feature providing real-time response capabilities using OpenAI's chat completion streaming.
2350
+ 1. OpenAI Chat and Text Completion Support: This addition enables the software to handle both chat and text completions from OpenAI.
2351
+ 1. Retry Management: A feature to enhance resilience by managing retry attempts for tasks.
2352
+ 1. Task Progress Reporting and Abort Signals: This allows users to track the progress of tasks and gives the ability to abort tasks when needed.
2353
+ 1. Recursive Character Splitter: A feature to split text into characters recursively for more detailed text analysis.
2354
+ 1. Recursive Text Mapping: This enables recursive mapping of text, beneficial for tasks like summarization or extraction.
2355
+ 1. Split-Map-Filter-Reduce for Text Processing: A process chain developed for sophisticated text handling, allowing operations to split, map, filter, and reduce text data.
2356
+
2357
+ ```
2358
+
2359
+ ```