| import { | |
| getLlama, | |
| LlamaChatSession, | |
| } from "node-llama-cpp"; | |
| import {fileURLToPath} from "url"; | |
| import path from "path"; | |
| const __dirname = path.dirname(fileURLToPath(import.meta.url)); | |
| const llama = await getLlama(); | |
| const model = await llama.loadModel({ | |
| modelPath: path.join( | |
| __dirname, | |
| '..', | |
| '..', | |
| 'models', | |
| 'Qwen3-1.7B-Q8_0.gguf' | |
| ) | |
| }); | |
| const systemPrompt = `You are an expert logical and quantitative reasoner. | |
| Your goal is to analyze real-world word problems involving families, quantities, averages, and relationships | |
| between entities, and compute the exact numeric answer. | |
| Goal: Return the correct final number as a single value — no explanation, no reasoning steps, just the answer. | |
| ` | |
| const context = await model.createContext(); | |
| const session = new LlamaChatSession({ | |
| contextSequence: context.getSequence(), | |
| systemPrompt | |
| }); | |
| const prompt = `My family reunion is this week, and I was assigned the mashed potatoes to bring. | |
| The attendees include my married mother and father, my twin brother and his family, my aunt and her family, my grandma | |
| and her brother, her brother's daughter, and his daughter's family. All the adults but me have been married, and no one | |
| is divorced or remarried, but my grandpa and my grandma's sister-in-law passed away last year. All living spouses are attending. | |
| My brother has two children that are still kids, my aunt has one six-year-old, and my grandma's brother's daughter has | |
| three kids under 12. I figure each adult will eat about 1.5 potatoes and each kid will eat about 1/2 a potato, except my | |
| second cousins don't eat carbs. The average potato is about half a pound, and potatoes are sold in 5-pound bags. | |
| How many whole bags of potatoes do I need? | |
| `; | |
| const answer = await session.prompt(prompt); | |
| console.log(`AI: ${answer}`); | |
| llama.dispose() | |
| model.dispose() | |
| context.dispose() | |
| session.dispose() |