Skip to content

Commit 998e55b

Browse files
Merge pull request #524 from yodamaster726/ollama-fix
fix: Ollama fix
2 parents 68a4dcd + 93608e0 commit 998e55b

File tree

1 file changed

+26
-3
lines changed
  • packages/plugin-node/src/services

1 file changed

+26
-3
lines changed

packages/plugin-node/src/services/llama.ts

+26-3
Original file line numberDiff line numberDiff line change
@@ -486,9 +486,32 @@ export class LlamaService extends Service {
486486
throw new Error("Model not initialized. Call initialize() first.");
487487
}
488488

489-
const embeddingContext = await this.model.createEmbeddingContext();
490-
const embedding = await embeddingContext.getEmbeddingFor(input);
491-
return embedding?.vector ? [...embedding.vector] : undefined;
489+
const ollamaModel = process.env.OLLAMA_MODEL;
490+
const ollamaUrl =
491+
process.env.OLLAMA_SERVER_URL || "http://localhost:11434";
492+
const embeddingModel =
493+
process.env.OLLAMA_EMBEDDING_MODEL || "mxbai-embed-large";
494+
elizaLogger.info(
495+
`Using Ollama API for embeddings with model ${embeddingModel} (base: ${ollamaModel})`
496+
);
497+
498+
const response = await fetch(`${ollamaUrl}/api/embeddings`, {
499+
method: "POST",
500+
headers: {
501+
"Content-Type": "application/json",
502+
},
503+
body: JSON.stringify({
504+
input: input,
505+
model: embeddingModel,
506+
}),
507+
});
508+
509+
if (!response.ok) {
510+
throw new Error(`Failed to get embedding: ${response.statusText}`);
511+
}
512+
513+
const embedding = await response.json();
514+
return embedding.vector;
492515
}
493516
}
494517

0 commit comments

Comments
 (0)