Add LM Studio to embedding models (#948)

This commit is contained in:
Logan Yang 2024-12-19 14:40:34 -08:00 committed by GitHub
parent 45fe1e2eac
commit 31d2ba7ccf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 3 deletions

View file

@ -3,8 +3,8 @@ import { CustomModel } from "@/aiParams";
import { EmbeddingModelProviders } from "@/constants";
import { getDecryptedKey } from "@/encryptionService";
import { CustomError } from "@/error";
import { safeFetch } from "@/utils";
import { getSettings, subscribeToSettingsChange } from "@/settings/model";
import { safeFetch } from "@/utils";
import { CohereEmbeddings } from "@langchain/cohere";
import { Embeddings } from "@langchain/core/embeddings";
import { GoogleGenerativeAIEmbeddings } from "@langchain/google-genai";
@ -19,6 +19,7 @@ const EMBEDDING_PROVIDER_CONSTRUCTORS = {
[EmbeddingModelProviders.GOOGLE]: GoogleGenerativeAIEmbeddings,
[EmbeddingModelProviders.AZURE_OPENAI]: OpenAIEmbeddings,
[EmbeddingModelProviders.OLLAMA]: OllamaEmbeddings,
[EmbeddingModelProviders.LM_STUDIO]: OpenAIEmbeddings,
[EmbeddingModelProviders.OPENAI_FORMAT]: OpenAIEmbeddings,
} as const;
@ -43,6 +44,7 @@ export default class EmbeddingManager {
[EmbeddingModelProviders.GOOGLE]: () => getSettings().googleApiKey,
[EmbeddingModelProviders.AZURE_OPENAI]: () => getSettings().azureOpenAIApiKey,
[EmbeddingModelProviders.OLLAMA]: () => "default-key",
[EmbeddingModelProviders.LM_STUDIO]: () => "default-key",
[EmbeddingModelProviders.OPENAI_FORMAT]: () => "",
};
@ -196,6 +198,14 @@ export default class EmbeddingManager {
model: modelName,
truncate: true,
},
[EmbeddingModelProviders.LM_STUDIO]: {
modelName,
openAIApiKey: getDecryptedKey(customModel.apiKey || "default-key"),
configuration: {
baseURL: customModel.baseUrl || "http://localhost:1234/v1",
fetch: customModel.enableCors ? safeFetch : undefined,
},
},
[EmbeddingModelProviders.OPENAI_FORMAT]: {
modelName,
openAIApiKey: getDecryptedKey(customModel.apiKey || ""),

View file

@ -123,6 +123,7 @@ export enum EmbeddingModelProviders {
GOOGLE = "google",
AZURE_OPENAI = "azure_openai",
OLLAMA = "ollama",
LM_STUDIO = "lm-studio",
OPENAI_FORMAT = "3rd party (openai-format)",
// HUGGINGFACE = "huggingface",
// VOYAGEAI = "voyageai",

View file

@ -32,7 +32,6 @@ const QASettings: React.FC<QASettingsProps> = ({ vectorStoreManager }) => {
if (modelKey !== settings.embeddingModelKey) {
new RebuildIndexConfirmModal(app, async () => {
updateSetting("embeddingModelKey", modelKey);
await vectorStoreManager.indexVaultToVectorStore(true);
}).open();
}
};
@ -119,7 +118,7 @@ const QASettings: React.FC<QASettingsProps> = ({ vectorStoreManager }) => {
<br />
<SliderComponent
name="Max Sources"
description="Copilot goes through your vault to find relevant blocks and passes the top N blocks to the LLM. Default for N is 3. Increase if you want more sources included in the answer generation step."
description="Copilot goes through your vault to find relevant blocks and passes the top N blocks to the LLM. Default for N is 3. Increase if you want more sources included in the answer generation step. WARNING: more sources significantly degrades answer quality if the chat model is weak!"
min={1}
max={30}
step={1}