@elizaos/plugin-local-ai 1.0.4 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +73 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2395,6 +2395,10 @@ var LocalAIManager = class _LocalAIManager {
|
|
|
2395
2395
|
*/
|
|
2396
2396
|
async generateText(params) {
|
|
2397
2397
|
try {
|
|
2398
|
+
if (this.ctx) {
|
|
2399
|
+
this.ctx.dispose();
|
|
2400
|
+
this.ctx = void 0;
|
|
2401
|
+
}
|
|
2398
2402
|
await this.initializeEnvironment();
|
|
2399
2403
|
logger8.info("Generating text with model:", params.modelType);
|
|
2400
2404
|
if (params.modelType === ModelType.TEXT_LARGE) {
|
|
@@ -2674,17 +2678,81 @@ var localAIManager = LocalAIManager.getInstance();
|
|
|
2674
2678
|
var localAiPlugin = {
|
|
2675
2679
|
name: "local-ai",
|
|
2676
2680
|
description: "Local AI plugin using LLaMA models",
|
|
2677
|
-
async init() {
|
|
2681
|
+
async init(_config, runtime) {
|
|
2682
|
+
logger8.info("\u{1F680} Initializing Local AI plugin...");
|
|
2678
2683
|
try {
|
|
2679
|
-
logger8.debug("Initializing local-ai plugin environment...");
|
|
2680
2684
|
await localAIManager.initializeEnvironment();
|
|
2681
|
-
|
|
2685
|
+
const config = validateConfig();
|
|
2686
|
+
if (!config.LOCAL_SMALL_MODEL || !config.LOCAL_LARGE_MODEL || !config.LOCAL_EMBEDDING_MODEL) {
|
|
2687
|
+
logger8.warn("\u26A0\uFE0F Local AI plugin: Model configuration is incomplete");
|
|
2688
|
+
logger8.warn("Please ensure the following environment variables are set:");
|
|
2689
|
+
logger8.warn("- LOCAL_SMALL_MODEL: Path to small language model file");
|
|
2690
|
+
logger8.warn("- LOCAL_LARGE_MODEL: Path to large language model file");
|
|
2691
|
+
logger8.warn("- LOCAL_EMBEDDING_MODEL: Path to embedding model file");
|
|
2692
|
+
logger8.warn("Example: LOCAL_SMALL_MODEL=llama-3.2-1b-instruct-q8_0.gguf");
|
|
2693
|
+
}
|
|
2694
|
+
const modelsDir = config.MODELS_DIR || path5.join(os3.homedir(), ".eliza", "models");
|
|
2695
|
+
if (!fs5.existsSync(modelsDir)) {
|
|
2696
|
+
logger8.warn(`\u26A0\uFE0F Models directory does not exist: ${modelsDir}`);
|
|
2697
|
+
logger8.warn("The directory will be created, but you need to download model files");
|
|
2698
|
+
logger8.warn("Visit https://huggingface.co/models to download compatible GGUF models");
|
|
2699
|
+
}
|
|
2700
|
+
logger8.info("\u{1F50D} Testing Local AI initialization...");
|
|
2701
|
+
try {
|
|
2702
|
+
await localAIManager.checkPlatformCapabilities();
|
|
2703
|
+
const llamaInstance = await getLlama();
|
|
2704
|
+
if (llamaInstance) {
|
|
2705
|
+
logger8.success("\u2705 Local AI: llama.cpp library loaded successfully");
|
|
2706
|
+
} else {
|
|
2707
|
+
throw new Error("Failed to load llama.cpp library");
|
|
2708
|
+
}
|
|
2709
|
+
const smallModelPath = path5.join(modelsDir, config.LOCAL_SMALL_MODEL);
|
|
2710
|
+
const largeModelPath = path5.join(modelsDir, config.LOCAL_LARGE_MODEL);
|
|
2711
|
+
const embeddingModelPath = path5.join(modelsDir, config.LOCAL_EMBEDDING_MODEL);
|
|
2712
|
+
const modelsExist = {
|
|
2713
|
+
small: fs5.existsSync(smallModelPath),
|
|
2714
|
+
large: fs5.existsSync(largeModelPath),
|
|
2715
|
+
embedding: fs5.existsSync(embeddingModelPath)
|
|
2716
|
+
};
|
|
2717
|
+
if (!modelsExist.small && !modelsExist.large && !modelsExist.embedding) {
|
|
2718
|
+
logger8.warn("\u26A0\uFE0F No model files found in models directory");
|
|
2719
|
+
logger8.warn("Models will be downloaded on first use, which may take time");
|
|
2720
|
+
logger8.warn("To pre-download models, run the plugin and it will fetch them automatically");
|
|
2721
|
+
} else {
|
|
2722
|
+
logger8.info("\u{1F4E6} Found model files:", {
|
|
2723
|
+
small: modelsExist.small ? "\u2713" : "\u2717",
|
|
2724
|
+
large: modelsExist.large ? "\u2713" : "\u2717",
|
|
2725
|
+
embedding: modelsExist.embedding ? "\u2713" : "\u2717"
|
|
2726
|
+
});
|
|
2727
|
+
}
|
|
2728
|
+
logger8.success("\u2705 Local AI plugin initialized successfully");
|
|
2729
|
+
logger8.info("\u{1F4A1} Models will be loaded on-demand when first used");
|
|
2730
|
+
} catch (testError) {
|
|
2731
|
+
logger8.error("\u274C Local AI initialization test failed:", testError);
|
|
2732
|
+
logger8.warn("The plugin may not function correctly");
|
|
2733
|
+
logger8.warn("Please check:");
|
|
2734
|
+
logger8.warn("1. Your system has sufficient memory (8GB+ recommended)");
|
|
2735
|
+
logger8.warn("2. C++ build tools are installed (for node-llama-cpp)");
|
|
2736
|
+
logger8.warn("3. Your CPU supports the required instruction sets");
|
|
2737
|
+
}
|
|
2682
2738
|
} catch (error) {
|
|
2683
|
-
logger8.error("
|
|
2739
|
+
logger8.error("\u274C Failed to initialize Local AI plugin:", {
|
|
2684
2740
|
error: error instanceof Error ? error.message : String(error),
|
|
2685
2741
|
stack: error instanceof Error ? error.stack : void 0
|
|
2686
2742
|
});
|
|
2687
|
-
|
|
2743
|
+
if (error instanceof Error) {
|
|
2744
|
+
if (error.message.includes("Cannot find module")) {
|
|
2745
|
+
logger8.error("\u{1F4DA} Missing dependencies detected");
|
|
2746
|
+
logger8.error("Please run: npm install or bun install");
|
|
2747
|
+
} else if (error.message.includes("node-llama-cpp")) {
|
|
2748
|
+
logger8.error("\u{1F527} node-llama-cpp build issue detected");
|
|
2749
|
+
logger8.error("Please ensure C++ build tools are installed:");
|
|
2750
|
+
logger8.error("- Windows: Install Visual Studio Build Tools");
|
|
2751
|
+
logger8.error("- macOS: Install Xcode Command Line Tools");
|
|
2752
|
+
logger8.error("- Linux: Install build-essential package");
|
|
2753
|
+
}
|
|
2754
|
+
}
|
|
2755
|
+
logger8.warn("\u26A0\uFE0F Local AI plugin will not be available");
|
|
2688
2756
|
}
|
|
2689
2757
|
},
|
|
2690
2758
|
models: {
|