@browser-ai/web-llm 2.1.0 → 2.1.2

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/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateResult, LanguageModelV3StreamResult } from '@ai-sdk/provider';
2
- import { AppConfig, InitProgressReport, MLCEngineConfig } from '@mlc-ai/web-llm';
1
+ import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateResult, LanguageModelV3StreamResult, EmbeddingModelV3, EmbeddingModelV3CallOptions, EmbeddingModelV3Result, ProviderV3 } from '@ai-sdk/provider';
2
+ import { AppConfig, InitProgressReport, MLCEngineConfig, MLCEngineInterface } from '@mlc-ai/web-llm';
3
3
  export { InitProgressReport as WebLLMProgress, WebWorkerMLCEngineHandler } from '@mlc-ai/web-llm';
4
4
  import { UIMessage } from 'ai';
5
5
 
@@ -75,6 +75,11 @@ declare global {
75
75
  gpu?: GPU;
76
76
  }
77
77
  }
78
+ /**
79
+ * Check if the browser supports WebLLM (WebGPU)
80
+ */
81
+ declare function doesBrowserSupportWebLLM(): boolean;
82
+
78
83
  type WebLLMModelId = string;
79
84
  interface WebLLMSettings {
80
85
  /**
@@ -97,11 +102,6 @@ interface WebLLMSettings {
97
102
  */
98
103
  worker?: Worker;
99
104
  }
