modelfusion 0.75.0 → 0.77.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 CHANGED
@@ -50,6 +50,8 @@ You can use [prompt formats](https://modelfusion.dev/guide/function/generate-tex
50
50
  #### generateText
51
51
 
52
52
  ```ts
53
+ import { generateText, openai } from "modelfusion";
54
+
53
55
  const text = await generateText(
54
56
  openai.CompletionTextGenerator({ model: "gpt-3.5-turbo-instruct" }),
55
57
  "Write a short story about a robot learning to love:\n\n"
@@ -61,6 +63,8 @@ Providers: [OpenAI](https://modelfusion.dev/integration/model-provider/openai),
61
63
  #### streamText
62
64
 
63
65
  ```ts
66
+ import { streamText, openai } from "modelfusion";
67
+
64
68
  const textStream = await streamText(
65
69
  openai.CompletionTextGenerator({ model: "gpt-3.5-turbo-instruct" }),
66
70
  "Write a short story about a robot learning to love:\n\n"
@@ -78,6 +82,8 @@ Providers: [OpenAI](https://modelfusion.dev/integration/model-provider/openai),
78
82
  Multi-modal vision models such as GPT 4 Vision can process images as part of the prompt.
79
83
 
80
84
  ```ts
85
+ import { streamText, openai } from "modelfusion";
86
+
81
87
  const textStream = await streamText(
82
88
  openai.ChatTextGenerator({ model: "gpt-4-vision-preview" }),
83
89
  [
@@ -95,6 +101,8 @@ Providers: [OpenAI](https://modelfusion.dev/integration/model-provider/openai),
95
101
  Generate an image from a prompt.
96
102
 
97
103
  ```ts
104
+ import { generateImage, openai } from "modelfusion";
105
+
98
106
  const image = await generateImage(
99
107
  openai.ImageGenerator({ model: "dall-e-3", size: "1024x1024" }),
100
108
  "the wicked witch of the west in the style of early 19th century painting"
@@ -112,9 +120,11 @@ Synthesize speech (audio) from text. Also called TTS (text-to-speech).
112
120
  `generateSpeech` synthesizes speech from text.
113
121
 
114
122
  ```ts
123
+ import { generateSpeech, lmnt } from "modelfusion";
124
+
115
125
  // `speech` is a Buffer with MP3 audio data
116
126
  const speech = await generateSpeech(
117
- lmnt.Speech({
127
+ lmnt.SpeechGenerator({
118
128
  voice: "034b632b-df71-46c8-b440-86a42ffc3cf3", // Henry
119
129
  }),
120
130
  "Good evening, ladies and gentlemen! Exciting news on the airwaves tonight " +
@@ -131,10 +141,12 @@ Providers: [Eleven Labs](https://modelfusion.dev/integration/model-provider/elev
131
141
  `generateSpeech` generates a stream of speech chunks from text or from a text stream. Depending on the model, this can be fully duplex.
132
142
 
133
143
  ```ts
134
- const textStream = await streamText(/* ... */);
144
+ import { streamSpeech, elevenlabs } from "modelfusion";
145
+
146
+ const textStream: AsyncIterable<string>;
135
147
 
136
148
  const speechStream = await streamSpeech(
137
- elevenlabs.Speech({
149
+ elevenlabs.SpeechGenerator({
138
150
  model: "eleven_turbo_v2",
139
151
  voice: "pNInz6obpgDQGcFmaJgB", // Adam
140
152
  optimizeStreamingLatency: 1,
@@ -158,8 +170,10 @@ Providers: [Eleven Labs](https://modelfusion.dev/integration/model-provider/elev
158
170
  Transcribe speech (audio) data into text. Also called speech-to-text (STT).
159
171
 
160
172
  ```ts
173
+ import { generateTranscription, openai } from "modelfusion";
174
+
161
175
  const transcription = await generateTranscription(
162
- openai.Transcription({ model: "whisper-1" }),
176
+ openai.Transcriber({ model: "whisper-1" }),
163
177
  {
164
178
  type: "mp3",
165
179
  data: await fs.promises.readFile("data/test.mp3"),
@@ -9,7 +9,7 @@ import { SpeechGenerationModel, SpeechGenerationModelSettings } from "./SpeechGe
9
9
  *
10
10
  * @example
11
11
  * const speech = await generateSpeech(
12
- * lmnt.Speech(...),
12
+ * lmnt.SpeechGenerator(...),
13
13
  * "Good evening, ladies and gentlemen! Exciting news on the airwaves tonight " +
14
14
  * "as The Rolling Stones unveil 'Hackney Diamonds.'
15
15
  * );
@@ -12,7 +12,7 @@ import { SpeechGenerationModelSettings, StreamingSpeechGenerationModel } from ".
12
12
  * const textStream = await streamText(...);
13
13
  *
14
14
  * const speechStream = await streamSpeech(
15
- * elevenlabs.Speech(...),
15
+ * elevenlabs.SpeechGenerator(...),
16
16
  * textStream
17
17
  * );
18
18
  *
@@ -10,7 +10,7 @@ import { TranscriptionModel, TranscriptionModelSettings } from "./TranscriptionM
10
10
  * const data = await fs.promises.readFile("data/test.mp3");
11
11
  *
12
12
  * const transcription = await generateTranscription(
13
- * openai.Transcription({ model: "whisper-1" }),
13
+ * openai.Transcriber({ model: "whisper-1" }),
14
14
  * { type: "mp3", data }
15
15
  * );
16
16
  *
@@ -24,10 +24,7 @@ exports.text = text;
24
24
  function instruction() {
25
25
  return {
26
26
  format: (instruction) => {
27
- let text = "";
28
- if (instruction.system != null) {
29
- text += `${instruction.system}`;
30
- }
27
+ let text = instruction.system ?? "";
31
28
  text += "\n\nHuman:";
32
29
  text += instruction.instruction;
33
30
  text += "\n\nAssistant:";
@@ -46,7 +43,7 @@ function chat() {
46
43
  return {
47
44
  format: (chatPrompt) => {
48
45
  (0, validateChatPrompt_js_1.validateChatPrompt)(chatPrompt);
49
- let text = chatPrompt.system != null ? `${chatPrompt.system}\n\n` : "";
46
+ let text = chatPrompt.system ?? "";
50
47
  for (const { role, content } of chatPrompt.messages) {
51
48
  switch (role) {
52
49
  case "user": {
@@ -20,10 +20,7 @@ export function text() {
20
20
  export function instruction() {
21
21
  return {
22
22
  format: (instruction) => {
23
- let text = "";
24
- if (instruction.system != null) {
25
- text += `${instruction.system}`;
26
- }
23
+ let text = instruction.system ?? "";
27
24
  text += "\n\nHuman:";
28
25
  text += instruction.instruction;
29
26
  text += "\n\nAssistant:";
@@ -41,7 +38,7 @@ export function chat() {
41
38
  return {
42
39
  format: (chatPrompt) => {
43
40
  validateChatPrompt(chatPrompt);
44
- let text = chatPrompt.system != null ? `${chatPrompt.system}\n\n` : "";
41
+ let text = chatPrompt.system ?? "";
45
42
  for (const { role, content } of chatPrompt.messages) {
46
43
  switch (role) {
47
44
  case "user": {
@@ -21,11 +21,14 @@ exports.ANTHROPIC_TEXT_GENERATION_MODELS = {
21
21
  contextWindowSize: 100000,
22
22
  },
23
23
  "claude-2": {
24
- contextWindowSize: 100000,
24
+ contextWindowSize: 200000,
25
25
  },
26
26
  "claude-2.0": {
27
27
  contextWindowSize: 100000,
28
28
  },
29
+ "claude-2.1": {
30
+ contextWindowSize: 200000,
31
+ },
29
32
  };
30
33
  /**
31
34
  * Create a text generation model that calls the Anthropic API.
@@ -20,6 +20,9 @@ export declare const ANTHROPIC_TEXT_GENERATION_MODELS: {
20
20
  "claude-2.0": {
21
21
  contextWindowSize: number;
22
22
  };
23
+ "claude-2.1": {
24
+ contextWindowSize: number;
25
+ };
23
26
  };
24
27
  export type AnthropicTextGenerationModelType = keyof typeof ANTHROPIC_TEXT_GENERATION_MODELS;
25
28
  export interface AnthropicTextGenerationModelSettings extends TextGenerationModelSettings {
@@ -38,7 +41,7 @@ export interface AnthropicTextGenerationModelSettings extends TextGenerationMode
38
41
  export declare class AnthropicTextGenerationModel extends AbstractModel<AnthropicTextGenerationModelSettings> implements TextStreamingModel<string, AnthropicTextGenerationModelSettings> {
39
42
  constructor(settings: AnthropicTextGenerationModelSettings);
40
43
  readonly provider: "anthropic";
41
- get modelName(): "claude-instant-1" | "claude-instant-1.2" | "claude-2" | "claude-2.0";
44
+ get modelName(): "claude-instant-1" | "claude-instant-1.2" | "claude-2" | "claude-2.0" | "claude-2.1";
42
45
  readonly contextWindowSize: number;
43
46
  readonly tokenizer: undefined;
44
47
  readonly countPromptTokens: undefined;
@@ -18,11 +18,14 @@ export const ANTHROPIC_TEXT_GENERATION_MODELS = {
18
18
  contextWindowSize: 100000,
19
19
  },
20
20
  "claude-2": {
21
- contextWindowSize: 100000,
21
+ contextWindowSize: 200000,
22
22
  },
23
23
  "claude-2.0": {
24
24
  contextWindowSize: 100000,
25
25
  },
26
+ "claude-2.1": {
27
+ contextWindowSize: 200000,
28
+ },
26
29
  };
27
30
  /**
28
31
  * Create a text generation model that calls the Anthropic API.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Speech = void 0;
3
+ exports.SpeechGenerator = void 0;
4
4
  const ElevenLabsSpeechModel_js_1 = require("./ElevenLabsSpeechModel.cjs");
5
5
  /**
6
6
  * Synthesize speech using the ElevenLabs Text to Speech API.
@@ -12,7 +12,7 @@ const ElevenLabsSpeechModel_js_1 = require("./ElevenLabsSpeechModel.cjs");
12
12
  *
13
13
  * @returns A new instance of {@link ElevenLabsSpeechModel}.
14
14
  */
15
- function Speech(settings) {
15
+ function SpeechGenerator(settings) {
16
16
  return new ElevenLabsSpeechModel_js_1.ElevenLabsSpeechModel(settings);
17
17
  }
18
- exports.Speech = Speech;
18
+ exports.SpeechGenerator = SpeechGenerator;
@@ -9,4 +9,4 @@ import { ElevenLabsSpeechModel, ElevenLabsSpeechModelSettings } from "./ElevenLa
9
9
  *
10
10
  * @returns A new instance of {@link ElevenLabsSpeechModel}.
11
11
  */
12
- export declare function Speech(settings: ElevenLabsSpeechModelSettings): ElevenLabsSpeechModel;
12
+ export declare function SpeechGenerator(settings: ElevenLabsSpeechModelSettings): ElevenLabsSpeechModel;
@@ -9,6 +9,6 @@ import { ElevenLabsSpeechModel, } from "./ElevenLabsSpeechModel.js";
9
9
  *
10
10
  * @returns A new instance of {@link ElevenLabsSpeechModel}.
11
11
  */
12
- export function Speech(settings) {
12
+ export function SpeechGenerator(settings) {
13
13
  return new ElevenLabsSpeechModel(settings);
14
14
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Speech = void 0;
3
+ exports.SpeechGenerator = void 0;
4
4
  const LmntSpeechModel_js_1 = require("./LmntSpeechModel.cjs");
5
5
  /**
6
6
  * Synthesize speech using the LMNT API.
@@ -9,7 +9,7 @@ const LmntSpeechModel_js_1 = require("./LmntSpeechModel.cjs");
9
9
  *
10
10
  * @returns A new instance of {@link LmntSpeechModel}.
11
11
  */
12
- function Speech(settings) {
12
+ function SpeechGenerator(settings) {
13
13
  return new LmntSpeechModel_js_1.LmntSpeechModel(settings);
14
14
  }
15
- exports.Speech = Speech;
15
+ exports.SpeechGenerator = SpeechGenerator;
@@ -6,4 +6,4 @@ import { LmntSpeechModel, LmntSpeechModelSettings } from "./LmntSpeechModel.js";
6
6
  *
7
7
  * @returns A new instance of {@link LmntSpeechModel}.
8
8
  */
9
- export declare function Speech(settings: LmntSpeechModelSettings): LmntSpeechModel;
9
+ export declare function SpeechGenerator(settings: LmntSpeechModelSettings): LmntSpeechModel;
@@ -6,6 +6,6 @@ import { LmntSpeechModel } from "./LmntSpeechModel.js";
6
6
  *
7
7
  * @returns A new instance of {@link LmntSpeechModel}.
8
8
  */
9
- export function Speech(settings) {
9
+ export function SpeechGenerator(settings) {
10
10
  return new LmntSpeechModel(settings);
11
11
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Tokenizer = exports.ImageGenerator = exports.Transcription = exports.Speech = exports.TextEmbedder = exports.ChatTextGenerator = exports.CompletionTextGenerator = void 0;
3
+ exports.Tokenizer = exports.ImageGenerator = exports.Transcriber = exports.SpeechGenerator = exports.TextEmbedder = exports.ChatTextGenerator = exports.CompletionTextGenerator = void 0;
4
4
  const OpenAICompletionModel_js_1 = require("./OpenAICompletionModel.cjs");
5
5
  const OpenAIImageGenerationModel_js_1 = require("./OpenAIImageGenerationModel.cjs");
6
6
  const OpenAISpeechModel_js_1 = require("./OpenAISpeechModel.cjs");
@@ -82,10 +82,10 @@ exports.TextEmbedder = TextEmbedder;
82
82
  *
83
83
  * @returns A new instance of {@link OpenAISpeechModel}.
84
84
  */
85
- function Speech(settings) {
85
+ function SpeechGenerator(settings) {
86
86
  return new OpenAISpeechModel_js_1.OpenAISpeechModel(settings);
87
87
  }
88
- exports.Speech = Speech;
88
+ exports.SpeechGenerator = SpeechGenerator;
89
89
  /**
90
90
  * Create a transcription model that calls the OpenAI transcription API.
91
91
  *
@@ -95,7 +95,7 @@ exports.Speech = Speech;
95
95
  * const data = await fs.promises.readFile("data/test.mp3");
96
96
  *
97
97
  * const transcription = await transcribe(
98
- * openai.Transcription({ model: "whisper-1" }),
98
+ * openai.Transcriber({ model: "whisper-1" }),
99
99
  * {
100
100
  * type: "mp3",
101
101
  * data,
@@ -104,10 +104,10 @@ exports.Speech = Speech;
104
104
  *
105
105
  * @returns A new instance of {@link OpenAITranscriptionModel}.
106
106
  */
107
- function Transcription(settings) {
107
+ function Transcriber(settings) {
108
108
  return new OpenAITranscriptionModel_js_1.OpenAITranscriptionModel(settings);
109
109
  }
110
- exports.Transcription = Transcription;
110
+ exports.Transcriber = Transcriber;
111
111
  /**
112
112
  * Create an image generation model that calls the OpenAI AI image creation API.
113
113
  *
@@ -70,7 +70,7 @@ export declare function TextEmbedder(settings: OpenAITextEmbeddingModelSettings)
70
70
  *
71
71
  * @returns A new instance of {@link OpenAISpeechModel}.
72
72
  */
73
- export declare function Speech(settings: OpenAISpeechModelSettings): OpenAISpeechModel;
73
+ export declare function SpeechGenerator(settings: OpenAISpeechModelSettings): OpenAISpeechModel;
74
74
  /**
75
75
  * Create a transcription model that calls the OpenAI transcription API.
76
76
  *
@@ -80,7 +80,7 @@ export declare function Speech(settings: OpenAISpeechModelSettings): OpenAISpeec
80
80
  * const data = await fs.promises.readFile("data/test.mp3");
81
81
  *
82
82
  * const transcription = await transcribe(
83
- * openai.Transcription({ model: "whisper-1" }),
83
+ * openai.Transcriber({ model: "whisper-1" }),
84
84
  * {
85
85
  * type: "mp3",
86
86
  * data,
@@ -89,7 +89,7 @@ export declare function Speech(settings: OpenAISpeechModelSettings): OpenAISpeec
89
89
  *
90
90
  * @returns A new instance of {@link OpenAITranscriptionModel}.
91
91
  */
92
- export declare function Transcription(settings: OpenAITranscriptionModelSettings): OpenAITranscriptionModel;
92
+ export declare function Transcriber(settings: OpenAITranscriptionModelSettings): OpenAITranscriptionModel;
93
93
  /**
94
94
  * Create an image generation model that calls the OpenAI AI image creation API.
95
95
  *
@@ -76,7 +76,7 @@ export function TextEmbedder(settings) {
76
76
  *
77
77
  * @returns A new instance of {@link OpenAISpeechModel}.
78
78
  */
79
- export function Speech(settings) {
79
+ export function SpeechGenerator(settings) {
80
80
  return new OpenAISpeechModel(settings);
81
81
  }
82
82
  /**
@@ -88,7 +88,7 @@ export function Speech(settings) {
88
88
  * const data = await fs.promises.readFile("data/test.mp3");
89
89
  *
90
90
  * const transcription = await transcribe(
91
- * openai.Transcription({ model: "whisper-1" }),
91
+ * openai.Transcriber({ model: "whisper-1" }),
92
92
  * {
93
93
  * type: "mp3",
94
94
  * data,
@@ -97,7 +97,7 @@ export function Speech(settings) {
97
97
  *
98
98
  * @returns A new instance of {@link OpenAITranscriptionModel}.
99
99
  */
100
- export function Transcription(settings) {
100
+ export function Transcriber(settings) {
101
101
  return new OpenAITranscriptionModel(settings);
102
102
  }
103
103
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "modelfusion",
3
3
  "description": "The TypeScript library for building multi-modal AI applications.",
4
- "version": "0.75.0",
4
+ "version": "0.77.0",
5
5
  "author": "Lars Grammel",
6
6
  "license": "MIT",
7
7
  "keywords": [