-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-llama-cpp.js
More file actions
58 lines (44 loc) · 1.57 KB
/
Copy pathtest-llama-cpp.js
File metadata and controls
58 lines (44 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env node
/**
* Test node-llama-cpp with actual model inference
* NO PYTHON REQUIRED - Pure Node.js
*/
import { getLlama, LlamaChatSession } from "node-llama-cpp";
async function testLlamaCpp() {
console.log("🚀 Testing node-llama-cpp...");
try {
const llama = await getLlama();
console.log("✅ Llama loaded");
// Try to load a GGUF model if available
const modelPath = "./models/Meta-Llama-3-8B.Q2_K.gguf";
console.log(`📦 Loading model: ${modelPath}`);
const model = await llama.loadModel({
modelPath: modelPath
});
console.log("✅ Model loaded successfully!");
// Create context
const context = await model.createContext();
console.log("✅ Context created");
// Create chat session
const session = new LlamaChatSession({
contextSequence: context.getSequence()
});
console.log("✅ Chat session created");
// Test inference
const prompt = "What is 2+2?";
console.log(`\n💬 Prompt: ${prompt}`);
const response = await session.prompt(prompt);
console.log(`🤖 Response: ${response}`);
console.log("\n✅ SUCCESS! Node-llama-cpp is working with actual AI inference!");
} catch (error) {
console.error("❌ Error:", error.message);
console.log("\nTrying to download a model first...");
// If no model, provide instructions
console.log(`
To get a working GGUF model, run:
wget https://huggingface.co/TheBloke/Llama-2-7B-GGUF/resolve/main/llama-2-7b.Q4_K_M.gguf -P models/
`);
}
process.exit(0);
}
testLlamaCpp();