100
- /**
101
- * Check if the browser supports WebGPU (required for WebLLM).
102
- * @returns boolean - true if WebGPU API is available
103
- */
104
- declare function doesBrowserSupportWebLLM(): boolean;
105
105
  declare class WebLLMLanguageModel implements LanguageModelV3 {
106
106
  readonly specificationVersion = "v3";
107
107
  readonly modelId: WebLLMModelId;
@@ -162,11 +162,115 @@ declare class WebLLMLanguageModel implements LanguageModelV3 {
162
162
  doStream(options: LanguageModelV3CallOptions): Promise<LanguageModelV3StreamResult>;
163
163
  }
164
164
 
165
+ type WebLLMEmbeddingModelId = string;
166
+ interface WebLLMEmbeddingSettings {
167
+ /**
168
+ * Custom app configuration for WebLLM
169
+ */
170
+ appConfig?: AppConfig;
171
+ /**
172
+ * Progress callback for model initialization
173
+ */
174
+ initProgressCallback?: (progress: InitProgressReport) => void;
175
+ /**
176
+ * Engine configuration options
177
+ */
178
+ engineConfig?: MLCEngineConfig;
179
+ /**
180
+ * A web worker instance to run the model in.
181
+ * When provided, the model will run in a separate thread.
182
+ *
183
+ * @default undefined
184
+ */
185
+ worker?: Worker;
186
+ /**
187
+ * Maximum number of texts to embed in a single call.
188
+ * @default 100
189
+ */
190
+ maxEmbeddingsPerCall?: number;
191
+ }
192
+ declare class WebLLMEmbeddingModel implements EmbeddingModelV3 {
193
+ readonly specificationVersion = "v3";
194
+ readonly provider = "web-llm";
195
+ readonly modelId: WebLLMEmbeddingModelId;
196
+ readonly maxEmbeddingsPerCall: number;
197
+ readonly supportsParallelCalls = false;
198
+ private readonly config;
199
+ private engine?;
200
+ private isInitialized;
201
+ private initializationPromise?;
202
+ constructor(modelId: WebLLMEmbeddingModelId, options?: WebLLMEmbeddingSettings);
203
+ /**
204
+ * Check if the model is initialized and ready to use
205
+ */
206
+ get isModelInitialized(): boolean;
207
+ private getEngine;
208
+ private _initializeEngine;
209
+ /**
210
+ * Check the availability of the WebLLM embedding model
211
+ * @returns Promise resolving to "unavailable", "available", or "downloadable"
212
+ */
213
+ availability(): Promise<Availability>;
214
+ /**
215
+ * Creates an engine session with download progress monitoring.
216
+ *
217
+ * @example
218
+ * ```typescript
219
+ * const engine = await model.createSessionWithProgress(
220
+ * (progress) => {
221
+ * console.log(`Download progress: ${Math.round(progress.progress * 100)}%`);
222
+ * }
223
+ * );
224
+ * ```
225
+ *
226
+ * @param onInitProgress Optional callback receiving progress reports during model download
227
+ * @returns Promise resolving to a configured WebLLM engine
228
+ * @throws {LoadSettingError} When WebLLM isn't available or model is unavailable
229
+ */
230
+ createSessionWithProgress(onInitProgress?: (progress: InitProgressReport) => void): Promise<MLCEngineInterface>;
231
+ /**
232
+ * Embed texts using the WebLLM embedding model
233
+ */
234
+ doEmbed(options: EmbeddingModelV3CallOptions): Promise<EmbeddingModelV3Result>;
235
+ }
236
+
237
+ interface WebLLMProvider extends ProviderV3 {
238
+ (modelId: WebLLMModelId, settings?: WebLLMSettings): WebLLMLanguageModel;
239
+ /**
240
+ * Creates a model for text generation.
241
+ */
242
+ languageModel(modelId: WebLLMModelId, settings?: WebLLMSettings): WebLLMLanguageModel;
243
+ /**
244
+ * Creates a model for text generation.
245
+ */
246
+ chat(modelId: WebLLMModelId, settings?: WebLLMSettings): WebLLMLanguageModel;
247
+ /**
248
+ * Creates a model for text embeddings.
249
+ */
250
+ embedding(modelId: WebLLMEmbeddingModelId, settings?: WebLLMEmbeddingSettings): EmbeddingModelV3;
251
+ /**
252
+ * Creates a model for text embeddings.
253
+ */
254
+ embeddingModel: (modelId: WebLLMEmbeddingModelId, settings?: WebLLMEmbeddingSettings) => EmbeddingModelV3;
255
+ }
256
+ /**
257
+ * Create a WebLLM provider instance.
258
+ */
259
+ declare function createWebLLM(): WebLLMProvider;
165
260
  /**
166
- * Create a new WebLLMLanguageModel.
167
- * @param modelId The model ID to use (e.g., 'Llama-3.1-8B-Instruct-q4f32_1-MLC')
168
- * @param settings Options for the model
261
+ * Default WebLLM provider instance
262
+ *
263
+ * @example
264
+ * ```typescript
265
+ * import { webLLM } from "@browser-ai/web-llm";
266
+ *
267
+ * // Language model
268
+ * const chat = webLLM("Llama-3.2-3B-Instruct-q4f16_1-MLC");
269
+ *
270
+ * // Embedding model
271
+ * const embed = webLLM.embeddingModel("snowflake-arctic-embed-m-q0f32-MLC-b32");
272
+ * ```
169
273
  */
170
- declare function webLLM(modelId: WebLLMModelId, settings?: WebLLMSettings): WebLLMLanguageModel;
274
+ declare const webLLM: WebLLMProvider;
171
275
 
172
- export { WebLLMLanguageModel, type WebLLMModelId, type WebLLMSettings, type WebLLMUIMessage, doesBrowserSupportWebLLM, webLLM };
276
+ export { WebLLMEmbeddingModel, type WebLLMEmbeddingModelId, type WebLLMEmbeddingSettings, WebLLMLanguageModel, type WebLLMModelId, type WebLLMProvider, type WebLLMSettings, type WebLLMUIMessage, createWebLLM, doesBrowserSupportWebLLM, webLLM };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateResult, LanguageModelV3StreamResult } from '@ai-sdk/provider';
2
- import { AppConfig, InitProgressReport, MLCEngineConfig } from '@mlc-ai/web-llm';
1
+ import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateResult, LanguageModelV3StreamResult, EmbeddingModelV3, EmbeddingModelV3CallOptions, EmbeddingModelV3Result, ProviderV3 } from '@ai-sdk/provider';
2
+ import { AppConfig, InitProgressReport, MLCEngineConfig, MLCEngineInterface } from '@mlc-ai/web-llm';
3
3
  export { InitProgressReport as WebLLMProgress, WebWorkerMLCEngineHandler } from '@mlc-ai/web-llm';
4
4
  import { UIMessage } from 'ai';
5
5
 
@@ -75,6 +75,11 @@ declare global {
75
75
  gpu?: GPU;
76
76
  }
77
77
  }
78
+ /**
79
+ * Check if the browser supports WebLLM (WebGPU)
80
+ */
81
+ declare function doesBrowserSupportWebLLM(): boolean;
82
+
78
83
  type WebLLMModelId = string;
79
84
  interface WebLLMSettings {
80
85
  /**
@@ -97,11 +102,6 @@ interface WebLLMSettings {
97
102
  */
98
103
  worker?: Worker;
99
104
  }
