7ea9f93dc8
Replace mutable Ollama model export with a const fallback and initializeModel return value, resolving the model from the environment after optional API discovery. Use a for-of loop over attempt indices instead of let in the retry path. Continue PDF generation when map image generation or upscaling fails, and avoid mutating request headers in place. Document Open WebUI-style URLs in the README, pin OLLAMA_MODEL in the Gitea release workflow, and adjust integration and unit tests for the new initialization behavior. Reviewed-on: #9 Co-authored-by: keligrubb <keligrubb324@gmail.com> Co-committed-by: keligrubb <keligrubb324@gmail.com>
43 lines
1.4 KiB
JavaScript
43 lines
1.4 KiB
JavaScript
import "dotenv/config";
|
|
import { generateDungeon } from "./src/dungeonGenerator.js";
|
|
import { generateDungeonImages } from "./src/imageGenerator.js";
|
|
import { generatePDF } from "./src/generatePDF.js";
|
|
import { initializeModel } from "./src/ollamaClient.js";
|
|
|
|
// Utility to create a filesystem-safe filename from the dungeon title
|
|
function slugify(text) {
|
|
return text
|
|
.toLowerCase()
|
|
.replace(/[^a-z0-9]+/g, "-") // replace non-alphanumeric with hyphens
|
|
.replace(/^-+|-+$/g, ""); // trim leading/trailing hyphens
|
|
}
|
|
|
|
(async () => {
|
|
try {
|
|
if (!process.env.OLLAMA_API_URL) {
|
|
throw new Error("OLLAMA_API_URL environment variable is required");
|
|
}
|
|
console.log("Using Ollama API URL:", process.env.OLLAMA_API_URL);
|
|
|
|
const model = await initializeModel();
|
|
console.log("Using Ollama model:", model);
|
|
|
|
// Generate the dungeon data
|
|
const dungeonData = await generateDungeon();
|
|
|
|
const mapPath = await generateDungeonImages(dungeonData);
|
|
if (mapPath) dungeonData.map = mapPath;
|
|
|
|
// Generate PDF filename based on the title
|
|
const filename = `${slugify(dungeonData.title)}.pdf`;
|
|
|
|
// Generate the PDF using full dungeon data (including map)
|
|
await generatePDF(dungeonData, filename);
|
|
|
|
console.log(`Dungeon PDF successfully generated: ${filename}`);
|
|
} catch (err) {
|
|
console.error("Error generating dungeon:", err);
|
|
process.exit(1);
|
|
}
|
|
})();
|