-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mistral embedding engine support (#2667)
* add mistral embedding engine support * remove console log + fix data handling onboarding * update data handling description --------- Co-authored-by: Timothy Carambat <[email protected]>
- Loading branch information
1 parent
246152c
commit 9f38b93
Showing
6 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
frontend/src/components/EmbeddingSelection/MistralAiOptions/index.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
export default function MistralAiOptions({ settings }) { | ||
return ( | ||
<div className="w-full flex flex-col gap-y-4"> | ||
<div className="w-full flex items-center gap-[36px] mt-1.5"> | ||
<div className="flex flex-col w-60"> | ||
<label className="text-white text-sm font-semibold block mb-3"> | ||
API Key | ||
</label> | ||
<input | ||
type="password" | ||
name="MistralAiApiKey" | ||
className="bg-theme-settings-input-bg text-white placeholder:text-theme-settings-input-placeholder text-sm rounded-lg focus:outline-primary-button active:outline-primary-button outline-none block w-full p-2.5" | ||
placeholder="Mistral AI API Key" | ||
defaultValue={settings?.MistralApiKey ? "*".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-3"> | ||
Model Preference | ||
</label> | ||
<select | ||
name="EmbeddingModelPref" | ||
required={true} | ||
defaultValue={settings?.EmbeddingModelPref} | ||
className="bg-theme-settings-input-bg border-gray-500 text-white text-sm rounded-lg block w-full p-2.5" | ||
> | ||
<optgroup label="Available embedding models"> | ||
{[ | ||
"mistral-embed", | ||
].map((model) => { | ||
return ( | ||
<option key={model} value={model}> | ||
{model} | ||
</option> | ||
); | ||
})} | ||
</optgroup> | ||
</select> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
class MistralEmbedder { | ||
constructor() { | ||
if (!process.env.MISTRAL_API_KEY) | ||
throw new Error("No Mistral API key was set."); | ||
|
||
const { OpenAI: OpenAIApi } = require("openai"); | ||
this.openai = new OpenAIApi({ | ||
baseURL: "https://api.mistral.ai/v1", | ||
apiKey: process.env.MISTRAL_API_KEY ?? null, | ||
}); | ||
this.model = process.env.EMBEDDING_MODEL_PREF || "mistral-embed"; | ||
} | ||
|
||
async embedTextInput(textInput) { | ||
try { | ||
const response = await this.openai.embeddings.create({ | ||
model: this.model, | ||
input: textInput, | ||
}); | ||
return response?.data[0]?.embedding || []; | ||
} catch (error) { | ||
console.error("Failed to get embedding from Mistral.", error.message); | ||
return []; | ||
} | ||
} | ||
|
||
async embedChunks(textChunks = []) { | ||
try { | ||
const response = await this.openai.embeddings.create({ | ||
model: this.model, | ||
input: textChunks, | ||
}); | ||
return response?.data?.map((emb) => emb.embedding) || []; | ||
} catch (error) { | ||
console.error("Failed to get embeddings from Mistral.", error.message); | ||
return new Array(textChunks.length).fill([]); | ||
} | ||
} | ||
} | ||
|
||
module.exports = { | ||
MistralEmbedder, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters