modelfusion 0.127.0 → 0.129.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/README.md +7 -13
  3. package/core/api/postToApi.cjs +2 -2
  4. package/core/api/postToApi.d.ts +2 -3
  5. package/core/api/postToApi.js +2 -2
  6. package/core/getFunctionCallLogger.cjs +2 -2
  7. package/core/getFunctionCallLogger.js +2 -2
  8. package/core/getRun.cjs +2 -1
  9. package/core/getRun.js +2 -1
  10. package/model-function/generate-image/generateImage.cjs +2 -1
  11. package/model-function/generate-image/generateImage.d.ts +4 -5
  12. package/model-function/generate-image/generateImage.js +2 -1
  13. package/model-function/generate-speech/SpeechGenerationEvent.d.ts +1 -2
  14. package/model-function/generate-speech/SpeechGenerationModel.d.ts +3 -4
  15. package/model-function/generate-speech/generateSpeech.d.ts +3 -4
  16. package/model-function/generate-speech/streamSpeech.d.ts +3 -4
  17. package/model-function/generate-text/prompt-template/ContentPart.cjs +9 -1
  18. package/model-function/generate-text/prompt-template/ContentPart.d.ts +3 -2
  19. package/model-function/generate-text/prompt-template/ContentPart.js +7 -0
  20. package/model-provider/elevenlabs/ElevenLabsSpeechModel.cjs +2 -1
  21. package/model-provider/elevenlabs/ElevenLabsSpeechModel.d.ts +2 -3
  22. package/model-provider/elevenlabs/ElevenLabsSpeechModel.js +2 -1
  23. package/model-provider/llamacpp/LlamaCppBakLLaVA1PromptTemplate.cjs +2 -2
  24. package/model-provider/llamacpp/LlamaCppBakLLaVA1PromptTemplate.js +3 -3
  25. package/model-provider/lmnt/LmntSpeechModel.cjs +2 -1
  26. package/model-provider/lmnt/LmntSpeechModel.d.ts +1 -2
  27. package/model-provider/lmnt/LmntSpeechModel.js +2 -1
  28. package/model-provider/ollama/OllamaChatPromptTemplate.cjs +1 -1
  29. package/model-provider/ollama/OllamaChatPromptTemplate.js +2 -2
  30. package/model-provider/openai/OpenAIChatMessage.cjs +5 -4
  31. package/model-provider/openai/OpenAIChatMessage.js +5 -4
  32. package/model-provider/openai/OpenAISpeechModel.d.ts +1 -2
  33. package/model-provider/openai/OpenAITranscriptionModel.d.ts +1 -2
  34. package/model-provider/openai-compatible/FireworksAIApiConfiguration.cjs +6 -0
  35. package/model-provider/openai-compatible/FireworksAIApiConfiguration.d.ts +3 -1
  36. package/model-provider/openai-compatible/FireworksAIApiConfiguration.js +6 -0
  37. package/model-provider/openai-compatible/OpenAICompatibleApiConfiguration.d.ts +5 -0
  38. package/model-provider/openai-compatible/OpenAICompatibleChatModel.cjs +1 -1
  39. package/model-provider/openai-compatible/OpenAICompatibleChatModel.d.ts +2 -3
  40. package/model-provider/openai-compatible/OpenAICompatibleChatModel.js +1 -1
  41. package/model-provider/openai-compatible/OpenAICompatibleCompletionModel.cjs +1 -1
  42. package/model-provider/openai-compatible/OpenAICompatibleCompletionModel.d.ts +2 -3
  43. package/model-provider/openai-compatible/OpenAICompatibleCompletionModel.js +1 -1
  44. package/model-provider/openai-compatible/OpenAICompatibleTextEmbeddingModel.cjs +1 -1
  45. package/model-provider/openai-compatible/OpenAICompatibleTextEmbeddingModel.d.ts +2 -3
  46. package/model-provider/openai-compatible/OpenAICompatibleTextEmbeddingModel.js +1 -1
  47. package/model-provider/openai-compatible/PerplexityApiConfiguration.cjs +6 -0
  48. package/model-provider/openai-compatible/PerplexityApiConfiguration.d.ts +3 -1
  49. package/model-provider/openai-compatible/PerplexityApiConfiguration.js +6 -0
  50. package/model-provider/openai-compatible/TogetherAIApiConfiguration.cjs +6 -0
  51. package/model-provider/openai-compatible/TogetherAIApiConfiguration.d.ts +3 -1
  52. package/model-provider/openai-compatible/TogetherAIApiConfiguration.js +6 -0
  53. package/model-provider/openai-compatible/index.cjs +1 -1
  54. package/model-provider/openai-compatible/index.d.ts +1 -1
  55. package/model-provider/openai-compatible/index.js +1 -1
  56. package/model-provider/stability/StabilityImageGenerationModel.d.ts +5 -5
  57. package/model-provider/whispercpp/WhisperCppTranscriptionModel.d.ts +1 -2
  58. package/package.json +2 -2
  59. package/util/UInt8Utils.cjs +50 -0
  60. package/util/UInt8Utils.d.ts +3 -0
  61. package/util/UInt8Utils.js +44 -0
  62. package/model-provider/openai-compatible/OpenAICompatibleProviderName.d.ts +0 -1
  63. /package/model-provider/openai-compatible/{OpenAICompatibleProviderName.cjs → OpenAICompatibleApiConfiguration.cjs} +0 -0
  64. /package/model-provider/openai-compatible/{OpenAICompatibleProviderName.js → OpenAICompatibleApiConfiguration.js} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,59 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.129.0 - 2024-01-20
4
+
5
+ ### Changed
6
+
7
+ - **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`):
8
+
9
+ ```js
10
+ /**
11
+ * @type {import('next').NextConfig}
12
+ */
13
+ const nextConfig = {
14
+ webpack: (config, { isServer }) => {
15
+ if (isServer) {
16
+ return config;
17
+ }
18
+
19
+ config.resolve = config.resolve ?? {};
20
+ config.resolve.fallback = config.resolve.fallback ?? {};
21
+
22
+ // async hooks is not available in the browser:
23
+ config.resolve.fallback.async_hooks = false;
24
+
25
+ return config;
26
+ },
27
+ };
28
+ ```
29
+
30
+ ## v0.128.0 - 2024-01-20
31
+
32
+ ### Changed
33
+
34
+ - **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.
35
+ - **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:
36
+
37
+ ```ts
38
+ const image = fs.readFileSync(path.join("data", "example-image.png"));
39
+
40
+ const textStream = await streamText({
41
+ model: openai.ChatTextGenerator({
42
+ model: "gpt-4-vision-preview",
43
+ maxGenerationTokens: 1000,
44
+ }),
45
+
46
+ prompt: [
47
+ openai.ChatMessage.user([
48
+ { type: "text", text: "Describe the image in detail:\n\n" },
49
+ { type: "image", image, mimeType: "image/png" },
50
+ ]),
51
+ ],
52
+ });
53
+ ```
54
+
55
+ - OpenAI-compatible providers with predefined API configurations have a customized provider name that shows up in the events.
56
+
3
57
  ## v0.127.0 - 2024-01-15
4
58
 
5
59
  ### Changed
package/README.md CHANGED
@@ -86,14 +86,14 @@ Multi-modal vision models such as GPT 4 Vision can process images as part of the
86
86
  import { streamText, openai } from "modelfusion";
87
87
  import { readFileSync } from "fs";
88
88
 
89
- const image = readFileSync("./image.png").toString("base64");
89
+ const image = readFileSync("./image.png");
90
90
 
91
91
  const textStream = await streamText({
92
92
  model: openai.ChatTextGenerator({ model: "gpt-4-vision-preview" }),
93
93
  prompt: [
94
94
  openai.ChatMessage.user([
95
95
  { type: "text", text: "Describe the image in detail:" },
96
- { type: "image", base64Image: image, mimeType: "image/png" },
96
+ { type: "image", image, mimeType: "image/png" },
97
97
  ]),
98
98
  ],
99
99
  });
@@ -219,7 +219,7 @@ Synthesize speech (audio) from text. Also called TTS (text-to-speech).
219
219
  ```ts
