peg-memory
v2.0.0
Published
A peg memory toolkit for generating vivid memory images from default or custom peg lists.
Maintainers
Readme
peg-memory
peg-memory is a Node.js library for peg-based memorization. It ships with a default 1-100 peg list, lets people import custom lists, generates vivid memory scenes, and can create real local AI pictures when connected to a local image model server.
Install
npm install peg-memoryUse
import { list, importCustom, imager, saveImage } from "peg-memory";
const pegs = list();
console.log(pegs[28]); // Knife
const result = await imager(28, "American Revolution");
console.log(result.story);
console.log(result.explanation);
if (result.image) {
await saveImage(result, "./revolution.png");
}
importCustom({
1: "Sun",
2: "Shoe",
3: "Tree"
});API
list()
Returns the active peg list.
defaultList()
Returns the built-in default peg list.
importCustom(customList, options?)
Imports a custom peg list.
customList: object keyed from1to100options.merge: defaults totrue
When merge is true, missing pegs fall back to the default list.
resetList()
Restores the built-in default list.
getPeg(number)
Gets one peg by number.
imager(number, thing, options?)
Creates a mnemonic result for a peg and a thing to remember.
Returns:
{
number: 28,
peg: "Knife",
thing: "American Revolution",
story: "...",
imagePrompt: "...",
explanation: "...",
provider: "fallback",
svg: "<svg ...",
dataUri: "data:image/svg+xml..."
}The svg and dataUri fields give you a real generated image card even in fallback mode.
Text provider options:
fallback: always works locally with no AI setupauto: tries Ollama, then OpenAI, then fallbackollama: uses a local Ollama serveropenai: uses the OpenAI API
By default, imager() also tries to use a local image server at http://127.0.0.1:7860. If none is running, it falls back without failing.
Image options:
image.enabled: turns on real image generationimage.provider:automatic1111,forge, ornoneimage.endpoint: defaults tohttp://127.0.0.1:7860image.model: optional checkpoint/model nameimage.width,image.height,image.steps,image.cfgScale,image.samplerNameimage.promptPrefix: optional style prefix added to the generated promptimage.negativePrompt: optional negative prompt
Example with Ollama:
const result = await imager(42, "photosynthesis", {
provider: "ollama",
model: "llama3.1:8b"
});Example with OpenAI:
const result = await imager(42, "photosynthesis", {
provider: "openai",
apiKey: process.env.OPENAI_API_KEY
});Example with a local Stable Diffusion WebUI or Forge server:
const result = await imager(42, "photosynthesis", {
image: {
provider: "automatic1111",
endpoint: "http://127.0.0.1:7860",
width: 1024,
height: 1024,
promptPrefix: "surreal educational illustration, highly detailed"
}
});
console.log(result.image.dataUri);
await saveImage(result, "./photosynthesis.png");imagers.batch(entries, options?)
Creates multiple mnemonic images at once.
const results = await imagers.batch([
{ number: 5, thing: "gravity" },
{ number: 12, thing: "mitosis" }
]);Notes
- The built-in fallback mode is dependency-free and works out of the box.
- Local text AI and local image AI are optional.
- For real local pictures, run a compatible local server such as Stable Diffusion WebUI or Forge with API access enabled.
- The package targets Node.js
18+.
