@eclipse-docks/extension-webllm 0.7.139 → 0.8.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/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/webllmservice-Dk9S19ds.js +87 -0
- package/dist/webllmservice-Dk9S19ds.js.map +1 -0
- package/dist/webllmservice.d.ts.map +1 -1
- package/package.json +9 -9
- package/dist/webllmservice-lr842hZg.js +0 -50
- package/dist/webllmservice-lr842hZg.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -9,9 +9,10 @@ extensionRegistry.registerExtension({
|
|
|
9
9
|
id: pkg.name,
|
|
10
10
|
name: t.EXT_WEBLLM_NAME,
|
|
11
11
|
description: t.EXT_WEBLLM_DESC,
|
|
12
|
-
loader: () => import("./webllmservice-
|
|
12
|
+
loader: () => import("./webllmservice-Dk9S19ds.js"),
|
|
13
13
|
icon: "robot",
|
|
14
|
-
experimental: true
|
|
14
|
+
experimental: true,
|
|
15
|
+
dependencies: ["@eclipse-docks/extension-ai-system"]
|
|
15
16
|
});
|
|
16
17
|
//#endregion
|
|
17
18
|
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { extensionRegistry, i18n } from '@eclipse-docks/core';\nimport pkg from '../package.json';\n\nconst t = await i18n(import.meta.glob('./i18n*.json'), true);\n\nextensionRegistry.registerExtension({\n id: pkg.name,\n name: t.EXT_WEBLLM_NAME,\n description: t.EXT_WEBLLM_DESC,\n loader: () => import(
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { extensionRegistry, i18n } from '@eclipse-docks/core';\nimport pkg from '../package.json';\n\nconst t = await i18n(import.meta.glob('./i18n*.json'), true);\n\nextensionRegistry.registerExtension({\n id: pkg.name,\n name: t.EXT_WEBLLM_NAME,\n description: t.EXT_WEBLLM_DESC,\n loader: () => import('./webllmservice'),\n icon: 'robot',\n experimental: true,\n dependencies: ['@eclipse-docks/extension-ai-system'],\n});\n"],"mappings":";;;AAGA,IAAM,IAAI,MAAM,KAAK,uBAAA,OAAA;CAAA,wBAAA,OAAA;CAAA,wBAAA,OAAA;AAAA,CAAA,GAAkC,IAAI;AAE3D,kBAAkB,kBAAkB;CAClC,IAAI,IAAI;CACR,MAAM,EAAE;CACR,aAAa,EAAE;CACf,cAAc,OAAO;CACrB,MAAM;CACN,cAAc;CACd,cAAc,CAAC,oCAAoC;AACrD,CAAC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { createLogger } from "@eclipse-docks/core";
|
|
2
|
+
import { cognitiveRuntime } from "@eclipse-docks/extension-ai-system/api";
|
|
3
|
+
import { MLCEngine } from "@mlc-ai/web-llm";
|
|
4
|
+
//#region src/webllmservice.ts
|
|
5
|
+
var logger = createLogger("WebLLM");
|
|
6
|
+
var DEFAULT_MODELS = [{
|
|
7
|
+
id: "Llama-3.2-1B-Instruct-q4f16_1-MLC",
|
|
8
|
+
name: "Llama 3.2 1B (WebLLM)"
|
|
9
|
+
}, {
|
|
10
|
+
id: "Llama-3.2-3B-Instruct-q4f16_1-MLC",
|
|
11
|
+
name: "Llama 3.2 3B (WebLLM)"
|
|
12
|
+
}];
|
|
13
|
+
var WebLLMProvider = class {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.id = "webllm";
|
|
16
|
+
}
|
|
17
|
+
listModels() {
|
|
18
|
+
return DEFAULT_MODELS;
|
|
19
|
+
}
|
|
20
|
+
async init(model) {
|
|
21
|
+
if (this.engine && this.loadedModel === model) return;
|
|
22
|
+
const initProgressCallback = (progress) => {
|
|
23
|
+
logger.debug("Model loading progress:", progress);
|
|
24
|
+
};
|
|
25
|
+
this.engine = new MLCEngine({ initProgressCallback });
|
|
26
|
+
await this.engine.reload(model);
|
|
27
|
+
this.loadedModel = model;
|
|
28
|
+
}
|
|
29
|
+
async *stream(params) {
|
|
30
|
+
const model = params.model.includes("/") ? params.model.split("/").slice(1).join("/") : params.model;
|
|
31
|
+
try {
|
|
32
|
+
await this.init(model || DEFAULT_MODELS[0].id);
|
|
33
|
+
} catch (err) {
|
|
34
|
+
yield {
|
|
35
|
+
type: "error",
|
|
36
|
+
error: err instanceof Error ? err.message : String(err)
|
|
37
|
+
};
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const messages = params.messages.map(toWebLLMMessage);
|
|
41
|
+
try {
|
|
42
|
+
const content = (await this.engine.chat.completions.create({ messages })).choices[0]?.message?.content;
|
|
43
|
+
if (typeof content === "string" && content) yield {
|
|
44
|
+
type: "text",
|
|
45
|
+
text: content
|
|
46
|
+
};
|
|
47
|
+
yield { type: "done" };
|
|
48
|
+
} catch (err) {
|
|
49
|
+
yield {
|
|
50
|
+
type: "error",
|
|
51
|
+
error: err instanceof Error ? err.message : String(err)
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
function toWebLLMMessage(message) {
|
|
57
|
+
if (message.role === "tool") return {
|
|
58
|
+
role: "tool",
|
|
59
|
+
tool_call_id: message.toolCallId ?? "",
|
|
60
|
+
content: message.content
|
|
61
|
+
};
|
|
62
|
+
if (message.role === "assistant" && message.toolCalls?.length) return {
|
|
63
|
+
role: "assistant",
|
|
64
|
+
content: message.content || null,
|
|
65
|
+
tool_calls: message.toolCalls.map((tc) => ({
|
|
66
|
+
id: tc.id,
|
|
67
|
+
type: "function",
|
|
68
|
+
function: {
|
|
69
|
+
name: tc.name,
|
|
70
|
+
arguments: tc.arguments || "{}"
|
|
71
|
+
}
|
|
72
|
+
}))
|
|
73
|
+
};
|
|
74
|
+
return {
|
|
75
|
+
role: message.role,
|
|
76
|
+
content: message.content
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
var webllmservice_default = () => {
|
|
80
|
+
cognitiveRuntime.start();
|
|
81
|
+
cognitiveRuntime.registerExternalProvider(new WebLLMProvider());
|
|
82
|
+
logger.info("WebLLM provider registered");
|
|
83
|
+
};
|
|
84
|
+
//#endregion
|
|
85
|
+
export { webllmservice_default as default };
|
|
86
|
+
|
|
87
|
+
//# sourceMappingURL=webllmservice-Dk9S19ds.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webllmservice-Dk9S19ds.js","names":[],"sources":["../src/webllmservice.ts"],"sourcesContent":["import { createLogger } from '@eclipse-docks/core';\nimport {\n cognitiveRuntime,\n type ModelProvider,\n type ProviderChatMessage,\n type StreamChunk,\n type StreamParams,\n} from '@eclipse-docks/extension-ai-system/api';\nimport { ChatCompletionMessageParam, MLCEngine } from '@mlc-ai/web-llm';\n\nconst logger = createLogger('WebLLM');\n\nconst DEFAULT_MODELS = [\n { id: 'Llama-3.2-1B-Instruct-q4f16_1-MLC', name: 'Llama 3.2 1B (WebLLM)' },\n { id: 'Llama-3.2-3B-Instruct-q4f16_1-MLC', name: 'Llama 3.2 3B (WebLLM)' },\n];\n\nclass WebLLMProvider implements ModelProvider {\n readonly id = 'webllm';\n private engine?: MLCEngine;\n private loadedModel?: string;\n\n listModels(): Array<{ id: string; name: string }> {\n return DEFAULT_MODELS;\n }\n\n private async init(model: string): Promise<void> {\n if (this.engine && this.loadedModel === model) return;\n\n const initProgressCallback = (progress: unknown) => {\n logger.debug('Model loading progress:', progress);\n };\n\n this.engine = new MLCEngine({ initProgressCallback });\n await this.engine.reload(model);\n this.loadedModel = model;\n }\n\n async *stream(params: StreamParams): AsyncIterable<StreamChunk> {\n const model = params.model.includes('/') ? params.model.split('/').slice(1).join('/') : params.model;\n try {\n await this.init(model || DEFAULT_MODELS[0]!.id);\n } catch (err) {\n yield { type: 'error', error: err instanceof Error ? err.message : String(err) };\n return;\n }\n\n const messages = params.messages.map(toWebLLMMessage);\n try {\n const result = await this.engine!.chat.completions.create({ messages });\n const content = result.choices[0]?.message?.content;\n if (typeof content === 'string' && content) {\n yield { type: 'text', text: content };\n }\n yield { type: 'done' };\n } catch (err) {\n yield { type: 'error', error: err instanceof Error ? err.message : String(err) };\n }\n }\n}\n\nfunction toWebLLMMessage(message: ProviderChatMessage): ChatCompletionMessageParam {\n if (message.role === 'tool') {\n return {\n role: 'tool',\n tool_call_id: message.toolCallId ?? '',\n content: message.content,\n } as ChatCompletionMessageParam;\n }\n if (message.role === 'assistant' && message.toolCalls?.length) {\n return {\n role: 'assistant',\n content: message.content || null,\n tool_calls: message.toolCalls.map((tc) => ({\n id: tc.id,\n type: 'function' as const,\n function: { name: tc.name, arguments: tc.arguments || '{}' },\n })),\n } as ChatCompletionMessageParam;\n }\n return {\n role: message.role,\n content: message.content,\n } as ChatCompletionMessageParam;\n}\n\nexport default () => {\n cognitiveRuntime.start();\n cognitiveRuntime.registerExternalProvider(new WebLLMProvider());\n logger.info('WebLLM provider registered');\n};\n"],"mappings":";;;;AAUA,IAAM,SAAS,aAAa,QAAQ;AAEpC,IAAM,iBAAiB,CACrB;CAAE,IAAI;CAAqC,MAAM;AAAwB,GACzE;CAAE,IAAI;CAAqC,MAAM;AAAwB,CAC3E;AAEA,IAAM,iBAAN,MAA8C;;EAC9B,KAAA,KAAA;;CAId,aAAkD;EAChD,OAAO;CACT;CAEA,MAAc,KAAK,OAA8B;EAC/C,IAAI,KAAK,UAAU,KAAK,gBAAgB,OAAO;EAE/C,MAAM,wBAAwB,aAAsB;GAClD,OAAO,MAAM,2BAA2B,QAAQ;EAClD;EAEA,KAAK,SAAS,IAAI,UAAU,EAAE,qBAAqB,CAAC;EACpD,MAAM,KAAK,OAAO,OAAO,KAAK;EAC9B,KAAK,cAAc;CACrB;CAEA,OAAO,OAAO,QAAkD;EAC9D,MAAM,QAAQ,OAAO,MAAM,SAAS,GAAG,IAAI,OAAO,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,OAAO;EAC/F,IAAI;GACF,MAAM,KAAK,KAAK,SAAS,eAAe,EAAE,CAAE,EAAE;EAChD,SAAS,KAAK;GACZ,MAAM;IAAE,MAAM;IAAS,OAAO,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;GAAE;GAC/E;EACF;EAEA,MAAM,WAAW,OAAO,SAAS,IAAI,eAAe;EACpD,IAAI;GAEF,MAAM,WAAU,MADK,KAAK,OAAQ,KAAK,YAAY,OAAO,EAAE,SAAS,CAAC,EAAA,CAC/C,QAAQ,EAAE,EAAE,SAAS;GAC5C,IAAI,OAAO,YAAY,YAAY,SACjC,MAAM;IAAE,MAAM;IAAQ,MAAM;GAAQ;GAEtC,MAAM,EAAE,MAAM,OAAO;EACvB,SAAS,KAAK;GACZ,MAAM;IAAE,MAAM;IAAS,OAAO,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;GAAE;EACjF;CACF;AACF;AAEA,SAAS,gBAAgB,SAA0D;CACjF,IAAI,QAAQ,SAAS,QACnB,OAAO;EACL,MAAM;EACN,cAAc,QAAQ,cAAc;EACpC,SAAS,QAAQ;CACnB;CAEF,IAAI,QAAQ,SAAS,eAAe,QAAQ,WAAW,QACrD,OAAO;EACL,MAAM;EACN,SAAS,QAAQ,WAAW;EAC5B,YAAY,QAAQ,UAAU,KAAK,QAAQ;GACzC,IAAI,GAAG;GACP,MAAM;GACN,UAAU;IAAE,MAAM,GAAG;IAAM,WAAW,GAAG,aAAa;GAAK;EAC7D,EAAE;CACJ;CAEF,OAAO;EACL,MAAM,QAAQ;EACd,SAAS,QAAQ;CACnB;AACF;AAEA,IAAA,8BAAqB;CACnB,iBAAiB,MAAM;CACvB,iBAAiB,yBAAyB,IAAI,eAAe,CAAC;CAC9D,OAAO,KAAK,4BAA4B;AAC1C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webllmservice.d.ts","sourceRoot":"","sources":["../src/webllmservice.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"webllmservice.d.ts","sourceRoot":"","sources":["../src/webllmservice.ts"],"names":[],"mappings":";AAsFA,wBAIE"}
|
package/package.json
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eclipse-docks/extension-webllm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
6
8
|
"exports": {
|
|
7
9
|
".": {
|
|
8
10
|
"types": "./dist/index.d.ts",
|
|
9
11
|
"import": "./dist/index.js"
|
|
10
12
|
}
|
|
11
13
|
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "vite build"
|
|
19
|
+
},
|
|
12
20
|
"dependencies": {
|
|
13
21
|
"@eclipse-docks/core": "*",
|
|
14
22
|
"@eclipse-docks/extension-ai-system": "*",
|
|
@@ -19,14 +27,6 @@
|
|
|
19
27
|
"vite": "^8.0.0",
|
|
20
28
|
"vite-plugin-dts": "^4.5.4"
|
|
21
29
|
},
|
|
22
|
-
"module": "./dist/index.js",
|
|
23
|
-
"types": "./dist/index.d.ts",
|
|
24
|
-
"files": [
|
|
25
|
-
"dist"
|
|
26
|
-
],
|
|
27
|
-
"scripts": {
|
|
28
|
-
"build": "vite build"
|
|
29
|
-
},
|
|
30
30
|
"repository": {
|
|
31
31
|
"type": "git",
|
|
32
32
|
"url": "https://github.com/eclipse-docks/core"
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { createLogger } from "@eclipse-docks/core";
|
|
2
|
-
import { MLCEngine } from "@mlc-ai/web-llm";
|
|
3
|
-
import { aiService } from "@eclipse-docks/extension-ai-system/api";
|
|
4
|
-
//#region src/webllmservice.ts
|
|
5
|
-
var logger = createLogger("WebLLM");
|
|
6
|
-
var WebLLMProvider = class {
|
|
7
|
-
constructor() {
|
|
8
|
-
this.name = "webllm";
|
|
9
|
-
}
|
|
10
|
-
canHandle(chatProvider) {
|
|
11
|
-
return chatProvider.name === "webllm";
|
|
12
|
-
}
|
|
13
|
-
async init(model, parameters) {
|
|
14
|
-
if (this.engine) return;
|
|
15
|
-
const initProgressCallback = (progress) => {
|
|
16
|
-
logger.debug("Model loading progress:", progress);
|
|
17
|
-
};
|
|
18
|
-
this.engine = new MLCEngine({ initProgressCallback });
|
|
19
|
-
await this.engine.reload(model, parameters);
|
|
20
|
-
}
|
|
21
|
-
async *stream(params) {
|
|
22
|
-
if (!this.engine) await this.init(params.model, params.chatConfig.parameters);
|
|
23
|
-
const internalMessages = params.messages.map((message) => {
|
|
24
|
-
return { ...message };
|
|
25
|
-
});
|
|
26
|
-
const message = (await this.engine.chat.completions.create({ messages: internalMessages })).choices[0].message;
|
|
27
|
-
if (message.content) for (const char of message.content) yield {
|
|
28
|
-
type: "token",
|
|
29
|
-
content: char
|
|
30
|
-
};
|
|
31
|
-
yield {
|
|
32
|
-
type: "done",
|
|
33
|
-
content: ""
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
async complete(params) {
|
|
37
|
-
if (!this.engine) await this.init(params.model, params.chatConfig.parameters);
|
|
38
|
-
const internalMessages = params.messages.map((message) => {
|
|
39
|
-
return { ...message };
|
|
40
|
-
});
|
|
41
|
-
return (await this.engine.chat.completions.create({ messages: internalMessages })).choices[0].message;
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
var webllmservice_default = () => {
|
|
45
|
-
aiService.registerStreamingFetcher(new WebLLMProvider());
|
|
46
|
-
};
|
|
47
|
-
//#endregion
|
|
48
|
-
export { webllmservice_default as default };
|
|
49
|
-
|
|
50
|
-
//# sourceMappingURL=webllmservice-lr842hZg.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"webllmservice-lr842hZg.js","names":[],"sources":["../src/webllmservice.ts"],"sourcesContent":["import {ChatCompletionMessageParam, MLCEngine} from \"@mlc-ai/web-llm\";\nimport { createLogger } from \"@eclipse-docks/core\";\nimport type {ChatMessage, ChatProvider, StreamChunk} from \"@eclipse-docks/extension-ai-system/api\";\n\nconst logger = createLogger('WebLLM');\nimport type {IProvider, StreamingParams, CompletionParams} from \"@eclipse-docks/extension-ai-system/api\";\nimport {aiService} from \"@eclipse-docks/extension-ai-system/api\";\n\nclass WebLLMProvider implements IProvider {\n name = \"webllm\";\n private engine?: MLCEngine;\n\n canHandle(chatProvider: ChatProvider): boolean {\n return chatProvider.name === \"webllm\";\n }\n\n private async init(model: string, parameters?: any): Promise<void> {\n if (this.engine) return;\n \n const initProgressCallback = (progress: any) => {\n logger.debug(\"Model loading progress:\", progress);\n };\n\n this.engine = new MLCEngine({initProgressCallback});\n await this.engine.reload(model, parameters);\n }\n\n async *stream(params: StreamingParams): AsyncIterable<StreamChunk> {\n if (!this.engine) {\n await this.init(params.model, params.chatConfig.parameters);\n }\n \n const internalMessages = params.messages.map((message) => {\n return {...message} as ChatCompletionMessageParam;\n });\n \n const result = await this.engine!.chat.completions.create({\n messages: internalMessages\n });\n \n const message = result.choices[0].message as ChatMessage;\n \n if (message.content) {\n for (const char of message.content) {\n yield {\n type: 'token',\n content: char\n };\n }\n }\n \n yield {\n type: 'done',\n content: ''\n };\n }\n\n async complete(params: CompletionParams): Promise<ChatMessage> {\n if (!this.engine) {\n await this.init(params.model, params.chatConfig.parameters);\n }\n \n const internalMessages = params.messages.map((message) => {\n return {...message} as ChatCompletionMessageParam;\n });\n \n const result = await this.engine!.chat.completions.create({\n messages: internalMessages\n });\n \n return result.choices[0].message as ChatMessage;\n }\n}\n\nexport default () => {\n aiService.registerStreamingFetcher(new WebLLMProvider());\n}"],"mappings":";;;;AAIA,IAAM,SAAS,aAAa,QAAQ;AAIpC,IAAM,iBAAN,MAA0C;;EAC/B,KAAA,OAAA;;CAGP,UAAU,cAAqC;EAC3C,OAAO,aAAa,SAAS;CACjC;CAEA,MAAc,KAAK,OAAe,YAAiC;EAC/D,IAAI,KAAK,QAAQ;EAEjB,MAAM,wBAAwB,aAAkB;GAC5C,OAAO,MAAM,2BAA2B,QAAQ;EACpD;EAEA,KAAK,SAAS,IAAI,UAAU,EAAC,qBAAoB,CAAC;EAClD,MAAM,KAAK,OAAO,OAAO,OAAO,UAAU;CAC9C;CAEA,OAAO,OAAO,QAAqD;EAC/D,IAAI,CAAC,KAAK,QACN,MAAM,KAAK,KAAK,OAAO,OAAO,OAAO,WAAW,UAAU;EAG9D,MAAM,mBAAmB,OAAO,SAAS,KAAK,YAAY;GACtD,OAAO,EAAC,GAAG,QAAO;EACtB,CAAC;EAMD,MAAM,WAAU,MAJK,KAAK,OAAQ,KAAK,YAAY,OAAO,EACtD,UAAU,iBACd,CAAC,EAAA,CAEsB,QAAQ,EAAE,CAAC;EAElC,IAAI,QAAQ,SACR,KAAK,MAAM,QAAQ,QAAQ,SACvB,MAAM;GACF,MAAM;GACN,SAAS;EACb;EAIR,MAAM;GACF,MAAM;GACN,SAAS;EACb;CACJ;CAEA,MAAM,SAAS,QAAgD;EAC3D,IAAI,CAAC,KAAK,QACN,MAAM,KAAK,KAAK,OAAO,OAAO,OAAO,WAAW,UAAU;EAG9D,MAAM,mBAAmB,OAAO,SAAS,KAAK,YAAY;GACtD,OAAO,EAAC,GAAG,QAAO;EACtB,CAAC;EAMD,QAAO,MAJc,KAAK,OAAQ,KAAK,YAAY,OAAO,EACtD,UAAU,iBACd,CAAC,EAAA,CAEa,QAAQ,EAAE,CAAC;CAC7B;AACJ;AAEA,IAAA,8BAAqB;CACjB,UAAU,yBAAyB,IAAI,eAAe,CAAC;AAC3D"}
|