100
- /**
101
- * Check if the browser supports WebGPU (required for WebLLM).
102
- * @returns boolean - true if WebGPU API is available
103
- */
104
- declare function doesBrowserSupportWebLLM(): boolean;
105
105
  declare class WebLLMLanguageModel implements LanguageModelV3 {
106
106
  readonly specificationVersion = "v3";
107
107
  readonly modelId: WebLLMModelId;
@@ -162,11 +162,115 @@ declare class WebLLMLanguageModel implements LanguageModelV3 {
162
162
  doStream(options: LanguageModelV3CallOptions): Promise<LanguageModelV3StreamResult>;
163
163
  }
164
164
 
165
+ type WebLLMEmbeddingModelId = string;
166
+ interface WebLLMEmbeddingSettings {
167
+ /**
168
+ * Custom app configuration for WebLLM
169
+ */
170
+ appConfig?: AppConfig;
171
+ /**
172
+ * Progress callback for model initialization
173
+ */
174
+ initProgressCallback?: (progress: InitProgressReport) => void;
175
+ /**
176
+ * Engine configuration options
177
+ */
178
+ engineConfig?: MLCEngineConfig;
179
+ /**
180
+ * A web worker instance to run the model in.
181
+ * When provided, the model will run in a separate thread.
182
+ *
183
+ * @default undefined
184
+ */
185
+ worker?: Worker;
186
+ /**
187
+ * Maximum number of texts to embed in a single call.
188
+ * @default 100
189
+ */
190
+ maxEmbeddingsPerCall?: number;
191
+ }
192
+ declare class WebLLMEmbeddingModel implements EmbeddingModelV3 {
193
+ readonly specificationVersion = "v3";
194
+ readonly provider = "web-llm";
195
+ readonly modelId: WebLLMEmbeddingModelId;
196
+ readonly maxEmbeddingsPerCall: number;
197
+ readonly supportsParallelCalls = false;
198
+ private readonly config;
199
+ private engine?;
200
+ private isInitialized;
201
+ private initializationPromise?;
202
+ constructor(modelId: WebLLMEmbeddingModelId, options?: WebLLMEmbeddingSettings);
203
+ /**
204
+ * Check if the model is initialized and ready to use
205
+ */
206
+ get isModelInitialized(): boolean;
207
+ private getEngine;
208
+ private _initializeEngine;
209
+ /**
210
+ * Check the availability of the WebLLM embedding model
211
+ * @returns Promise resolving to "unavailable", "available", or "downloadable"
212
+ */
213
+ availability(): Promise<Availability>;
214
+ /**
215
+ * Creates an engine session with download progress monitoring.
216
+ *
217
+ * @example
218
+ * ```typescript
219
+ * const engine = await model.createSessionWithProgress(
220
+ * (progress) => {
221
+ * console.log(`Download progress: ${Math.round(progress.progress * 100)}%`);
222
+ * }
223
+ * );
224
+ * ```
225
+ *
226
+ * @param onInitProgress Optional callback receiving progress reports during model download
227
+ * @returns Promise resolving to a configured WebLLM engine
228
+ * @throws {LoadSettingError} When WebLLM isn't available or model is unavailable
229
+ */
230
+ createSessionWithProgress(onInitProgress?: (progress: InitProgressReport) => void): Promise<MLCEngineInterface>;
231
+ /**
232
+ * Embed texts using the WebLLM embedding model
233
+ */
234
+ doEmbed(options: EmbeddingModelV3CallOptions): Promise<EmbeddingModelV3Result>;
235
+ }
236
+
237
+ interface WebLLMProvider extends ProviderV3 {
238
+ (modelId: WebLLMModelId, settings?: WebLLMSettings): WebLLMLanguageModel;
239
+ /**
240
+ * Creates a model for text generation.
241
+ */
242
+ languageModel(modelId: WebLLMModelId, settings?: WebLLMSettings): WebLLMLanguageModel;
243
+ /**
244
+ * Creates a model for text generation.
245
+ */
246
+ chat(modelId: WebLLMModelId, settings?: WebLLMSettings): WebLLMLanguageModel;
247
+ /**
248
+ * Creates a model for text embeddings.
249
+ */
250
+ embedding(modelId: WebLLMEmbeddingModelId, settings?: WebLLMEmbeddingSettings): EmbeddingModelV3;
251
+ /**
252
+ * Creates a model for text embeddings.
253
+ */
254
+ embeddingModel: (modelId: WebLLMEmbeddingModelId, settings?: WebLLMEmbeddingSettings) => EmbeddingModelV3;
255
+ }
256
+ /**
257
+ * Create a WebLLM provider instance.
258
+ */
259
+ declare function createWebLLM(): WebLLMProvider;
165
260
  /**
166
- * Create a new WebLLMLanguageModel.
167
- * @param modelId The model ID to use (e.g., 'Llama-3.1-8B-Instruct-q4f32_1-MLC')
168
- * @param settings Options for the model
261
+ * Default WebLLM provider instance
262
+ *
263
+ * @example
264
+ * ```typescript
265
+ * import { webLLM } from "@browser-ai/web-llm";
266
+ *
267
+ * // Language model
268
+ * const chat = webLLM("Llama-3.2-3B-Instruct-q4f16_1-MLC");
269
+ *
270
+ * // Embedding model
271
+ * const embed = webLLM.embeddingModel("snowflake-arctic-embed-m-q0f32-MLC-b32");
272
+ * ```
169
273
  */
170
- declare function webLLM(modelId: WebLLMModelId, settings?: WebLLMSettings): WebLLMLanguageModel;
274
+ declare const webLLM: WebLLMProvider;
171
275
 
172
- export { WebLLMLanguageModel, type WebLLMModelId, type WebLLMSettings, type WebLLMUIMessage, doesBrowserSupportWebLLM, webLLM };
276
+ export { WebLLMEmbeddingModel, type WebLLMEmbeddingModelId, type WebLLMEmbeddingSettings, WebLLMLanguageModel, type WebLLMModelId, type WebLLMProvider, type WebLLMSettings, type WebLLMUIMessage, createWebLLM, doesBrowserSupportWebLLM, webLLM };
package/dist/index.js CHANGED
@@ -20,8 +20,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
+ WebLLMEmbeddingModel: () => WebLLMEmbeddingModel,
23
24
  WebLLMLanguageModel: () => WebLLMLanguageModel,
24
- WebWorkerMLCEngineHandler: () => import_web_llm2.WebWorkerMLCEngineHandler,
25
+ WebWorkerMLCEngineHandler: () => import_web_llm3.WebWorkerMLCEngineHandler,
26
+ createWebLLM: () => createWebLLM,
25
27
  doesBrowserSupportWebLLM: () => doesBrowserSupportWebLLM,
26
28
  webLLM: () => webLLM
27
29
  });
