Comments (5)
Hey @kaiwinut! 👋 I'm here to help you with bug fixes, answer questions, and even guide you on becoming a contributor. If you need assistance, feel free to ask.
To resolve the issue with initializing ChatWebLLM
due to the renaming of the Engine
class to MLCEngine
in the @mlc-ai/web-llm
package, you need to update your code to use MLCEngine
instead of Engine
. Here is the updated code:
import { ChatWebLLM } from '@langchain/community/chat_models/webllm';
import * as webllm from "@mlc-ai/web-llm";
webllmModel = new ChatWebLLM({
model: 'Phi2-q4f32_1',
chatOptions: {
temperature: 0.1
}
});
await webllmModel.initialize();
Additionally, ensure that your ChatWebLLM
class is updated to use MLCEngine
as shown in the libs/langchain-community/src/chat_models/webllm.ts
file:
import * as webllm from "@mlc-ai/web-llm";
export class ChatWebLLM extends SimpleChatModel<WebLLMCallOptions> {
protected engine: webllm.MLCEngine;
async initialize(progressCallback?: webllm.InitProgressCallback) {
this.engine = new webllm.MLCEngine();
if (progressCallback !== undefined) {
this.engine.setInitProgressCallback(progressCallback);
}
await this.reload(this.model, this.chatOptions, this.appConfig);
this.engine.setInitProgressCallback(() => {});
}
async reload(
modelId: string,
newAppConfig?: webllm.AppConfig,
newChatOpts?: webllm.ChatOptions
) {
if (this.engine !== undefined) {
await this.engine.reload(modelId, newAppConfig, newChatOpts);
} else {
throw new Error("Initialize model before reloading.");
}
}
async *_streamResponseChunks(
messages: BaseMessage[],
options: this["ParsedCallOptions"],
runManager?: CallbackManagerForLLMRun
): AsyncGenerator<ChatGenerationChunk> {
await this.initialize();
const messagesInput: ChatCompletionMessageParam[] = messages.map(
(message) => {
if (typeof message.content !== "string") {
throw new Error(
"ChatWebLLM does not support non-string message content in sessions."
);
}
const langChainType = message._getType();
let role;
if (langChainType === "ai") {
role = "assistant" as const;
} else if (langChainType === "human") {
role = "user" as const;
} else if (langChainType === "system") {
role = "system" as const;
} else {
throw new Error(
"Function, tool, and generic messages are not supported."
);
}
return {
role,
content: message.content,
};
}
);
const stream = this.engine.chatCompletionAsyncChunkGenerator(
{
stream: true,
messages: messagesInput,
stop: options.stop,
logprobs: true,
},
{}
);
for await (const chunk of stream) {
const text = chunk.choices[0].delta.content ?? "";
yield new ChatGenerationChunk({
text,
message: new AIMessageChunk({
content: text,
additional_kwargs: {
logprobs: chunk.choices[0].logprobs,
finish_reason: chunk.choices[0].finish_reason,
},
}),
});
await runManager?.handleLLMNewToken(text ?? "");
}
}
async _call(
messages: BaseMessage[],
options: this["ParsedCallOptions"],
runManager?: CallbackManagerForLLMRun
): Promise<string> {
const chunks = [];
for await (const chunk of this._streamResponseChunks(
messages,
options,
runManager
)) {
chunks.push(chunk.text);
}
return chunks.join("");
}
}
This change updates the ChatWebLLM
class to use MLCEngine
instead of Engine
, aligning with the recent renaming in the @mlc-ai/web-llm
package [1].
To continue talking to Dosu, mention @dosu.
from langchainjs.
Live in community 0.2.6
from langchainjs.
Sorry, just figured that there's already a related PR #5637 ...
from langchainjs.
Merged that one, will ship community today!
from langchainjs.
Thanks a lot for the great work!
I found out some other tiny issues in the code and example.
Just created a PR #5671 to fix them.
from langchainjs.
Related Issues (20)
- text to sql Error occurred: Error: (f-string) Missing value for input query HOT 2
- ChatGoogleGenerativeAI: Invalid JSON payload received HOT 4
- Error "Unknown / unsupported author: tool" when using Gemini (@langchain/google-genai) with AgentExecutor HOT 7
- DOC: <Issue related to /v0.2/docs/integrations/document_loaders/web_loaders/youtube/>
- Issue with RemoteRunnable and custom 'LangServe' endpoint... The issue seems to be in reviving the results of my BaseMessages HOT 5
- PostgresRecordManager creates table named `undefined` HOT 1
- Json Loader is not working HOT 1
- GitHub Workflow Failures in Langchain Integrations After PR 5733 HOT 2
- [Community] Milvus HOT 2
- TypeError: getDefaultAgent is not a function HOT 4
- GoogleGenerativeAIError: [400 Bad Request] Invalid JSON payload received. HOT 3
- Gmail tools are not allowing providing a subject to impersonate when connecting with a GCP ServiceAccount HOT 3
- Error occurred: Error: (f-string) Missing value for input Question ( Promnt Template) HOT 1
- Confluence loader only returns partial `pageContent` HOT 4
- google-common google-genai [feature]: Context Caching HOT 1
- Can not import faiss-node from Electron.js 'main HOT 6
- Cannot convert langchain's ReadableStream to node ReadableStream HOT 4
- Update langchain create agent functions to accept oai formatted tools
- DOC: Use TypeScript syntax on /v0.2/docs/tutorials/chatbot/ code block HOT 1
- Patch for using LCEL to stream from LLM HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from langchainjs.