Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preload inference and embedding models #175

Merged
merged 1 commit into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/components/ChatBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
DEFAULT_HOST,
apiConnected,
getLumosOptions,
preloadModel,
} from "../pages/Options";
import { getHtmlContent } from "../scripts/content";

Expand Down Expand Up @@ -506,7 +507,13 @@ const ChatBar: React.FC = () => {

useEffect(() => {
chrome.storage.local.get(
["chatContainerHeight", "selectedModel", "selectedHost", "chatHistory"],
[
"chatContainerHeight",
"selectedModel",
"selectedEmbeddingModel",
"selectedHost",
"chatHistory",
],
async (data) => {
if (data.chatContainerHeight) {
setChatContainerHeight(data.chatContainerHeight);
Expand Down Expand Up @@ -540,6 +547,16 @@ const ChatBar: React.FC = () => {
// persist selected model to local storage
chrome.storage.local.set({ selectedModel: models[0] });
}

// preload inference model
const inferenceModel = data.selectedModel || models[0];
preloadModel(selectedHost, inferenceModel);

// preload embedding model
const embeddingModel = data.selectedEmbeddingModel || inferenceModel;
if (embeddingModel !== inferenceModel) {
preloadModel(selectedHost, embeddingModel, true);
}
} else {
setPromptError(true);
setPromptPlaceholderText(errMsg);
Expand Down
24 changes: 24 additions & 0 deletions src/pages/Options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,20 @@ export const apiConnected = async (
return [false, [], errMsg];
};

export const preloadModel = async (
host: string,
model: string,
isEmbedding = false,
): Promise<void> => {
fetch(`${host}/api/${isEmbedding ? "embeddings" : "chat"}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ model: model }),
});
};

const Options: React.FC = () => {
const [model, setModel] = useState("");
const [embeddingModel, setEmbeddingModel] = useState("");
Expand Down Expand Up @@ -283,6 +297,16 @@ const Options: React.FC = () => {
if (data.selectedEmbeddingModel) {
setEmbeddingModel(data.selectedEmbeddingModel);
}

// preload inference model
const inferenceModel = data.selectedModel || models[0];
preloadModel(selectedHost, inferenceModel);

// preload embedding model
const embeddingModel = data.selectedEmbeddingModel || inferenceModel;
if (embeddingModel !== inferenceModel) {
preloadModel(selectedHost, embeddingModel, true);
}
} else {
setHostError(true);
setHostHelpText(errMsg);
Expand Down
Loading