220
220
  import { generateSpeech, lmnt } from "modelfusion";
221
221
 
222
- // `speech` is a Buffer with MP3 audio data
222
+ // `speech` is a Uint8Array with MP3 audio data
223
223
  const speech = await generateSpeech({
224
224
  model: lmnt.SpeechGenerator({
225
225
  voice: "034b632b-df71-46c8-b440-86a42ffc3cf3", // Henry
@@ -257,7 +257,7 @@ const speechStream = await streamSpeech({
257
257
  });
258
258
 
259
259
  for await (const part of speechStream) {
260
- // each part is a Buffer with MP3 audio data
260
+ // each part is a Uint8Array with MP3 audio data
261
261
  }
262
262
  ```
263
263
 
@@ -635,17 +635,11 @@ A web chat with an AI assistant, implemented as a Next.js app.
635
635
 
636
636
  Ask questions about a PDF document and get answers from the document.
637
637
 
638
- ### [Image generator (Next.js)](https://github.com/lgrammel/modelfusion/tree/main/examples/image-generator-next-js)
638
+ ### [Next.js / ModelFusion Demos](https://github.com/lgrammel/modelfusion/tree/main/examples/nextjs)
639
639
 
640
- > _Next.js app_, _Stability AI image generation_
640
+ > _Next.js app_, _image generation_
641
641
 
642
- Create an 19th century painting image for your input.
643
-
644
- ### [Voice recording and transcription (Next.js)](https://github.com/lgrammel/modelfusion/tree/main/examples/voice-recording-next-js)
645
-
646
- > _Next.js app_, _OpenAI Whisper_
647
-
648
- Record audio with push-to-talk and transcribe it using Whisper, implemented as a Next.js app. The app shows a list of the transcriptions.
642
+ Various examples of using ModelFusion with Next.js: Image generation, voice recording & transcription.
649
643
 
650
644
  ### [Duplex Speech Streaming (using Vite/React & ModelFusion Server/Fastify)](https://github.com/lgrammel/modelfusion/tree/main/examples/speech-streaming-vite-react-fastify)
651
645
 
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.postToApi = exports.postJsonToApi = exports.createAudioMpegResponseHandler = exports.createTextResponseHandler = exports.createJsonResponseHandler = exports.createTextErrorResponseHandler = exports.createJsonErrorResponseHandler = void 0;
4
+ const UInt8Utils_js_1 = require("../../util/UInt8Utils.cjs");
4
5
  const parseJSON_js_1 = require("../schema/parseJSON.cjs");
5
6
  const ApiCallError_js_1 = require("./ApiCallError.cjs");
6
7
  const createJsonErrorResponseHandler = ({ errorSchema, errorToMessage, isRetryable, }) => async ({ response, url, requestBodyValues }) => {
@@ -86,8 +87,7 @@ const createAudioMpegResponseHandler = () => async ({ response, url, requestBody
86
87
  requestBodyValues,
87
88
  });
88
89
  }
89
- const arrayBuffer = await response.arrayBuffer();
90
- return Buffer.from(arrayBuffer);
90
+ return (0, UInt8Utils_js_1.toUint8Array)(await response.arrayBuffer());
91
91
  };
92
92
  exports.createAudioMpegResponseHandler = createAudioMpegResponseHandler;
93
93
  const postJsonToApi = async ({ url, headers, body, failedResponseHandler, successfulResponseHandler, abortSignal, }) => (0, exports.postToApi)({
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { Schema } from "../schema/Schema.js";
3
2
  import { ApiCallError } from "./ApiCallError.js";
4
3
  export type ResponseHandler<T> = (options: {
@@ -16,7 +15,7 @@ export declare const createTextErrorResponseHandler: ({ isRetryable, }?: {
16
15
  }) => ResponseHandler<ApiCallError>;
17
16
  export declare const createJsonResponseHandler: <T>(responseSchema: Schema<T>) => ResponseHandler<T>;
18
17
  export declare const createTextResponseHandler: () => ResponseHandler<string>;
19
- export declare const createAudioMpegResponseHandler: () => ResponseHandler<Buffer>;
18
+ export declare const createAudioMpegResponseHandler: () => ResponseHandler<Uint8Array>;
20
19
  export declare const postJsonToApi: <T>({ url, headers, body, failedResponseHandler, successfulResponseHandler, abortSignal, }: {
21
20
  url: string;
22
21
  headers?: Record<string, string> | undefined;
@@ -29,7 +28,7 @@ export declare const postToApi: <T>({ url, headers, body, successfulResponseHand
29
28
  url: string;
30
29
  headers?: Record<string, string> | undefined;
31
30
  body: {
32
- content: string | FormData | Buffer;
31
+ content: string | FormData | Uint8Array;
33
32
  values: unknown;
34
33
  };
35
34
  failedResponseHandler: ResponseHandler<Error>;
@@ -1,3 +1,4 @@
1
+ import { toUint8Array } from "../../util/UInt8Utils.js";
1
2
  import { parseJSON, safeParseJSON } from "../schema/parseJSON.js";
2
3
  import { ApiCallError } from "./ApiCallError.js";
3
4
  export const createJsonErrorResponseHandler = ({ errorSchema, errorToMessage, isRetryable, }) => async ({ response, url, requestBodyValues }) => {
@@ -79,8 +80,7 @@ export const createAudioMpegResponseHandler = () => async ({ response, url, requ
79
80
  requestBodyValues,
80
81
  });
81
82
  }
82
- const arrayBuffer = await response.arrayBuffer();
83
- return Buffer.from(arrayBuffer);
83
+ return toUint8Array(await response.arrayBuffer());
84
84
  };
85
85
  export const postJsonToApi = async ({ url, headers, body, failedResponseHandler, successfulResponseHandler, abortSignal, }) => postToApi({
86
86
  url,
@@ -61,8 +61,8 @@ const detailedObjectObserver = {
61
61
  if (v === undefined) {
62
62
  return [k, undefined];
63
63
  }
64
- else if (v instanceof Buffer) {
65
- return [k, "omitted<Buffer>"];
64
+ else if (v instanceof Uint8Array) {
65
+ return [k, "omitted<Uint8Array>"];
66
66
  }
67
67
  else if (Array.isArray(v) &&
68
68
  v.length > 20 &&
@@ -57,8 +57,8 @@ const detailedObjectObserver = {
57
57
  if (v === undefined) {
58
58
  return [k, undefined];
59
59
  }
60
- else if (v instanceof Buffer) {
61
- return [k, "omitted<Buffer>"];
60
+ else if (v instanceof Uint8Array) {
61
+ return [k, "omitted<Uint8Array>"];
62
62
  }
63
63
  else if (Array.isArray(v) &&
64
64
  v.length > 20 &&
package/core/getRun.cjs CHANGED
@@ -34,7 +34,8 @@ async function ensureLoaded() {
34
34
  if (!isNode)
35
35
  return Promise.resolve();
36
36
  if (!runStorage) {
37
- const { AsyncLocalStorage } = await Promise.resolve().then(() => __importStar(require("node:async_hooks")));
37
+ // Note: using "async_hooks" instead of "node:async_hooks" to avoid webpack fallback problems.
38
+ const { AsyncLocalStorage } = await Promise.resolve().then(() => __importStar(require("async_hooks")));
38
39
  runStorage = new AsyncLocalStorage();
39
40
  }
40
41
  return Promise.resolve();
package/core/getRun.js CHANGED
@@ -8,7 +8,8 @@ async function ensureLoaded() {
8
8
  if (!isNode)
9
9
  return Promise.resolve();
10
10
  if (!runStorage) {
11
- const { AsyncLocalStorage } = await import("node:async_hooks");
11
+ // Note: using "async_hooks" instead of "node:async_hooks" to avoid webpack fallback problems.
12
+ const { AsyncLocalStorage } = await import("async_hooks");
12
13
  runStorage = new AsyncLocalStorage();
13
14
  }
14
15
  return Promise.resolve();
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateImage = void 0;
4
+ const UInt8Utils_js_1 = require("../../util/UInt8Utils.cjs");
4
5
  const executeStandardCall_js_1 = require("../executeStandardCall.cjs");
5
6
  async function generateImage({ model, prompt, fullResponse, ...options }) {
6
7
  const callResponse = await (0, executeStandardCall_js_1.executeStandardCall)({
@@ -17,7 +18,7 @@ async function generateImage({ model, prompt, fullResponse, ...options }) {
17
18
  },
18
19
  });
19
20
  const imagesBase64 = callResponse.value;
20
- const images = imagesBase64.map((imageBase64) => Buffer.from(imageBase64, "base64"));
21
+ const images = imagesBase64.map(UInt8Utils_js_1.base64ToUint8Array);
21
22
  return fullResponse
22
23
  ? {
23
24
  image: images[0],
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { FunctionOptions } from "../../core/FunctionOptions.js";
3
2
  import { ModelCallMetadata } from "../ModelCallMetadata.js";
4
3
  import { ImageGenerationModel, ImageGenerationModelSettings } from "./ImageGenerationModel.js";
@@ -23,21 +22,21 @@ import { ImageGenerationModel, ImageGenerationModelSettings } from "./ImageGener
23
22
  * @param {PROMPT} prompt - The prompt to be used for image generation.
24
23
  *
25
24
  * @returns {Promise} - Returns a promise that resolves to the generated image.
26
- * The image is a Buffer containing the image data in PNG format.
25
+ * The image is a Uint8Array containing the image data in PNG format.
27
26
  */
28
27
  export declare function generateImage<PROMPT>(args: {
29
28
  model: ImageGenerationModel<PROMPT, ImageGenerationModelSettings>;
30
29
  prompt: PROMPT;
31
30
  fullResponse?: false;
32
- } & FunctionOptions): Promise<Buffer>;
31
+ } & FunctionOptions): Promise<Uint8Array>;
33
32
  export declare function generateImage<PROMPT>(args: {
34
33
  model: ImageGenerationModel<PROMPT, ImageGenerationModelSettings>;
35
34
  prompt: PROMPT;
36
35
  fullResponse: true;
37
36
  } & FunctionOptions): Promise<{
38
- image: Buffer;
37
+ image: Uint8Array;
39
38
  imageBase64: string;
40
- images: Buffer[];
39
+ images: Uint8Array[];
41
40
  imagesBase64: string[];
42
41
  rawResponse: unknown;
43
42
  metadata: ModelCallMetadata;
@@ -1,3 +1,4 @@
1
+ import { base64ToUint8Array } from "../../util/UInt8Utils.js";
1
2
  import { executeStandardCall } from "../executeStandardCall.js";
2
3
  export async function generateImage({ model, prompt, fullResponse, ...options }) {
3
4
  const callResponse = await executeStandardCall({
@@ -14,7 +15,7 @@ export async function generateImage({ model, prompt, fullResponse, ...options })
14
15
  },
15
16
  });
16
17
  const imagesBase64 = callResponse.value;
17
- const images = imagesBase64.map((imageBase64) => Buffer.from(imageBase64, "base64"));
18
+ const images = imagesBase64.map(base64ToUint8Array);
18
19
  return fullResponse
19
20
  ? {
20
21
  image: images[0],
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { BaseModelCallFinishedEvent, BaseModelCallStartedEvent } from "../ModelCallEvent.js";
3
2
  export interface SpeechGenerationStartedEvent extends BaseModelCallStartedEvent {
4
3
  functionType: "generate-speech";
@@ -7,7 +6,7 @@ export interface SpeechGenerationStartedEvent extends BaseModelCallStartedEvent
7
6
  export type SpeechGenerationFinishedEventResult = {
8
7
  status: "success";
9
8
  rawResponse: unknown;
10
- value: Buffer;
9
+ value: Uint8Array;
11
10
  } | {
12
11
  status: "error";
13
12
  error: unknown;
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { FunctionCallOptions } from "../../core/FunctionOptions.js";
3
2
  import { Delta } from "../Delta.js";
4
3
  import { Model, ModelSettings } from "../Model.js";
@@ -6,10 +5,10 @@ export interface SpeechGenerationModelSettings extends ModelSettings {
6
5
  }
7
6
  export interface SpeechGenerationModel<SETTINGS extends SpeechGenerationModelSettings = SpeechGenerationModelSettings> extends Model<SETTINGS> {
8
7
  /**
9
- * Generates an mp3 audio buffer that contains the speech for the given text.
8
+ * Generates an mp3 audio Uint8Array that contains the speech for the given text.
10
9
  */
11
- doGenerateSpeechStandard(text: string, options: FunctionCallOptions): PromiseLike<Buffer>;
10
+ doGenerateSpeechStandard(text: string, options: FunctionCallOptions): PromiseLike<Uint8Array>;
12
11
  }
13
12
  export interface StreamingSpeechGenerationModel<SETTINGS extends SpeechGenerationModelSettings = SpeechGenerationModelSettings> extends SpeechGenerationModel<SETTINGS> {
14
- doGenerateSpeechStreamDuplex(textStream: AsyncIterable<string>, options: FunctionCallOptions): PromiseLike<AsyncIterable<Delta<Buffer>>>;
13
+ doGenerateSpeechStreamDuplex(textStream: AsyncIterable<string>, options: FunctionCallOptions): PromiseLike<AsyncIterable<Delta<Uint8Array>>>;
15
14
  }
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { FunctionOptions } from "../../core/FunctionOptions.js";
3
2
  import { ModelCallMetadata } from "../ModelCallMetadata.js";
4
3
  import { SpeechGenerationModel, SpeechGenerationModelSettings } from "./SpeechGenerationModel.js";
@@ -17,19 +16,19 @@ import { SpeechGenerationModel, SpeechGenerationModelSettings } from "./SpeechGe
17
16
  * @param {SpeechGenerationModel<SpeechGenerationModelSettings>} model - The speech generation model.
18
17
  * @param {string} text - The text to be converted to speech.
19
18
  *
20
- * @returns {Promise<Buffer>} - A promise that resolves to a buffer containing the synthesized speech.
19
+ * @returns {Promise<Uint8Array>} - A promise that resolves to a Uint8Array containing the synthesized speech.
21
20
  */
22
21
  export declare function generateSpeech(args: {
23
22
  model: SpeechGenerationModel<SpeechGenerationModelSettings>;
24
23
  text: string;
25
24
  fullResponse?: false;
26
- } & FunctionOptions): Promise<Buffer>;
25
+ } & FunctionOptions): Promise<Uint8Array>;
27
26
  export declare function generateSpeech(args: {
28
27
  model: SpeechGenerationModel<SpeechGenerationModelSettings>;
29
28
  text: string;
30
29
  fullResponse: true;
31
30
  } & FunctionOptions): Promise<{
32
- speech: Buffer;
31
+ speech: Uint8Array;
33
32
  rawResponse: unknown;
34
33
  metadata: ModelCallMetadata;
35
34
  }>;
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { FunctionOptions } from "../../core/FunctionOptions.js";
3
2
  import { ModelCallMetadata } from "../ModelCallMetadata.js";
4
3
  import { SpeechGenerationModelSettings, StreamingSpeechGenerationModel } from "./SpeechGenerationModel.js";
@@ -24,18 +23,18 @@ import { SpeechGenerationModelSettings, StreamingSpeechGenerationModel } from ".
24
23
  * @param {AsyncIterable<string> | string} text - The text to be converted to speech. Can be a string or an async iterable of strings.
25
24
  * @param {FunctionOptions} [options] - Optional function options.
26
25
  *
27
- * @returns {AsyncIterableResultPromise<Buffer>} An async iterable promise that contains the synthesized speech chunks.
26
+ * @returns {AsyncIterableResultPromise<Uint8Array>} An async iterable promise that contains the synthesized speech chunks.
28
27
  */
29
28
  export declare function streamSpeech(args: {
30
29
  model: StreamingSpeechGenerationModel<SpeechGenerationModelSettings>;
31
30
  text: AsyncIterable<string> | string;
32
31
  fullResponse?: false;
33
- } & FunctionOptions): Promise<AsyncIterable<Buffer>>;
32
+ } & FunctionOptions): Promise<AsyncIterable<Uint8Array>>;
34
33
  export declare function streamSpeech(args: {
35
34
  model: StreamingSpeechGenerationModel<SpeechGenerationModelSettings>;
36
35
  text: AsyncIterable<string> | string;
37
36
  fullResponse: true;
38
37
  } & FunctionOptions): Promise<{
39
- speechStream: AsyncIterable<Buffer>;
38
+ speechStream: AsyncIterable<Uint8Array>;
40
39
  metadata: Omit<ModelCallMetadata, "durationInMs" | "finishTimestamp">;
41
40
  }>;
@@ -1,7 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateContentIsString = void 0;
3
+ exports.validateContentIsString = exports.getImageAsBase64 = void 0;
4
+ const UInt8Utils_js_1 = require("../../../util/UInt8Utils.cjs");
4
5
  const InvalidPromptError_js_1 = require("./InvalidPromptError.cjs");
6
+ function getImageAsBase64(image) {
7
+ if (typeof image === "string") {
8
+ return image;
9
+ }
10
+ return (0, UInt8Utils_js_1.uint8ArrayToBase64)(image);
11
+ }
12
+ exports.getImageAsBase64 = getImageAsBase64;
5
13
  function validateContentIsString(content, prompt) {
6
14
  if (typeof content !== "string") {
7
15
  throw new InvalidPromptError_js_1.InvalidPromptError("Only text prompts are are supported by this prompt template.", prompt);
@@ -8,9 +8,9 @@ export interface TextPart {
8
8
  export interface ImagePart {
9
9
  type: "image";
10
10
  /**
11
- * Base-64 encoded image.
11
+ * Image data. Can either be a base64-encoded string or a Uint8Array.
12
12
  */
13
- base64Image: string;
13
+ image: string | Uint8Array;
14
14
  /**
15
15
  * Optional mime type of the image.
16
16
  */
@@ -27,4 +27,5 @@ export interface ToolResponsePart {
27
27
  id: string;
28
28
  response: unknown;
29
29
  }
30
+ export declare function getImageAsBase64(image: string | Uint8Array): string;
30
31
  export declare function validateContentIsString(content: string | unknown, prompt: unknown): string;
@@ -1,4 +1,11 @@
1
+ import { uint8ArrayToBase64 } from "../../../util/UInt8Utils.js";
1
2
  import { InvalidPromptError } from "./InvalidPromptError.js";
3
+ export function getImageAsBase64(image) {
4
+ if (typeof image === "string") {
5
+ return image;
6
+ }
7
+ return uint8ArrayToBase64(image);
8
+ }
2
9
  export function validateContentIsString(content, prompt) {
3
10
  if (typeof content !== "string") {
4
11
  throw new InvalidPromptError("Only text prompts are are supported by this prompt template.", prompt);
@@ -9,6 +9,7 @@ const parseJSON_js_1 = require("../../core/schema/parseJSON.cjs");
9
9
  const AbstractModel_js_1 = require("../../model-function/AbstractModel.cjs");
10
10
  const AsyncQueue_js_1 = require("../../util/AsyncQueue.cjs");
11
11
  const SimpleWebSocket_js_1 = require("../../util/SimpleWebSocket.cjs");
12
+ const UInt8Utils_js_1 = require("../../util/UInt8Utils.cjs");
12
13
  const ElevenLabsApiConfiguration_js_1 = require("./ElevenLabsApiConfiguration.cjs");
13
14
  const elevenLabsModels = [
14
15
  "eleven_multilingual_v2",
@@ -141,7 +142,7 @@ class ElevenLabsSpeechModel extends AbstractModel_js_1.AbstractModel {
141
142
  if (!response.isFinal) {
142
143
  queue.push({
143
144
  type: "delta",
144
- deltaValue: Buffer.from(response.audio, "base64"),
145
+ deltaValue: (0, UInt8Utils_js_1.base64ToUint8Array)(response.audio),
145
146
  });
146
147
  }
147
148
  };
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { FunctionCallOptions } from "../../core/FunctionOptions.js";
3
2
  import { ApiConfiguration } from "../../core/api/ApiConfiguration.js";
4
3
  import { AbstractModel } from "../../model-function/AbstractModel.js";
@@ -37,8 +36,8 @@ export declare class ElevenLabsSpeechModel extends AbstractModel<ElevenLabsSpeec
37
36
  get modelName(): string;
38
37
  private callAPI;
39
38
  get settingsForEvent(): Partial<ElevenLabsSpeechModelSettings>;
40
- doGenerateSpeechStandard(text: string, options: FunctionCallOptions): Promise<Buffer>;
41
- doGenerateSpeechStreamDuplex(textStream: AsyncIterable<string>): Promise<AsyncIterable<Delta<Buffer>>>;
39
+ doGenerateSpeechStandard(text: string, options: FunctionCallOptions): Promise<Uint8Array>;
40
+ doGenerateSpeechStreamDuplex(textStream: AsyncIterable<string>): Promise<AsyncIterable<Delta<Uint8Array>>>;
42
41
  withSettings(additionalSettings: Partial<ElevenLabsSpeechModelSettings>): this;
43
42
  }
44
43
  export {};
@@ -6,6 +6,7 @@ import { safeParseJSON } from "../../core/schema/parseJSON.js";
6
6
  import { AbstractModel } from "../../model-function/AbstractModel.js";
7
7
  import { AsyncQueue } from "../../util/AsyncQueue.js";
8
8
  import { createSimpleWebSocket } from "../../util/SimpleWebSocket.js";
9
+ import { base64ToUint8Array } from "../../util/UInt8Utils.js";
9
10
  import { ElevenLabsApiConfiguration } from "./ElevenLabsApiConfiguration.js";
10
11
  const elevenLabsModels = [
11
12
  "eleven_multilingual_v2",
@@ -138,7 +139,7 @@ export class ElevenLabsSpeechModel extends AbstractModel {
138
139
  if (!response.isFinal) {
139
140
  queue.push({
140
141
  type: "delta",
141
- deltaValue: Buffer.from(response.audio, "base64"),
142
+ deltaValue: base64ToUint8Array(response.audio),
142
143
  });
143
144
  }
144
145
  };
@@ -46,7 +46,7 @@ function instruction() {
46
46
  }
47
47
  case "image": {
48
48
  text += `[img-${imageCounter}]`;
49
- images[imageCounter.toString()] = content.base64Image;
49
+ images[imageCounter.toString()] = (0, ContentPart_js_1.getImageAsBase64)(content.image);
50
50
  imageCounter++;
51
51
  break;
52
52
  }
@@ -85,7 +85,7 @@ function chat() {
85
85
  }
86
86
  case "image": {
87
87
  text += `[img-${imageCounter}]`;
88
- images[imageCounter.toString()] = part.base64Image;
88
+ images[imageCounter.toString()] = (0, ContentPart_js_1.getImageAsBase64)(part.image);
89
89
  imageCounter++;
90
90
  break;
91
91
  }
@@ -1,4 +1,4 @@
1
- import { validateContentIsString } from "../../model-function/generate-text/prompt-template/ContentPart.js";
1
+ import { getImageAsBase64, validateContentIsString, } from "../../model-function/generate-text/prompt-template/ContentPart.js";
2
2
  import { InvalidPromptError } from "../../model-function/generate-text/prompt-template/InvalidPromptError.js";
3
3
  import { text as vicunaText } from "../../model-function/generate-text/prompt-template/TextPromptTemplate.js";
4
4
  // default Vicuna 1 system message
@@ -42,7 +42,7 @@ export function instruction() {
42
42
  }
43
43
  case "image": {
44
44
  text += `[img-${imageCounter}]`;
45
- images[imageCounter.toString()] = content.base64Image;
45
+ images[imageCounter.toString()] = getImageAsBase64(content.image);
46
46
  imageCounter++;
47
47
  break;
48
48
  }
@@ -80,7 +80,7 @@ export function chat() {
80
80
  }
81
81
  case "image": {
82
82
  text += `[img-${imageCounter}]`;
83
- images[imageCounter.toString()] = part.base64Image;
83
+ images[imageCounter.toString()] = getImageAsBase64(part.image);
84
84
  imageCounter++;
85
85
  break;
86
86
  }
@@ -6,6 +6,7 @@ const callWithRetryAndThrottle_js_1 = require("../../core/api/callWithRetryAndTh
6
6
  const postToApi_js_1 = require("../../core/api/postToApi.cjs");
7
7
  const ZodSchema_js_1 = require("../../core/schema/ZodSchema.cjs");
8
8
  const AbstractModel_js_1 = require("../../model-function/AbstractModel.cjs");
9
+ const UInt8Utils_js_1 = require("../../util/UInt8Utils.cjs");
9
10
  const LmntApiConfiguration_js_1 = require("./LmntApiConfiguration.cjs");
10
11
  /**
11
12
  * Synthesize speech using the LMNT API.
@@ -81,7 +82,7 @@ class LmntSpeechModel extends AbstractModel_js_1.AbstractModel {
81
82
  }
82
83
  async doGenerateSpeechStandard(text, options) {
83
84
  const response = await this.callAPI(text, options);
84
- return Buffer.from(response.audio, "base64");
85
+ return (0, UInt8Utils_js_1.base64ToUint8Array)(response.audio);
85
86
  }
86
87
  withSettings(additionalSettings) {
87
88
  return new LmntSpeechModel({
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { z } from "zod";
3
2
  import { FunctionCallOptions } from "../../core/FunctionOptions.js";
4
3
  import { ApiConfiguration } from "../../core/api/ApiConfiguration.js";
@@ -34,7 +33,7 @@ export declare class LmntSpeechModel extends AbstractModel<LmntSpeechModelSettin
34
33
  get modelName(): string;
35
34
  private callAPI;
36
35
  get settingsForEvent(): Partial<LmntSpeechModelSettings>;
37
- doGenerateSpeechStandard(text: string, options: FunctionCallOptions): Promise<Buffer>;
36
+ doGenerateSpeechStandard(text: string, options: FunctionCallOptions): Promise<Uint8Array>;
38
37
  withSettings(additionalSettings: Partial<LmntSpeechModelSettings>): this;
39
38
  }
40
39
  declare const lmntSpeechResponseSchema: z.ZodObject<{
@@ -3,6 +3,7 @@ import { callWithRetryAndThrottle } from "../../core/api/callWithRetryAndThrottl
3
3
  import { createJsonResponseHandler, createTextErrorResponseHandler, postToApi, } from "../../core/api/postToApi.js";
4
4
  import { zodSchema } from "../../core/schema/ZodSchema.js";
5
5
  import { AbstractModel } from "../../model-function/AbstractModel.js";
6
+ import { base64ToUint8Array } from "../../util/UInt8Utils.js";
6
7
  import { LmntApiConfiguration } from "./LmntApiConfiguration.js";
7
8
  /**
8
9
  * Synthesize speech using the LMNT API.
@@ -78,7 +79,7 @@ export class LmntSpeechModel extends AbstractModel {
78
79
  }
79
80
  async doGenerateSpeechStandard(text, options) {
80
81
  const response = await this.callAPI(text, options);
81
- return Buffer.from(response.audio, "base64");
82
+ return base64ToUint8Array(response.audio);
82
83
  }
83
84
  withSettings(additionalSettings) {
84
85
  return new LmntSpeechModel({
@@ -95,7 +95,7 @@ function extractUserContent(input) {
95
95
  content += part.text;
96
96
  }
97
97
  else {
98
- images.push(part.base64Image);
98
+ images.push((0, ContentPart_js_1.getImageAsBase64)(part.image));
99
99
  }
100
100
  }
101
101
  return { content, images };
@@ -1,4 +1,4 @@
1
- import { validateContentIsString } from "../../model-function/generate-text/prompt-template/ContentPart.js";
1
+ import { getImageAsBase64, validateContentIsString, } from "../../model-function/generate-text/prompt-template/ContentPart.js";
2
2
  import { InvalidPromptError } from "../../model-function/generate-text/prompt-template/InvalidPromptError.js";
3
3
  /**
4
4
  * OllamaChatPrompt identity chat format.
@@ -88,7 +88,7 @@ function extractUserContent(input) {
88
88
  content += part.text;
89
89
  }
90
90
  else {
91
- images.push(part.base64Image);
91
+ images.push(getImageAsBase64(part.image));
92
92
  }
93
93
  }
94
94
  return { content, images };
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OpenAIChatMessage = void 0;
4
+ const ContentPart_js_1 = require("../../model-function/generate-text/prompt-template/ContentPart.cjs");
4
5
  exports.OpenAIChatMessage = {
5
6
  /**
6
7
  * Creates a system chat message.
@@ -16,15 +17,15 @@ exports.OpenAIChatMessage = {
16
17
  role: "user",
17
18
  content: typeof content === "string"
18
19
  ? content
19
- : content.map((element) => {
20
- switch (element.type) {
20
+ : content.map((part) => {
21
+ switch (part.type) {
21
22
  case "text": {
22
- return { type: "text", text: element.text };
23
+ return { type: "text", text: part.text };
23
24
  }
24
25
  case "image": {
25
26
  return {
26
27
  type: "image_url",
27
- image_url: `data:${element.mimeType ?? "image/jpeg"};base64,${element.base64Image}`,
28
+ image_url: `data:${part.mimeType ?? "image/jpeg"};base64,${(0, ContentPart_js_1.getImageAsBase64)(part.image)}`,
28
29
  };
29
30
  }
30
31
  }
@@ -1,3 +1,4 @@
1
+ import { getImageAsBase64, } from "../../model-function/generate-text/prompt-template/ContentPart.js";
1
2
  export const OpenAIChatMessage = {
2
3
  /**
3
4
  * Creates a system chat message.
@@ -13,15 +14,15 @@ export const OpenAIChatMessage = {
13
14
  role: "user",
14
15
  content: typeof content === "string"
15
16
  ? content
16
- : content.map((element) => {
17
- switch (element.type) {
17
+ : content.map((part) => {
18
+ switch (part.type) {
18
19
  case "text": {
19
- return { type: "text", text: element.text };
20
+ return { type: "text", text: part.text };
20
21
  }
21
22
  case "image": {
22
23
  return {
23
24
  type: "image_url",
24
- image_url: `data:${element.mimeType ?? "image/jpeg"};base64,${element.base64Image}`,
25
+ image_url: `data:${part.mimeType ?? "image/jpeg"};base64,${getImageAsBase64(part.image)}`,
25
26
  };
26
27
  }
27
28
  }
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { FunctionCallOptions } from "../../core/FunctionOptions.js";
3
2
  import { ApiConfiguration } from "../../core/api/ApiConfiguration.js";
4
3
  import { AbstractModel } from "../../model-function/AbstractModel.js";
@@ -46,7 +45,7 @@ export declare class OpenAISpeechModel extends AbstractModel<OpenAISpeechModelSe
46
45
  get modelName(): "tts-1" | "tts-1-hd";
47
46
  private callAPI;
48
47
  get settingsForEvent(): Partial<OpenAISpeechModelSettings>;
49
- doGenerateSpeechStandard(text: string, options: FunctionCallOptions): Promise<Buffer>;
48
+ doGenerateSpeechStandard(text: string, options: FunctionCallOptions): Promise<Uint8Array>;
50
49
  withSettings(additionalSettings: Partial<OpenAISpeechModelSettings>): this;
51
50
  }
52
51
  export {};
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { z } from "zod";
3
2
  import { FunctionCallOptions } from "../../core/FunctionOptions.js";
4
3
  import { ApiConfiguration } from "../../core/api/ApiConfiguration.js";
@@ -43,7 +42,7 @@ export interface OpenAITranscriptionModelSettings extends TranscriptionModelSett
43
42
  }
44
43
  export type OpenAITranscriptionInput = {
45
44
  type: "flac" | "m4a" | "mp3" | "mp4" | "mpeg" | "mpga" | "ogg" | "wav" | "webm";
46
- data: Buffer;
45
+ data: Uint8Array;
47
46
  };
48
47
  /**
49
48
  * Create a transcription model that calls the OpenAI transcription API.
@@ -28,6 +28,12 @@ class FireworksAIApiConfiguration extends BaseUrlApiConfiguration_js_1.BaseUrlAp
28
28
  path: "/inference/v1",
29
29
  },
30
30
  });
31
+ Object.defineProperty(this, "provider", {
32
+ enumerable: true,
33
+ configurable: true,
34
+ writable: true,
35
+ value: "openaicompatible-fireworksai"
36
+ });
31
37
  }
32
38
  }
33
39
  exports.FireworksAIApiConfiguration = FireworksAIApiConfiguration;
@@ -1,4 +1,5 @@
1
1
  import { BaseUrlApiConfigurationWithDefaults, PartialBaseUrlPartsApiConfigurationOptions } from "../../core/api/BaseUrlApiConfiguration.js";
2
+ import { OpenAICompatibleApiConfiguration } from "./OpenAICompatibleApiConfiguration.js";
2
3
  /**
3
4
  * Configuration for the Fireworks.ai API.
4
5
  *
@@ -6,8 +7,9 @@ import { BaseUrlApiConfigurationWithDefaults, PartialBaseUrlPartsApiConfiguratio
6
7
  *
7
8
  * @see https://readme.fireworks.ai/docs/openai-compatibility
8
9
  */
9
- export declare class FireworksAIApiConfiguration extends BaseUrlApiConfigurationWithDefaults {
10
+ export declare class FireworksAIApiConfiguration extends BaseUrlApiConfigurationWithDefaults implements OpenAICompatibleApiConfiguration {
10
11
  constructor(settings?: PartialBaseUrlPartsApiConfigurationOptions & {
11
12
  apiKey?: string;
12
13
  });
14
+ readonly provider = "openaicompatible-fireworksai";
13
15
  }
@@ -25,5 +25,11 @@ export class FireworksAIApiConfiguration extends BaseUrlApiConfigurationWithDefa
25
25
  path: "/inference/v1",
26
26
  },
27
27
  });
28
+ Object.defineProperty(this, "provider", {
29
+ enumerable: true,
30
+ configurable: true,
31
+ writable: true,
32
+ value: "openaicompatible-fireworksai"
33
+ });
28
34
  }
29
35
  }
@@ -0,0 +1,5 @@
1
+ import { ApiConfiguration } from "../../core/api/ApiConfiguration.js";
2
+ export type OpenAICompatibleProviderName = `openaicompatible` | `openaicompatible-${string}`;
3
+ export interface OpenAICompatibleApiConfiguration extends ApiConfiguration {
4
+ provider?: OpenAICompatibleProviderName;
5
+ }
@@ -37,7 +37,7 @@ class OpenAICompatibleChatModel extends AbstractOpenAIChatModel_js_1.AbstractOpe
37
37
  });
38
38
  }
39
39
  get provider() {
40
- return this.settings.provider ?? "openaicompatible";
40
+ return (this.settings.provider ?? this.settings.api.provider ?? "openaicompatible");
41
41
  }
42
42
  get modelName() {
43
43
  return this.settings.model;
@@ -1,4 +1,3 @@
1
- import { ApiConfiguration } from "../../core/api/ApiConfiguration.js";
2
1
  import { FlexibleStructureFromTextPromptTemplate, StructureFromTextPromptTemplate } from "../../model-function/generate-structure/StructureFromTextPromptTemplate.js";
3
2
  import { StructureFromTextStreamingModel } from "../../model-function/generate-structure/StructureFromTextStreamingModel.js";
4
3
  import { PromptTemplateFullTextModel } from "../../model-function/generate-text/PromptTemplateFullTextModel.js";
@@ -7,9 +6,9 @@ import { TextGenerationPromptTemplate } from "../../model-function/generate-text
7
6
  import { ToolCallGenerationModel } from "../../tool/generate-tool-call/ToolCallGenerationModel.js";
8
7
  import { ToolCallsGenerationModel } from "../../tool/generate-tool-calls/ToolCallsGenerationModel.js";
9
8
  import { AbstractOpenAIChatModel, AbstractOpenAIChatSettings, OpenAIChatPrompt } from "../openai/AbstractOpenAIChatModel.js";
10
- import { OpenAICompatibleProviderName } from "./OpenAICompatibleProviderName.js";
9
+ import { OpenAICompatibleApiConfiguration, OpenAICompatibleProviderName } from "./OpenAICompatibleApiConfiguration.js";
11
10
  export interface OpenAICompatibleChatSettings extends AbstractOpenAIChatSettings {
12
- api: ApiConfiguration;
11
+ api: OpenAICompatibleApiConfiguration;
13
12
  provider?: OpenAICompatibleProviderName;
14
13
  }
15
14
  /**
@@ -34,7 +34,7 @@ export class OpenAICompatibleChatModel extends AbstractOpenAIChatModel {
34
34
  });
35
35
  }
36
36
  get provider() {
37
- return this.settings.provider ?? "openaicompatible";
37
+ return (this.settings.provider ?? this.settings.api.provider ?? "openaicompatible");
38
38
  }
39
39
  get modelName() {
40
40
  return this.settings.model;
@@ -36,7 +36,7 @@ class OpenAICompatibleCompletionModel extends AbstractOpenAICompletionModel_js_1
36
36
  });
37
37
  }
38
38
  get provider() {
39
- return this.settings.provider ?? "openaicompatible";
39
+ return (this.settings.provider ?? this.settings.api.provider ?? "openaicompatible");
40
40
  }
41
41
  get modelName() {
42
42
  return this.settings.model;
@@ -1,11 +1,10 @@
1
- import { ApiConfiguration } from "../../core/api/ApiConfiguration.js";
2
1
  import { PromptTemplateTextStreamingModel } from "../../model-function/generate-text/PromptTemplateTextStreamingModel.js";
3
2
  import { TextStreamingBaseModel } from "../../model-function/generate-text/TextGenerationModel.js";
4
3
  import { TextGenerationPromptTemplate } from "../../model-function/generate-text/TextGenerationPromptTemplate.js";
5
4
  import { AbstractOpenAICompletionModel, AbstractOpenAICompletionModelSettings } from "../openai/AbstractOpenAICompletionModel.js";
6
- import { OpenAICompatibleProviderName } from "./OpenAICompatibleProviderName.js";
5
+ import { OpenAICompatibleApiConfiguration, OpenAICompatibleProviderName } from "./OpenAICompatibleApiConfiguration.js";
7
6
  export interface OpenAICompatibleCompletionModelSettings extends AbstractOpenAICompletionModelSettings {
8
- api: ApiConfiguration;
7
+ api: OpenAICompatibleApiConfiguration;
9
8
  provider?: OpenAICompatibleProviderName;
10
9
  }
11
10
  /**
@@ -33,7 +33,7 @@ export class OpenAICompatibleCompletionModel extends AbstractOpenAICompletionMod
33
33
  });
34
34
  }
35
35
  get provider() {
36
- return this.settings.provider ?? "openaicompatible";
36
+ return (this.settings.provider ?? this.settings.api.provider ?? "openaicompatible");
37
37
  }
38
38
  get modelName() {
39
39
  return this.settings.model;
@@ -7,7 +7,7 @@ class OpenAICompatibleTextEmbeddingModel extends AbstractOpenAITextEmbeddingMode
7
7
  super(settings);
8
8
  }
9
9
  get provider() {
10
- return this.settings.provider ?? "openaicompatible";
10
+ return (this.settings.provider ?? this.settings.api.provider ?? "openaicompatible");
11
11
  }
12
12
  get modelName() {
13
13
  return this.settings.model;
@@ -1,9 +1,8 @@
1
- import { ApiConfiguration } from "../../core/api/ApiConfiguration.js";
2
1
  import { EmbeddingModel } from "../../model-function/embed/EmbeddingModel.js";
3
2
  import { AbstractOpenAITextEmbeddingModel, AbstractOpenAITextEmbeddingModelSettings } from "../openai/AbstractOpenAITextEmbeddingModel.js";
4
- import { OpenAICompatibleProviderName } from "./OpenAICompatibleProviderName.js";
3
+ import { OpenAICompatibleApiConfiguration, OpenAICompatibleProviderName } from "./OpenAICompatibleApiConfiguration.js";
5
4
  export interface OpenAICompatibleTextEmbeddingModelSettings extends AbstractOpenAITextEmbeddingModelSettings {
6
- api: ApiConfiguration;
5
+ api: OpenAICompatibleApiConfiguration;
7
6
  provider?: OpenAICompatibleProviderName;
8
7
  model: string;
9
8
  embeddingDimensions?: number;
@@ -4,7 +4,7 @@ export class OpenAICompatibleTextEmbeddingModel extends AbstractOpenAITextEmbedd
4
4
  super(settings);
5
5
  }
6
6
  get provider() {
7
- return this.settings.provider ?? "openaicompatible";
7
+ return (this.settings.provider ?? this.settings.api.provider ?? "openaicompatible");
8
8
  }
9
9
  get modelName() {
10
10
  return this.settings.model;
@@ -28,6 +28,12 @@ class PerplexityApiConfiguration extends BaseUrlApiConfiguration_js_1.BaseUrlApi
28
28
  path: "",
29
29
  },
30
30
  });
31
+ Object.defineProperty(this, "provider", {
32
+ enumerable: true,
33
+ configurable: true,
34
+ writable: true,
35
+ value: "openaicompatible-perplexity"
36
+ });
31
37
  }
32
38
  }
33
39
  exports.PerplexityApiConfiguration = PerplexityApiConfiguration;
@@ -1,4 +1,5 @@
1
1
  import { BaseUrlApiConfigurationWithDefaults, PartialBaseUrlPartsApiConfigurationOptions } from "../../core/api/BaseUrlApiConfiguration.js";
2
+ import { OpenAICompatibleApiConfiguration } from "./OpenAICompatibleApiConfiguration.js";
2
3
  /**
3
4
  * Configuration for the Perplexity API.
4
5
  *
@@ -6,8 +7,9 @@ import { BaseUrlApiConfigurationWithDefaults, PartialBaseUrlPartsApiConfiguratio
6
7
  *
7
8
  * @see https://docs.perplexity.ai/reference/post_chat_completions
8
9
  */
9
- export declare class PerplexityApiConfiguration extends BaseUrlApiConfigurationWithDefaults {
10
+ export declare class PerplexityApiConfiguration extends BaseUrlApiConfigurationWithDefaults implements OpenAICompatibleApiConfiguration {
10
11
  constructor(settings?: PartialBaseUrlPartsApiConfigurationOptions & {
11
12
  apiKey?: string;
12
13
  });
14
+ readonly provider = "openaicompatible-perplexity";
13
15
  }
@@ -25,5 +25,11 @@ export class PerplexityApiConfiguration extends BaseUrlApiConfigurationWithDefau
25
25
  path: "",
26
26
  },
27
27
  });
28
+ Object.defineProperty(this, "provider", {
29
+ enumerable: true,
30
+ configurable: true,
31
+ writable: true,
32
+ value: "openaicompatible-perplexity"
33
+ });
28
34
  }
29
35
  }
@@ -28,6 +28,12 @@ class TogetherAIApiConfiguration extends BaseUrlApiConfiguration_js_1.BaseUrlApi
28
28
  path: "/v1",
29
29
  },
30
30
  });
31
+ Object.defineProperty(this, "provider", {
32
+ enumerable: true,
33
+ configurable: true,
34
+ writable: true,
35
+ value: "openaicompatible-togetherai"
36
+ });
31
37
  }
32
38
  }
33
39
  exports.TogetherAIApiConfiguration = TogetherAIApiConfiguration;
@@ -1,4 +1,5 @@
1
1
  import { BaseUrlApiConfigurationWithDefaults, PartialBaseUrlPartsApiConfigurationOptions } from "../../core/api/BaseUrlApiConfiguration.js";
2
+ import { OpenAICompatibleApiConfiguration } from "./OpenAICompatibleApiConfiguration.js";
2
3
  /**
3
4
  * Configuration for the Together.ai API.
4
5
  *
@@ -6,8 +7,9 @@ import { BaseUrlApiConfigurationWithDefaults, PartialBaseUrlPartsApiConfiguratio
6
7
  *
7
8
  * @see https://docs.together.ai/docs/openai-api-compatibility
8
9
  */
9
- export declare class TogetherAIApiConfiguration extends BaseUrlApiConfigurationWithDefaults {
10
+ export declare class TogetherAIApiConfiguration extends BaseUrlApiConfigurationWithDefaults implements OpenAICompatibleApiConfiguration {
10
11
  constructor(settings?: PartialBaseUrlPartsApiConfigurationOptions & {
11
12
  apiKey?: string;
12
13
  });
14
+ readonly provider = "openaicompatible-togetherai";
13
15
  }
@@ -25,5 +25,11 @@ export class TogetherAIApiConfiguration extends BaseUrlApiConfigurationWithDefau
25
25
  path: "/v1",
26
26
  },
27
27
  });
28
+ Object.defineProperty(this, "provider", {
29
+ enumerable: true,
30
+ configurable: true,
31
+ writable: true,
32
+ value: "openaicompatible-togetherai"
33
+ });
28
34
  }
29
35
  }
@@ -28,10 +28,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.openaicompatible = void 0;
30
30
  __exportStar(require("./FireworksAIApiConfiguration.cjs"), exports);
31
+ __exportStar(require("./OpenAICompatibleApiConfiguration.cjs"), exports);
31
32
  __exportStar(require("./OpenAICompatibleChatModel.cjs"), exports);
32
33
  __exportStar(require("./OpenAICompatibleCompletionModel.cjs"), exports);
33
34
  exports.openaicompatible = __importStar(require("./OpenAICompatibleFacade.cjs"));
34
- __exportStar(require("./OpenAICompatibleProviderName.cjs"), exports);
35
35
  __exportStar(require("./OpenAICompatibleTextEmbeddingModel.cjs"), exports);
36
36
  __exportStar(require("./PerplexityApiConfiguration.cjs"), exports);
37
37
  __exportStar(require("./TogetherAIApiConfiguration.cjs"), exports);
@@ -1,8 +1,8 @@
1
1
  export * from "./FireworksAIApiConfiguration.js";
2
+ export * from "./OpenAICompatibleApiConfiguration.js";
2
3
  export * from "./OpenAICompatibleChatModel.js";
3
4
  export * from "./OpenAICompatibleCompletionModel.js";
4
5
  export * as openaicompatible from "./OpenAICompatibleFacade.js";
5
- export * from "./OpenAICompatibleProviderName.js";
6
6
  export * from "./OpenAICompatibleTextEmbeddingModel.js";
7
7
  export * from "./PerplexityApiConfiguration.js";
8
8
  export * from "./TogetherAIApiConfiguration.js";
@@ -1,8 +1,8 @@
1
1
  export * from "./FireworksAIApiConfiguration.js";
2
+ export * from "./OpenAICompatibleApiConfiguration.js";
2
3
  export * from "./OpenAICompatibleChatModel.js";
3
4
  export * from "./OpenAICompatibleCompletionModel.js";
4
5
  export * as openaicompatible from "./OpenAICompatibleFacade.js";
5
- export * from "./OpenAICompatibleProviderName.js";
6
6
  export * from "./OpenAICompatibleTextEmbeddingModel.js";
7
7
  export * from "./PerplexityApiConfiguration.js";
8
8
  export * from "./TogetherAIApiConfiguration.js";
@@ -69,9 +69,9 @@ export declare class StabilityImageGenerationModel extends AbstractModel<Stabili
69
69
  doGenerateImages(prompt: StabilityImageGenerationPrompt, callOptions: FunctionCallOptions): Promise<{
70
70
  rawResponse: {
71
71
  artifacts: {
72
- base64: string;
73
72
  finishReason: "ERROR" | "SUCCESS" | "CONTENT_FILTERED";
74
73
  seed: number;
74
+ base64: string;
75
75
  }[];
76
76
  };
77
77
  base64Images: string[];
@@ -86,25 +86,25 @@ declare const stabilityImageGenerationResponseSchema: z.ZodObject<{
86
86
  seed: z.ZodNumber;
87
87
  finishReason: z.ZodEnum<["SUCCESS", "ERROR", "CONTENT_FILTERED"]>;
88
88
  }, "strip", z.ZodTypeAny, {
89
- base64: string;
90
89
  finishReason: "ERROR" | "SUCCESS" | "CONTENT_FILTERED";
91
90
  seed: number;
92
- }, {
93
91
  base64: string;
92
+ }, {
94
93
  finishReason: "ERROR" | "SUCCESS" | "CONTENT_FILTERED";
95
94
  seed: number;
95
+ base64: string;
96
96
  }>, "many">;
97
97
  }, "strip", z.ZodTypeAny, {
98
98
  artifacts: {
99
- base64: string;
100
99
  finishReason: "ERROR" | "SUCCESS" | "CONTENT_FILTERED";
101
100
  seed: number;
101
+ base64: string;
102
102
  }[];
103
103
  }, {
104
104
  artifacts: {
105
- base64: string;
106
105
  finishReason: "ERROR" | "SUCCESS" | "CONTENT_FILTERED";
107
106
  seed: number;
107
+ base64: string;
108
108
  }[];
109
109
  }>;
110
110
  export type StabilityImageGenerationResponse = z.infer<typeof stabilityImageGenerationResponseSchema>;
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { FunctionCallOptions } from "../../core/FunctionOptions.js";
3
2
  import { ApiConfiguration } from "../../core/api/ApiConfiguration.js";
4
3
  import { AbstractModel } from "../../model-function/AbstractModel.js";
@@ -9,7 +8,7 @@ export interface WhisperCppTranscriptionModelSettings extends TranscriptionModel
9
8
  }
10
9
  export type WhisperCppTranscriptionInput = {
11
10
  type: "wav";
12
- data: Buffer;
11
+ data: Uint8Array;
13
12
  };
14
13
  export declare class WhisperCppTranscriptionModel extends AbstractModel<WhisperCppTranscriptionModelSettings> implements TranscriptionModel<WhisperCppTranscriptionInput, WhisperCppTranscriptionModelSettings> {
15
14
  constructor(settings: WhisperCppTranscriptionModelSettings);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "modelfusion",
3
3
  "description": "The TypeScript library for building AI applications.",
4
- "version": "0.127.0",
4
+ "version": "0.129.0",
5
5
  "author": "Lars Grammel",
6
6
  "license": "MIT",
7
7
  "keywords": [
@@ -80,7 +80,7 @@
80
80
  "@vitest/ui": "1.1.0",
81
81
  "eslint": "^8.45.0",
82
82
  "eslint-config-prettier": "9.1.0",
83
- "msw": "2.0.11",
83
+ "msw": "2.1.2",
84
84
  "type-fest": "4.9.0"
85
85
  }
86
86
  }
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ /*
3
+ * MIT License
4
+ *
5
+ * Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8
+ *
9
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
+ *
11
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12
+ */
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.uint8ArrayToBase64 = exports.base64ToUint8Array = exports.toUint8Array = void 0;
15
+ // copied from: https://github.com/sindresorhus/uint8array-extras/blob/main/index.js
16
+ function toUint8Array(value) {
17
+ if (value instanceof ArrayBuffer) {
18
+ return new Uint8Array(value);
19
+ }
20
+ if (ArrayBuffer.isView(value)) {
21
+ return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
22
+ }
23
+ throw new TypeError(`Unsupported value, got \`${typeof value}\`.`);
24
+ }
25
+ exports.toUint8Array = toUint8Array;
26
+ function base64ToUint8Array(base64String) {
27
+ return Uint8Array.from(globalThis.atob(base64UrlToBase64(base64String)), (x) => x.codePointAt(0));
28
+ }
29
+ exports.base64ToUint8Array = base64ToUint8Array;
30
+ // Reference: https://phuoc.ng/collection/this-vs-that/concat-vs-push/
31
+ const MAX_BLOCK_SIZE = 65535;
32
+ function uint8ArrayToBase64(array) {
33
+ let base64;
34
+ if (array.length < MAX_BLOCK_SIZE) {
35
+ // Required as `btoa` and `atob` don't properly support Unicode: https://developer.mozilla.org/en-US/docs/Glossary/Base64#the_unicode_problem
36
+ base64 = globalThis.btoa(String.fromCodePoint(...array));
37
+ }
38
+ else {
39
+ base64 = "";
40
+ for (const value of array) {
41
+ base64 += String.fromCodePoint(value);
42
+ }
43
+ base64 = globalThis.btoa(base64);
44
+ }
45
+ return base64;
46
+ }
47
+ exports.uint8ArrayToBase64 = uint8ArrayToBase64;
48
+ function base64UrlToBase64(base64url) {
49
+ return base64url.replaceAll("-", "+").replaceAll("_", "/");
50
+ }
@@ -0,0 +1,3 @@
1
+ export declare function toUint8Array(value: unknown): Uint8Array;
2
+ export declare function base64ToUint8Array(base64String: string): Uint8Array;
3
+ export declare function uint8ArrayToBase64(array: Uint8Array): string;
@@ -0,0 +1,44 @@
1
+ /*
2
+ * MIT License
3
+ *
4
+ * Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7
+ *
8
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9
+ *
10
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11
+ */
12
+ // copied from: https://github.com/sindresorhus/uint8array-extras/blob/main/index.js
13
+ export function toUint8Array(value) {
14
+ if (value instanceof ArrayBuffer) {
15
+ return new Uint8Array(value);
16
+ }
17
+ if (ArrayBuffer.isView(value)) {
18
+ return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
19
+ }
20
+ throw new TypeError(`Unsupported value, got \`${typeof value}\`.`);
21
+ }
22
+ export function base64ToUint8Array(base64String) {
23
+ return Uint8Array.from(globalThis.atob(base64UrlToBase64(base64String)), (x) => x.codePointAt(0));
24
+ }
25
+ // Reference: https://phuoc.ng/collection/this-vs-that/concat-vs-push/
26
+ const MAX_BLOCK_SIZE = 65535;
27
+ export function uint8ArrayToBase64(array) {
28
+ let base64;
29
+ if (array.length < MAX_BLOCK_SIZE) {
30
+ // Required as `btoa` and `atob` don't properly support Unicode: https://developer.mozilla.org/en-US/docs/Glossary/Base64#the_unicode_problem
31
+ base64 = globalThis.btoa(String.fromCodePoint(...array));
32
+ }
33
+ else {
34
+ base64 = "";
35
+ for (const value of array) {
36
+ base64 += String.fromCodePoint(value);
37
+ }
38
+ base64 = globalThis.btoa(base64);
39
+ }
40
+ return base64;
41
+ }
42
+ function base64UrlToBase64(base64url) {
43
+ return base64url.replaceAll("-", "+").replaceAll("_", "/");
44
+ }
@@ -1 +0,0 @@
1
- export type OpenAICompatibleProviderName = `openaicompatible` | `openaicompatible-${string}`;