Generate sentences by finding the shortest path through a word-graph using Dijkstra's Algorithm.
Topic β LLM β Word Graph β Dijkstra β Sentence
node examples/simple.jsconst { TextGenerator } = require("./index.js");
const gen = new TextGenerator({
baseURL: "http://localhost:8888/v1",
startWord: "The"
});
const result = await gen.generate("animals", 5);
console.log(result.sentence); // "The quick brown fox jumps"| Example | Description |
|---|---|
simple.js |
Basic usage with verbose output |
game_mechanic.js |
Spell casting system using path distance as mana cost |
seo_strategy.js |
Internal linking structure for SEO topic clusters |
visualizer.js |
Export word graph to GraphViz DOT format |
node examples/game_mechanic.js # βοΈ Mana-based spell casting
node examples/seo_strategy.js # π SEO link clusters
node examples/visualizer.js # ποΈ GraphViz output- Fetch word transitions from LLM API
- Build directed graph (words = nodes, transitions = edges)
- Find shortest path of target length via Dijkstra
- Return path as sentence
MIT