-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Allow use of any embedder for any llm/update data handling modal #386
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
Allow use of any embedder for any llm/update data handling modal #386
Conversation
frontend/src/pages/GeneralSettings/EmbeddingPreference/index.jsxConsider using destructuring assignment for the state variables to make the code more readable and cleaner. const { LLMProvider, VectorDB, EmbeddingEngine } = await System.keys();
setLLMChoice(LLMProvider);
setVectorDb(VectorDB);
setEmbeddingEngine(EmbeddingEngine);Consider using React.memo for the functional components to avoid unnecessary re-renders and improve the performance of the application. const LLMProviderOption = React.memo(({ name, value, link, description, checked, image, onClick }) => {
// component code
});Consider using a switch statement instead of multiple if statements to make the code more readable and easier to maintain. switch (embeddingChoice) {
case "openai":
// code for openai
break;
case "azure":
// code for azure
break;
case "localai":
// code for localai
break;
default:
// default code
}server/endpoints/admin.js, server/endpoints/api/admin/index.jsInstead of using console.error(e) and then sending a response with status 500, it would be better to create a middleware for error handling. This would improve the readability of the code and make it easier to manage errors. function errorHandler (err, req, res, next) {
console.error(err);
res.status(500).end();
}
app.use(errorHandler);It would be better to separate the routes into different files based on their functionality. This would make the code more readable and easier to maintain. // users.js
app.get("/admin/users", [validatedRequest, strictMultiUserRoleValid], getUsers);
app.post("/admin/users/new", [validatedRequest, strictMultiUserRoleValid], createUser);
// ...
// workspaces.js
app.get("/admin/workspaces", [validatedRequest, strictMultiUserRoleValid], getWorkspaces);
app.post("/admin/workspaces/new", [validatedRequest, strictMultiUserRoleValid], createWorkspace);
// ...Instead of using the map function to remove the password from the user object, it would be better to select only the necessary fields from the database. This would improve the performance of the code. const users = await User.where().select('id', 'username', 'role'); |
| <LLMProviderOption | ||
| name="OpenAI" | ||
| value="openai" | ||
| link="openai.com" | ||
| description="Use OpenAI's text-embedding-ada-002 embedding model." | ||
| checked={embeddingChoice === "openai"} | ||
| image={OpenAiLogo} | ||
| onClick={updateChoice} | ||
| /> | ||
| <LLMProviderOption | ||
| name="Azure OpenAI" | ||
| value="azure" | ||
| link="azure.microsoft.com" | ||
| description="The enterprise option of OpenAI hosted on Azure services." | ||
| checked={embeddingChoice === "azure"} | ||
| image={AzureOpenAiLogo} | ||
| onClick={updateChoice} | ||
| /> | ||
| <LLMProviderOption | ||
| name="LocalAI" | ||
| value="localai" | ||
| link="localai.io" | ||
| description="Self hosted LocalAI embedding engine." | ||
| checked={embeddingChoice === "localai"} | ||
| image={LocalAiLogo} | ||
| onClick={updateChoice} | ||
| /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrapped the LLMProviderOption component with React.memo to prevent unnecessary re-renders and improve the performance of the application.
| <LLMProviderOption | |
| name="OpenAI" | |
| value="openai" | |
| link="openai.com" | |
| description="Use OpenAI's text-embedding-ada-002 embedding model." | |
| checked={embeddingChoice === "openai"} | |
| image={OpenAiLogo} | |
| onClick={updateChoice} | |
| /> | |
| <LLMProviderOption | |
| name="Azure OpenAI" | |
| value="azure" | |
| link="azure.microsoft.com" | |
| description="The enterprise option of OpenAI hosted on Azure services." | |
| checked={embeddingChoice === "azure"} | |
| image={AzureOpenAiLogo} | |
| onClick={updateChoice} | |
| /> | |
| <LLMProviderOption | |
| name="LocalAI" | |
| value="localai" | |
| link="localai.io" | |
| description="Self hosted LocalAI embedding engine." | |
| checked={embeddingChoice === "localai"} | |
| image={LocalAiLogo} | |
| onClick={updateChoice} | |
| /> | |
| const LLMProviderOption = React.memo(({ name, value, link, description, checked, image, onClick }) => { | |
| // component code | |
| }); |
| {embeddingChoice === "openai" && ( | ||
| <> | ||
| <div className="flex flex-col w-60"> | ||
| <label className="text-white text-sm font-semibold block mb-4"> | ||
| API Key | ||
| </label> | ||
| <input | ||
| type="text" | ||
| name="OpenAiKey" | ||
| className="bg-zinc-900 text-white placeholder-white placeholder-opacity-60 text-sm rounded-lg focus:border-white block w-full p-2.5" | ||
| placeholder="OpenAI API Key" | ||
| defaultValue={ | ||
| settings?.OpenAiKey ? "*".repeat(20) : "" | ||
| } | ||
| required={true} | ||
| autoComplete="off" | ||
| spellCheck={false} | ||
| /> | ||
| </div> | ||
| </> | ||
| )} | ||
|
|
||
| {embeddingChoice === "azure" && ( | ||
| <> | ||
| <div className="flex flex-col w-60"> | ||
| <label className="text-white text-sm font-semibold block mb-4"> | ||
| Azure Service Endpoint | ||
| </label> | ||
| <input | ||
| type="url" | ||
| name="AzureOpenAiEndpoint" | ||
| className="bg-zinc-900 text-white placeholder-white placeholder-opacity-60 text-sm rounded-lg focus:border-white block w-full p-2.5" | ||
| placeholder="https://my-azure.openai.azure.com" | ||
| defaultValue={settings?.AzureOpenAiEndpoint} | ||
| required={true} | ||
| autoComplete="off" | ||
| spellCheck={false} | ||
| /> | ||
| </div> | ||
| {embeddingChoice === "azure" && ( | ||
| <> | ||
| <div className="flex flex-col w-60"> | ||
| <label className="text-white text-sm font-semibold block mb-4"> | ||
| Azure Service Endpoint | ||
| </label> | ||
| <input | ||
| type="url" | ||
| name="AzureOpenAiEndpoint" | ||
| className="bg-zinc-900 text-white placeholder-white placeholder-opacity-60 text-sm rounded-lg focus:border-white block w-full p-2.5" | ||
| placeholder="https://my-azure.openai.azure.com" | ||
| defaultValue={settings?.AzureOpenAiEndpoint} | ||
| required={true} | ||
| autoComplete="off" | ||
| spellCheck={false} | ||
| /> | ||
| </div> | ||
|
|
||
| <div className="flex flex-col w-60"> | ||
| <label className="text-white text-sm font-semibold block mb-4"> | ||
| API Key | ||
| </label> | ||
| <input | ||
| type="password" | ||
| name="AzureOpenAiKey" | ||
| className="bg-zinc-900 text-white placeholder-white placeholder-opacity-60 text-sm rounded-lg focus:border-white block w-full p-2.5" | ||
| placeholder="Azure OpenAI API Key" | ||
| defaultValue={ | ||
| settings?.AzureOpenAiKey ? "*".repeat(20) : "" | ||
| } | ||
| required={true} | ||
| autoComplete="off" | ||
| spellCheck={false} | ||
| /> | ||
| </div> | ||
| <div className="flex flex-col w-60"> | ||
| <label className="text-white text-sm font-semibold block mb-4"> | ||
| API Key | ||
| </label> | ||
| <input | ||
| type="password" | ||
| name="AzureOpenAiKey" | ||
| className="bg-zinc-900 text-white placeholder-white placeholder-opacity-60 text-sm rounded-lg focus:border-white block w-full p-2.5" | ||
| placeholder="Azure OpenAI API Key" | ||
| defaultValue={ | ||
| settings?.AzureOpenAiKey ? "*".repeat(20) : "" | ||
| } | ||
| required={true} | ||
| autoComplete="off" | ||
| spellCheck={false} | ||
| /> | ||
| </div> | ||
|
|
||
| <div className="flex flex-col w-60"> | ||
| <label className="text-white text-sm font-semibold block mb-4"> | ||
| Embedding Deployment Name | ||
| </label> | ||
| <input | ||
| type="text" | ||
| name="AzureOpenAiEmbeddingModelPref" | ||
| className="bg-zinc-900 text-white placeholder-white placeholder-opacity-60 text-sm rounded-lg focus:border-white block w-full p-2.5" | ||
| placeholder="Azure OpenAI embedding model deployment name" | ||
| defaultValue={ | ||
| settings?.AzureOpenAiEmbeddingModelPref | ||
| } | ||
| required={true} | ||
| autoComplete="off" | ||
| spellCheck={false} | ||
| /> | ||
| </div> | ||
| </> | ||
| )} | ||
| <div className="flex flex-col w-60"> | ||
| <label className="text-white text-sm font-semibold block mb-4"> | ||
| Embedding Deployment Name | ||
| </label> | ||
| <input | ||
| type="text" | ||
| name="AzureOpenAiEmbeddingModelPref" | ||
| className="bg-zinc-900 text-white placeholder-white placeholder-opacity-60 text-sm rounded-lg focus:border-white block w-full p-2.5" | ||
| placeholder="Azure OpenAI embedding model deployment name" | ||
| defaultValue={settings?.AzureOpenAiEmbeddingModelPref} | ||
| required={true} | ||
| autoComplete="off" | ||
| spellCheck={false} | ||
| /> | ||
| </div> | ||
| </> | ||
| )} | ||
|
|
||
| {embeddingChoice === "localai" && ( | ||
| <> | ||
| <div className="flex flex-col w-60"> | ||
| <label className="text-white text-sm font-semibold block mb-4"> | ||
| LocalAI Base URL | ||
| </label> | ||
| <input | ||
| type="url" | ||
| name="EmbeddingBasePath" | ||
| className="bg-zinc-900 text-white placeholder-white placeholder-opacity-60 text-sm rounded-lg focus:border-white block w-full p-2.5" | ||
| placeholder="http://localhost:8080/v1" | ||
| defaultValue={settings?.EmbeddingBasePath} | ||
| onChange={(e) => setBasePathValue(e.target.value)} | ||
| onBlur={updateBasePath} | ||
| required={true} | ||
| autoComplete="off" | ||
| spellCheck={false} | ||
| /> | ||
| </div> | ||
| <LocalAIModelSelection | ||
| settings={settings} | ||
| basePath={basePath} | ||
| {embeddingChoice === "localai" && ( | ||
| <> | ||
| <div className="flex flex-col w-60"> | ||
| <label className="text-white text-sm font-semibold block mb-4"> | ||
| LocalAI Base URL | ||
| </label> | ||
| <input | ||
| type="url" | ||
| name="EmbeddingBasePath" | ||
| className="bg-zinc-900 text-white placeholder-white placeholder-opacity-60 text-sm rounded-lg focus:border-white block w-full p-2.5" | ||
| placeholder="http://localhost:8080/v1" | ||
| defaultValue={settings?.EmbeddingBasePath} | ||
| onChange={(e) => setBasePathValue(e.target.value)} | ||
| onBlur={updateBasePath} | ||
| required={true} | ||
| autoComplete="off" | ||
| spellCheck={false} | ||
| /> | ||
| </> | ||
| )} | ||
| </div> | ||
| </> | ||
| )} | ||
| </div> | ||
| <LocalAIModelSelection | ||
| settings={settings} | ||
| basePath={basePath} | ||
| /> | ||
| </> | ||
| )} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace the multiple if statements with a switch statement to improve code readability and maintainability.
| {embeddingChoice === "openai" && ( | |
| <> | |
| <div className="flex flex-col w-60"> | |
| <label className="text-white text-sm font-semibold block mb-4"> | |
| API Key | |
| </label> | |
| <input | |
| type="text" | |
| name="OpenAiKey" | |
| className="bg-zinc-900 text-white placeholder-white placeholder-opacity-60 text-sm rounded-lg focus:border-white block w-full p-2.5" | |
| placeholder="OpenAI API Key" | |
| defaultValue={ | |
| settings?.OpenAiKey ? "*".repeat(20) : "" | |
| } | |
| required={true} | |
| autoComplete="off" | |
| spellCheck={false} | |
| /> | |
| </div> | |
| </> | |
| )} | |
| {embeddingChoice === "azure" && ( | |
| <> | |
| <div className="flex flex-col w-60"> | |
| <label className="text-white text-sm font-semibold block mb-4"> | |
| Azure Service Endpoint | |
| </label> | |
| <input | |
| type="url" | |
| name="AzureOpenAiEndpoint" | |
| className="bg-zinc-900 text-white placeholder-white placeholder-opacity-60 text-sm rounded-lg focus:border-white block w-full p-2.5" | |
| placeholder="https://my-azure.openai.azure.com" | |
| defaultValue={settings?.AzureOpenAiEndpoint} | |
| required={true} | |
| autoComplete="off" | |
| spellCheck={false} | |
| /> | |
| </div> | |
| {embeddingChoice === "azure" && ( | |
| <> | |
| <div className="flex flex-col w-60"> | |
| <label className="text-white text-sm font-semibold block mb-4"> | |
| Azure Service Endpoint | |
| </label> | |
| <input | |
| type="url" | |
| name="AzureOpenAiEndpoint" | |
| className="bg-zinc-900 text-white placeholder-white placeholder-opacity-60 text-sm rounded-lg focus:border-white block w-full p-2.5" | |
| placeholder="https://my-azure.openai.azure.com" | |
| defaultValue={settings?.AzureOpenAiEndpoint} | |
| required={true} | |
| autoComplete="off" | |
| spellCheck={false} | |
| /> | |
| </div> | |
| <div className="flex flex-col w-60"> | |
| <label className="text-white text-sm font-semibold block mb-4"> | |
| API Key | |
| </label> | |
| <input | |
| type="password" | |
| name="AzureOpenAiKey" | |
| className="bg-zinc-900 text-white placeholder-white placeholder-opacity-60 text-sm rounded-lg focus:border-white block w-full p-2.5" | |
| placeholder="Azure OpenAI API Key" | |
| defaultValue={ | |
| settings?.AzureOpenAiKey ? "*".repeat(20) : "" | |
| } | |
| required={true} | |
| autoComplete="off" | |
| spellCheck={false} | |
| /> | |
| </div> | |
| <div className="flex flex-col w-60"> | |
| <label className="text-white text-sm font-semibold block mb-4"> | |
| API Key | |
| </label> | |
| <input | |
| type="password" | |
| name="AzureOpenAiKey" | |
| className="bg-zinc-900 text-white placeholder-white placeholder-opacity-60 text-sm rounded-lg focus:border-white block w-full p-2.5" | |
| placeholder="Azure OpenAI API Key" | |
| defaultValue={ | |
| settings?.AzureOpenAiKey ? "*".repeat(20) : "" | |
| } | |
| required={true} | |
| autoComplete="off" | |
| spellCheck={false} | |
| /> | |
| </div> | |
| <div className="flex flex-col w-60"> | |
| <label className="text-white text-sm font-semibold block mb-4"> | |
| Embedding Deployment Name | |
| </label> | |
| <input | |
| type="text" | |
| name="AzureOpenAiEmbeddingModelPref" | |
| className="bg-zinc-900 text-white placeholder-white placeholder-opacity-60 text-sm rounded-lg focus:border-white block w-full p-2.5" | |
| placeholder="Azure OpenAI embedding model deployment name" | |
| defaultValue={ | |
| settings?.AzureOpenAiEmbeddingModelPref | |
| } | |
| required={true} | |
| autoComplete="off" | |
| spellCheck={false} | |
| /> | |
| </div> | |
| </> | |
| )} | |
| <div className="flex flex-col w-60"> | |
| <label className="text-white text-sm font-semibold block mb-4"> | |
| Embedding Deployment Name | |
| </label> | |
| <input | |
| type="text" | |
| name="AzureOpenAiEmbeddingModelPref" | |
| className="bg-zinc-900 text-white placeholder-white placeholder-opacity-60 text-sm rounded-lg focus:border-white block w-full p-2.5" | |
| placeholder="Azure OpenAI embedding model deployment name" | |
| defaultValue={settings?.AzureOpenAiEmbeddingModelPref} | |
| required={true} | |
| autoComplete="off" | |
| spellCheck={false} | |
| /> | |
| </div> | |
| </> | |
| )} | |
| {embeddingChoice === "localai" && ( | |
| <> | |
| <div className="flex flex-col w-60"> | |
| <label className="text-white text-sm font-semibold block mb-4"> | |
| LocalAI Base URL | |
| </label> | |
| <input | |
| type="url" | |
| name="EmbeddingBasePath" | |
| className="bg-zinc-900 text-white placeholder-white placeholder-opacity-60 text-sm rounded-lg focus:border-white block w-full p-2.5" | |
| placeholder="http://localhost:8080/v1" | |
| defaultValue={settings?.EmbeddingBasePath} | |
| onChange={(e) => setBasePathValue(e.target.value)} | |
| onBlur={updateBasePath} | |
| required={true} | |
| autoComplete="off" | |
| spellCheck={false} | |
| /> | |
| </div> | |
| <LocalAIModelSelection | |
| settings={settings} | |
| basePath={basePath} | |
| {embeddingChoice === "localai" && ( | |
| <> | |
| <div className="flex flex-col w-60"> | |
| <label className="text-white text-sm font-semibold block mb-4"> | |
| LocalAI Base URL | |
| </label> | |
| <input | |
| type="url" | |
| name="EmbeddingBasePath" | |
| className="bg-zinc-900 text-white placeholder-white placeholder-opacity-60 text-sm rounded-lg focus:border-white block w-full p-2.5" | |
| placeholder="http://localhost:8080/v1" | |
| defaultValue={settings?.EmbeddingBasePath} | |
| onChange={(e) => setBasePathValue(e.target.value)} | |
| onBlur={updateBasePath} | |
| required={true} | |
| autoComplete="off" | |
| spellCheck={false} | |
| /> | |
| </> | |
| )} | |
| </div> | |
| </> | |
| )} | |
| </div> | |
| <LocalAIModelSelection | |
| settings={settings} | |
| basePath={basePath} | |
| /> | |
| </> | |
| )} | |
| switch (embeddingChoice) { | |
| case 'openai': | |
| return ( | |
| <div className='flex flex-col w-60'> | |
| <label className='text-white text-sm font-semibold block mb-4'> | |
| API Key | |
| </label> | |
| <input | |
| type='text' | |
| name='OpenAiKey' | |
| className='bg-zinc-900 text-white placeholder-white placeholder-opacity-60 text-sm rounded-lg focus:border-white block w-full p-2.5' | |
| placeholder='OpenAI API Key' | |
| defaultValue={settings?.OpenAiKey ? '*'.repeat(20) : ''} | |
| required={true} | |
| autoComplete='off' | |
| spellCheck={false} | |
| /> | |
| </div> | |
| ); | |
| case 'azure': | |
| return ( | |
| <> | |
| <div className='flex flex-col w-60'> | |
| <label className='text-white text-sm font-semibold block mb-4'> | |
| Azure Service Endpoint | |
| </label> | |
| <input | |
| type='url' | |
| name='AzureOpenAiEndpoint' | |
| className='bg-zinc-900 text-white placeholder-white placeholder-opacity-60 text-sm rounded-lg focus:border-white block w-full p-2.5' | |
| placeholder='https://my-azure.openai.azure.com' | |
| defaultValue={settings?.AzureOpenAiEndpoint} | |
| required={true} | |
| autoComplete='off' | |
| spellCheck={false} | |
| /> | |
| </div> | |
| <div className='flex flex-col w-60'> | |
| <label className='text-white text-sm font-semibold block mb-4'> | |
| API Key | |
| </label> | |
| <input | |
| type='password' | |
| name='AzureOpenAiKey' | |
| className='bg-zinc-900 text-white placeholder-white placeholder-opacity-60 text-sm rounded-lg focus:border-white block w-full p-2.5' | |
| placeholder='Azure OpenAI API Key' | |
| defaultValue={settings?.AzureOpenAiKey ? '*'.repeat(20) : ''} | |
| required={true} | |
| autoComplete='off' | |
| spellCheck={false} | |
| /> | |
| </div> | |
| <div className='flex flex-col w-60'> | |
| <label className='text-white text-sm font-semibold block mb-4'> | |
| Embedding Deployment Name | |
| </label> | |
| <input | |
| type='text' | |
| name='AzureOpenAiEmbeddingModelPref' | |
| className='bg-zinc-900 text-white placeholder-white placeholder-opacity-60 text-sm rounded-lg focus:border-white block w-full p-2.5' | |
| placeholder='Azure OpenAI embedding model deployment name' | |
| defaultValue={settings?.AzureOpenAiEmbeddingModelPref} | |
| required={true} | |
| autoComplete='off' | |
| spellCheck={false} | |
| /> | |
| </div> | |
| </> | |
| ); | |
| case 'localai': | |
| return ( | |
| <> | |
| <div className='flex flex-col w-60'> | |
| <label className='text-white text-sm font-semibold block mb-4'> | |
| LocalAI Base URL | |
| </label> | |
| <input | |
| type='url' | |
| name='EmbeddingBasePath' | |
| className='bg-zinc-900 text-white placeholder-white placeholder-opacity-60 text-sm rounded-lg focus:border-white block w-full p-2.5' | |
| placeholder='http://localhost:8080/v1' | |
| defaultValue={settings?.EmbeddingBasePath} | |
| onChange={(e) => setBasePathValue(e.target.value)} | |
| onBlur={updateBasePath} | |
| required={true} | |
| autoComplete='off' | |
| spellCheck={false} | |
| /> | |
| </div> | |
| <LocalAIModelSelection | |
| settings={settings} | |
| basePath={basePath} | |
| /> | |
| </> | |
| ); | |
| default: | |
| return null; | |
| } |
…79-allow-any-llm-to-use-any-embedder
…tplex-Labs#386) * allow use of any embedder for any llm/update data handling modal * Apply embedder override and fallback to OpenAI and Azure models --------- Co-authored-by: timothycarambat <rambat1010@gmail.com>
resolves #379
Allows user to change embedding engine for any llm and shows embedding engine in data handling modal to let users know where their documents can be seen.