@@ -983,7 +985,7 @@ ${existingContent}` : "")
983
985
  ];
984
986
  }
985
987
 
986
- // src/web-llm-language-model.ts
988
+ // src/utils/browser.ts
987
989
  function isMobile() {
988
990
  if (typeof navigator === "undefined") return false;
989
991
  return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
@@ -1000,6 +1002,8 @@ function checkWebGPU() {
1000
1002
  function doesBrowserSupportWebLLM() {
1001
1003
  return checkWebGPU();
1002
1004
  }
1005
+
1006
+ // src/web-llm-language-model.ts
1003
1007
  function extractToolName(content) {
1004
1008
  const jsonMatch = content.match(/\{\s*"name"\s*:\s*"([^"]+)"/);
1005
1009
  if (jsonMatch) {
@@ -1142,7 +1146,8 @@ var WebLLMLanguageModel = class {
1142
1146
  responseFormat,
1143
1147
  seed,
1144
1148
  tools,
1145
- toolChoice
1149
+ toolChoice,
1150
+ providerOptions
1146
1151
  }) {
1147
1152
  const warnings = [];
1148
1153
  const functionTools = (tools ?? []).filter(isFunctionTool).map((tool) => ({
@@ -1209,6 +1214,12 @@ var WebLLMLanguageModel = class {
1209
1214
  top_p: topP,
1210
1215
  seed
1211
1216
  };
1217
+ if (providerOptions?.extra_body) {
1218
+ requestOptions.extra_body = {
1219
+ enable_thinking: providerOptions.extra_body.enable_thinking,
1220
+ enable_latency_breakdown: providerOptions.extra_body.enable_latency_breakdown
1221
+ };
1222
+ }
1212
1223
  if (responseFormat?.type === "json") {
1213
1224
  requestOptions.response_format = {
1214
1225
  type: "json_object",
@@ -1714,17 +1725,211 @@ var WebLLMLanguageModel = class {
1714
1725
  }
1715
1726
  };
1716
1727
 
1717
- // src/index.ts
1728
+ // src/web-llm-embedding-model.ts
1718
1729
  var import_web_llm2 = require("@mlc-ai/web-llm");
1730
+ var WebLLMEmbeddingModel = class {
1731
+ constructor(modelId, options = {}) {
1732
+ this.specificationVersion = "v3";
1733
+ this.provider = "web-llm";
1734
+ this.supportsParallelCalls = false;
1735
+ this.isInitialized = false;
1736
+ this.modelId = modelId;
1737
+ this.maxEmbeddingsPerCall = options.maxEmbeddingsPerCall ?? 100;
1738
+ this.config = {
1739
+ provider: this.provider,
1740
+ modelId,
1741
+ options
1742
+ };
1743
+ }
1744
+ /**
1745
+ * Check if the model is initialized and ready to use
1746
+ */
1747
+ get isModelInitialized() {
1748
+ return this.isInitialized;
1749
+ }
1750
+ async getEngine(options, onInitProgress) {
1751
+ const availability = await this.availability();
1752
+ if (availability === "unavailable") {
1753
+ throw new LoadSettingError({
1754
+ message: "WebLLM is not available. This library requires a browser with WebGPU support."
1755
+ });
1756
+ }
1757
+ if (this.engine && this.isInitialized) return this.engine;
1758
+ if (this.initializationPromise) {
1759
+ await this.initializationPromise;
1760
+ if (this.engine) return this.engine;
1761
+ }
1762
+ this.initializationPromise = this._initializeEngine(
1763
+ options,
1764
+ onInitProgress
1765
+ );
1766
+ await this.initializationPromise;
1767
+ if (!this.engine) {
1768
+ throw new LoadSettingError({
1769
+ message: "Engine initialization failed"
1770
+ });
1771
+ }
1772
+ return this.engine;
1773
+ }
1774
+ async _initializeEngine(options, onInitProgress) {
1775
+ try {
1776
+ const engineConfig = {
1777
+ ...this.config.options.engineConfig,
1778
+ ...options,
1779
+ initProgressCallback: onInitProgress || this.config.options.initProgressCallback
1780
+ };
1781
+ if (this.config.options.worker) {
1782
+ this.engine = await (0, import_web_llm2.CreateWebWorkerMLCEngine)(
1783
+ this.config.options.worker,
1784
+ this.modelId,
1785
+ engineConfig
1786
+ );
1787
+ } else {
1788
+ this.engine = new import_web_llm2.MLCEngine(engineConfig);
1789
+ await this.engine.reload(this.modelId);
1790
+ }
1791
+ this.isInitialized = true;
1792
+ } catch (error) {
1793
+ this.engine = void 0;
1794
+ this.isInitialized = false;
1795
+ this.initializationPromise = void 0;
1796
+ throw new LoadSettingError({
1797
+ message: `Failed to initialize WebLLM embedding engine: ${error instanceof Error ? error.message : "Unknown error"}`
1798
+ });
1799
+ }
1800
+ }
1801
+ /**
1802
+ * Check the availability of the WebLLM embedding model
1803
+ * @returns Promise resolving to "unavailable", "available", or "downloadable"
1804
+ */
1805
+ async availability() {
1806
+ if (this.isInitialized) {
1807
+ return "available";
1808
+ }
1809
+ if (this.config.options.worker && isMobile()) {
1810
+ return "downloadable";
1811
+ }
1812
+ const supported = checkWebGPU();
1813
+ return supported ? "downloadable" : "unavailable";
1814
+ }
1815
+ /**
1816
+ * Creates an engine session with download progress monitoring.
1817
+ *
1818
+ * @example
1819
+ * ```typescript
1820
+ * const engine = await model.createSessionWithProgress(
1821
+ * (progress) => {
1822
+ * console.log(`Download progress: ${Math.round(progress.progress * 100)}%`);
1823
+ * }
1824
+ * );
1825
+ * ```
1826
+ *
1827
+ * @param onInitProgress Optional callback receiving progress reports during model download
1828
+ * @returns Promise resolving to a configured WebLLM engine
1829
+ * @throws {LoadSettingError} When WebLLM isn't available or model is unavailable
1830
+ */
1831
+ async createSessionWithProgress(onInitProgress) {
1832
+ return this.getEngine(void 0, onInitProgress);
1833
+ }
1834
+ /**
1835
+ * Embed texts using the WebLLM embedding model
1836
+ */
1837
+ async doEmbed(options) {
1838
+ const { values, abortSignal } = options;
1839
+ if (values.length > this.maxEmbeddingsPerCall) {
1840
+ throw new TooManyEmbeddingValuesForCallError({
1841
+ provider: this.provider,
1842
+ modelId: this.modelId,
1843
+ maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
1844
+ values
1845
+ });
1846
+ }
1847
+ if (abortSignal?.aborted) {
1848
+ throw new Error("Operation was aborted");
1849
+ }
1850
+ const engine = await this.getEngine();
1851
+ const abortHandler = () => {
1852
+ engine.interruptGenerate();
1853
+ };
1854
+ if (abortSignal) {
1855
+ abortSignal.addEventListener("abort", abortHandler);
1856
+ }
1857
+ try {
1858
+ const response = await engine.embeddings.create({
1859
+ input: values,
1860
+ model: this.modelId,
1861
+ ...abortSignal && !this.config.options.worker && { signal: abortSignal }
1862
+ });
1863
+ const sortedEmbeddings = response.data.sort((a, b) => a.index - b.index).map((e) => e.embedding);
1864
+ return {
1865
+ embeddings: sortedEmbeddings,
1866
+ usage: {
1867
+ tokens: response.usage.total_tokens
1868
+ },
1869
+ providerMetadata: {
1870
+ webllm: {
1871
+ model: response.model,
1872
+ promptTokens: response.usage.prompt_tokens,
1873
+ totalTokens: response.usage.total_tokens,
1874
+ prefillTokensPerSecond: response.usage.extra?.prefill_tokens_per_s
1875
+ }
1876
+ },
1877
+ warnings: []
1878
+ };
1879
+ } catch (error) {
1880
+ throw new Error(
1881
+ `WebLLM embedding failed: ${error instanceof Error ? error.message : "Unknown error"}`
1882
+ );
1883
+ } finally {
1884
+ if (abortSignal) {
1885
+ abortSignal.removeEventListener("abort", abortHandler);
1886
+ }
1887
+ }
1888
+ }
1889
+ };
1890
+
1891
+ // src/index.ts
1892
+ var import_web_llm3 = require("@mlc-ai/web-llm");
1719
1893
 
1720
1894
  // src/web-llm-provider.ts
1721
- function webLLM(modelId, settings) {
1722
- return new WebLLMLanguageModel(modelId, settings);
1895
+ function createWebLLM() {
1896
+ const createLanguageModel = (modelId, settings) => {
1897
+ return new WebLLMLanguageModel(modelId, settings);
1898
+ };
1899
+ const createEmbeddingModel = (modelId, settings) => {
1900
+ return new WebLLMEmbeddingModel(modelId, settings);
1901
+ };
1902
+ const provider = function(modelId, settings) {
1903
+ if (new.target) {
1904
+ throw new Error(
1905
+ "The WebLLM model function cannot be called with the new keyword."
1906
+ );
1907
+ }
1908
+ return createLanguageModel(modelId, settings);
1909
+ };
1910
+ provider.specificationVersion = "v3";
1911
+ provider.languageModel = createLanguageModel;
1912
+ provider.chat = createLanguageModel;
1913
+ provider.embedding = createEmbeddingModel;
1914
+ provider.embeddingModel = createEmbeddingModel;
1915
+ provider.imageModel = (modelId) => {
1916
+ throw new NoSuchModelError({ modelId, modelType: "imageModel" });
1917
+ };
1918
+ provider.speechModel = (modelId) => {
1919
+ throw new NoSuchModelError({ modelId, modelType: "speechModel" });
1920
+ };
1921
+ provider.transcriptionModel = (modelId) => {
1922
+ throw new NoSuchModelError({ modelId, modelType: "transcriptionModel" });
1923
+ };
1924
+ return provider;
1723
1925
  }
1926
+ var webLLM = createWebLLM();
1724
1927
  // Annotate the CommonJS export names for ESM import in node:
1725
1928
  0 && (module.exports = {
1929
+ WebLLMEmbeddingModel,
1726
1930
  WebLLMLanguageModel,
1727
1931
  WebWorkerMLCEngineHandler,
1932
+ createWebLLM,
1728
1933
  doesBrowserSupportWebLLM,
1729
1934
  webLLM
1730
1935
  });