Skip to content

Commit

Permalink
community[minor]: Update ChatWebLLM to match new API and update example
Browse files Browse the repository at this point in the history
  • Loading branch information
Neet-Nestor committed Jun 16, 2024
1 parent d09f63a commit a0b1636
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
4 changes: 4 additions & 0 deletions examples/src/models/chat/integration_webllm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ const model = new ChatWebLLM({
},
});

await model.initialize((progress) => {
console.log(progress);
});

// Call the model with a message and await the response.
const response = await model.invoke([
new HumanMessage({ content: "What is 1 + 1?" }),
Expand Down
4 changes: 2 additions & 2 deletions libs/langchain-community/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"@langchain/standard-tests": "0.0.0",
"@layerup/layerup-security": "^1.5.12",
"@mendable/firecrawl-js": "^0.0.13",
"@mlc-ai/web-llm": "^0.2.40",
"@mlc-ai/web-llm": "^0.2.46",
"@mozilla/readability": "^0.4.4",
"@neondatabase/serverless": "^0.9.1",
"@notionhq/client": "^2.2.10",
Expand Down Expand Up @@ -241,7 +241,7 @@
"@huggingface/inference": "^2.6.4",
"@layerup/layerup-security": "^1.5.12",
"@mendable/firecrawl-js": "^0.0.13",
"@mlc-ai/web-llm": "^0.2.40",
"@mlc-ai/web-llm": "*",
"@mozilla/readability": "*",
"@neondatabase/serverless": "*",
"@notionhq/client": "^2.2.10",
Expand Down
14 changes: 6 additions & 8 deletions libs/langchain-community/src/chat_models/webllm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ export class ChatWebLLM extends SimpleChatModel<WebLLMCallOptions> {
this.chatOptions = inputs.chatOptions;
this.model = inputs.model;
this.temperature = inputs.temperature;
this.engine = new webllm.MLCEngine();
this.engine = new webllm.MLCEngine({
appConfig: this.appConfig,
});
}

_llmType() {
Expand All @@ -74,15 +76,11 @@ export class ChatWebLLM extends SimpleChatModel<WebLLMCallOptions> {
if (progressCallback !== undefined) {
this.engine.setInitProgressCallback(progressCallback);
}
await this.reload(this.model, this.chatOptions, this.appConfig);
await this.reload(this.model, this.chatOptions);
}

async reload(
modelId: string,
newChatOpts?: webllm.ChatOptions,
newAppConfig?: webllm.AppConfig
) {
await this.engine.reload(modelId, newChatOpts, newAppConfig);
async reload(modelId: string, newChatOpts?: webllm.ChatOptions) {
await this.engine.reload(modelId, newChatOpts);
}

async *_streamResponseChunks(
Expand Down
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9603,7 +9603,7 @@ __metadata:
"@langchain/standard-tests": 0.0.0
"@layerup/layerup-security": ^1.5.12
"@mendable/firecrawl-js": ^0.0.13
"@mlc-ai/web-llm": ^0.2.40
"@mlc-ai/web-llm": ^0.2.46
"@mozilla/readability": ^0.4.4
"@neondatabase/serverless": ^0.9.1
"@notionhq/client": ^2.2.10
Expand Down Expand Up @@ -9770,7 +9770,7 @@ __metadata:
"@huggingface/inference": ^2.6.4
"@layerup/layerup-security": ^1.5.12
"@mendable/firecrawl-js": ^0.0.13
"@mlc-ai/web-llm": ^0.2.40
"@mlc-ai/web-llm": "*"
"@mozilla/readability": "*"
"@neondatabase/serverless": "*"
"@notionhq/client": ^2.2.10
Expand Down Expand Up @@ -10998,12 +10998,12 @@ __metadata:
languageName: node
linkType: hard

"@mlc-ai/web-llm@npm:^0.2.40":
version: 0.2.40
resolution: "@mlc-ai/web-llm@npm:0.2.40"
"@mlc-ai/web-llm@npm:^0.2.46":
version: 0.2.46
resolution: "@mlc-ai/web-llm@npm:0.2.46"
dependencies:
loglevel: ^1.9.1
checksum: 44d46178f7b7f899893ee8096fd4188b8c343589a10428c52f87b1b7e708f7a94b2b6315c8a6f8075f14d6d92aebfd8afc7f6d049a2ef60f8b8dc950b98a82e2
checksum: 09c83a45d7f9351ae492d8704fe580868d0b46b640eca232ebc76d552f2ffad031c9c504a0d29f69122029478af270eeeda0800e7fb032b00c11dc1632e1ae11
languageName: node
linkType: hard

Expand Down

0 comments on commit a0b1636

Please sign in to comment.