mirror of
https://github.com/Mintplex-Labs/anything-llm.git
synced 2025-04-23 13:08:11 +00:00
Check ollama alive for embedder (#1057)
This commit is contained in:
parent
6f52a2b729
commit
1c11a47f93
1 changed files with 16 additions and 0 deletions
|
@ -18,12 +18,28 @@ class OllamaEmbedder {
|
||||||
console.log(`\x1b[36m[${this.constructor.name}]\x1b[0m ${text}`, ...args);
|
console.log(`\x1b[36m[${this.constructor.name}]\x1b[0m ${text}`, ...args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async #isAlive() {
|
||||||
|
return await fetch(process.env.EMBEDDING_BASE_PATH, {
|
||||||
|
method: "HEAD",
|
||||||
|
})
|
||||||
|
.then((res) => res.ok)
|
||||||
|
.catch((e) => {
|
||||||
|
this.log(e.message);
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async embedTextInput(textInput) {
|
async embedTextInput(textInput) {
|
||||||
const result = await this.embedChunks([textInput]);
|
const result = await this.embedChunks([textInput]);
|
||||||
return result?.[0] || [];
|
return result?.[0] || [];
|
||||||
}
|
}
|
||||||
|
|
||||||
async embedChunks(textChunks = []) {
|
async embedChunks(textChunks = []) {
|
||||||
|
if (!(await this.#isAlive()))
|
||||||
|
throw new Error(
|
||||||
|
`Ollama service could not be reached. Is Ollama running?`
|
||||||
|
);
|
||||||
|
|
||||||
const embeddingRequests = [];
|
const embeddingRequests = [];
|
||||||
this.log(
|
this.log(
|
||||||
`Embedding ${textChunks.length} chunks of text with ${this.model}.`
|
`Embedding ${textChunks.length} chunks of text with ${this.model}.`
|
||||||
|
|
Loading…
Add table
Reference in a new issue