Compare commits
20
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a0d4e1405a | ||
|
|
c55be962df | ||
|
|
cdf94c9fd0 | ||
|
|
b5f47ea033 | ||
|
|
6b080b7413 | ||
|
|
69d1be9415 | ||
|
|
e621505cf2 | ||
|
|
9cc8cb5f9b | ||
|
|
869f0b0c55 | ||
|
|
f8f4da4613 | ||
|
|
ecbc7e79e9 | ||
|
|
866cb8b43f | ||
|
|
5495d7640f | ||
|
|
cd5a5bff79 | ||
|
|
e6036fd831 | ||
|
|
b42210cb0c | ||
|
|
2cb57aed41 | ||
|
|
1e7c5855e5 | ||
|
|
7ea9f93dc8 | ||
|
|
4428cd4cb8 |
@@ -9,10 +9,10 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: https://github.com/actions/checkout@v6
|
uses: https://git.keligrubb.com/actions/checkout@v7
|
||||||
|
|
||||||
- name: Setup Node
|
- name: Setup Node
|
||||||
uses: https://github.com/actions/setup-node@v6
|
uses: https://git.keligrubb.com/actions/setup-node@v7
|
||||||
with:
|
with:
|
||||||
node-version: "24"
|
node-version: "24"
|
||||||
cache: "npm"
|
cache: "npm"
|
||||||
@@ -28,10 +28,10 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: https://github.com/actions/checkout@v6
|
uses: https://git.keligrubb.com/actions/checkout@v7
|
||||||
|
|
||||||
- name: Setup Node
|
- name: Setup Node
|
||||||
uses: https://github.com/actions/setup-node@v6
|
uses: https://git.keligrubb.com/actions/setup-node@v7
|
||||||
with:
|
with:
|
||||||
node-version: "24"
|
node-version: "24"
|
||||||
cache: "npm"
|
cache: "npm"
|
||||||
|
|||||||
@@ -15,13 +15,14 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
OLLAMA_API_URL: https://ai.keligrubb.com/api/chat/completions
|
OLLAMA_API_URL: https://ai.keligrubb.com/api/chat/completions
|
||||||
OLLAMA_API_KEY: ${{ secrets.OLLAMA_API_KEY }}
|
OLLAMA_API_KEY: ${{ secrets.OLLAMA_API_KEY }}
|
||||||
|
OLLAMA_MODEL: qwen3.5-122b-a10b
|
||||||
COMFYUI_URL: http://192.168.1.124:8188
|
COMFYUI_URL: http://192.168.1.124:8188
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: https://github.com/actions/checkout@v6
|
uses: https://git.keligrubb.com/actions/checkout@v7
|
||||||
|
|
||||||
- name: Setup Node
|
- name: Setup Node
|
||||||
uses: https://github.com/actions/setup-node@v6
|
uses: https://git.keligrubb.com/actions/setup-node@v7
|
||||||
with:
|
with:
|
||||||
node-version: "24"
|
node-version: "24"
|
||||||
cache: "npm"
|
cache: "npm"
|
||||||
@@ -33,7 +34,7 @@ jobs:
|
|||||||
run: npm start
|
run: npm start
|
||||||
|
|
||||||
- name: Upload PDF artifact
|
- name: Upload PDF artifact
|
||||||
uses: https://github.com/actions/upload-artifact@v7
|
uses: https://git.keligrubb.com/actions/upload-artifact@v7
|
||||||
with:
|
with:
|
||||||
name: release-pdf
|
name: release-pdf
|
||||||
path: "*.pdf"
|
path: "*.pdf"
|
||||||
@@ -46,9 +47,10 @@ jobs:
|
|||||||
GITEA_TOKEN: ${{ secrets.SCROLLSMITH_GITEA_TOKEN }}
|
GITEA_TOKEN: ${{ secrets.SCROLLSMITH_GITEA_TOKEN }}
|
||||||
steps:
|
steps:
|
||||||
- name: Download PDF artifact
|
- name: Download PDF artifact
|
||||||
uses: https://github.com/actions/download-artifact@v8
|
uses: https://git.keligrubb.com/actions/download-artifact@v8
|
||||||
with:
|
with:
|
||||||
name: release-pdf
|
name: release-pdf
|
||||||
|
path: .
|
||||||
|
|
||||||
- name: Create release and upload PDF
|
- name: Create release and upload PDF
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
[](https://ci.keligrubb.com/repos/2)
|
[](https://ci.keligrubb.com/repos/2)
|
||||||
|
|
||||||
Scrollsmith is a Node.js tool for generating Dungeons & Dragons one-page dungeon PDFs automatically. It uses an Ollama LLM server to create dungeon content, proofreads and refines it, then formats it into a structured PDF with maps, rooms, encounters, treasure, and NPCs.
|
Scrollsmith is a Node.js tool for generating Dungeons & Dragons one-page dungeon PDFs automatically. It calls an LLM (Open WebUI `/api/chat/completions` or Ollama `/api/generate`, inferred from `OLLAMA_API_URL`), proofreads and refines the result, then builds a structured PDF with maps, rooms, encounters, treasure, and NPCs.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -14,20 +14,21 @@ Scrollsmith is a Node.js tool for generating Dungeons & Dragons one-page dungeon
|
|||||||
3. JSON conversion: output strictly valid JSON for PDF generation
|
3. JSON conversion: output strictly valid JSON for PDF generation
|
||||||
- Automatically generates a PDF named after the dungeon title
|
- Automatically generates a PDF named after the dungeon title
|
||||||
- PDF layout includes three columns: map & hooks, rooms, encounters & treasure & NPCs
|
- PDF layout includes three columns: map & hooks, rooms, encounters & treasure & NPCs
|
||||||
- Easy to integrate with a local Ollama server
|
- Open WebUI or Ollama
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
- Node.js 22+
|
- Node.js 22+
|
||||||
- Ollama server running and accessible
|
- LLM endpoint (see below)
|
||||||
- Gitea Releases (optional) for PDF uploads
|
- Gitea Releases (optional) for PDF uploads
|
||||||
- `.env` file with:
|
- `.env` file with:
|
||||||
|
|
||||||
```env
|
```env
|
||||||
OLLAMA_API_URL=http://localhost:3000/api/chat/completions
|
OLLAMA_API_URL=https://your-openwebui-host/api/chat/completions
|
||||||
OLLAMA_API_KEY=your_api_key_here
|
OLLAMA_API_KEY=your_api_key_here
|
||||||
|
OLLAMA_MODEL=qwen3.5-122b-a10b
|
||||||
COMFYUI_URL=http://192.168.1.124:8188
|
COMFYUI_URL=http://192.168.1.124:8188
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -56,17 +57,18 @@ OLLAMA_API_URL=http://localhost:11434/api/generate
|
|||||||
### Open WebUI API
|
### Open WebUI API
|
||||||
For Open WebUI API calls, set:
|
For Open WebUI API calls, set:
|
||||||
```env
|
```env
|
||||||
OLLAMA_API_URL=http://localhost:3000/api/chat/completions
|
OLLAMA_API_URL=https://your-openwebui-host/api/chat/completions
|
||||||
OLLAMA_API_KEY=your_open_webui_api_key
|
OLLAMA_API_KEY=your_open_webui_api_key
|
||||||
|
OLLAMA_MODEL=qwen3.5-122b-a10b
|
||||||
```
|
```
|
||||||
|
|
||||||
> Note: The API type is automatically inferred from the endpoint URL. If the URL contains `/api/chat/completions`, it uses Open WebUI API. If it contains `/api/generate`, it uses direct Ollama API. No `OLLAMA_API_TYPE` environment variable is required.
|
> Note: The API type is inferred from the URL (`/api/chat/completions` vs `/api/generate`); no `OLLAMA_API_TYPE` variable.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
1. Make sure your Ollama server is running and `.env` is configured.
|
1. Configure `.env` and ensure the LLM endpoint is reachable.
|
||||||
2. Run:
|
2. Run:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@@ -81,7 +83,7 @@ Optional: update the map path in `index.js` if you have a local dungeon map.
|
|||||||
|
|
||||||
## Project structure
|
## Project structure
|
||||||
|
|
||||||
- **`index.js`** – Entry point: loads env, initializes the Ollama model, runs dungeon generation, image generation, and PDF output.
|
- **`index.js`** – Entry point: env, model init, dungeon + image + PDF.
|
||||||
- **`src/`** – Application modules:
|
- **`src/`** – Application modules:
|
||||||
- `dungeonGenerator.js` – LLM-backed dungeon content generation and validation.
|
- `dungeonGenerator.js` – LLM-backed dungeon content generation and validation.
|
||||||
- `dungeonTemplate.js` – HTML template and layout for the PDF.
|
- `dungeonTemplate.js` – HTML template and layout for the PDF.
|
||||||
@@ -105,7 +107,7 @@ Optional: update the map path in `index.js` if you have a local dungeon map.
|
|||||||
|
|
||||||
## Notes
|
## Notes
|
||||||
|
|
||||||
* Make sure your Ollama server is accessible and API key is valid.
|
* Open WebUI needs a valid `OLLAMA_API_KEY` when the server requires it.
|
||||||
* Dungeon generation can take a few minutes depending on your LLM response time.
|
* Dungeon generation can take a few minutes depending on your LLM response time.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import "dotenv/config";
|
|||||||
import { generateDungeon } from "./src/dungeonGenerator.js";
|
import { generateDungeon } from "./src/dungeonGenerator.js";
|
||||||
import { generateDungeonImages } from "./src/imageGenerator.js";
|
import { generateDungeonImages } from "./src/imageGenerator.js";
|
||||||
import { generatePDF } from "./src/generatePDF.js";
|
import { generatePDF } from "./src/generatePDF.js";
|
||||||
import { OLLAMA_MODEL, initializeModel } from "./src/ollamaClient.js";
|
import { initializeModel } from "./src/ollamaClient.js";
|
||||||
|
|
||||||
// Utility to create a filesystem-safe filename from the dungeon title
|
// Utility to create a filesystem-safe filename from the dungeon title
|
||||||
function slugify(text) {
|
function slugify(text) {
|
||||||
@@ -19,17 +19,14 @@ function slugify(text) {
|
|||||||
}
|
}
|
||||||
console.log("Using Ollama API URL:", process.env.OLLAMA_API_URL);
|
console.log("Using Ollama API URL:", process.env.OLLAMA_API_URL);
|
||||||
|
|
||||||
// Initialize model (will fetch default from API or use fallback)
|
const model = await initializeModel();
|
||||||
await initializeModel();
|
console.log("Using Ollama model:", model);
|
||||||
console.log("Using Ollama model:", OLLAMA_MODEL);
|
|
||||||
|
|
||||||
// Generate the dungeon data
|
// Generate the dungeon data
|
||||||
const dungeonData = await generateDungeon();
|
const dungeonData = await generateDungeon();
|
||||||
|
|
||||||
// Generate dungeon map image (uses dungeonData.flavor)
|
|
||||||
const mapPath = await generateDungeonImages(dungeonData);
|
const mapPath = await generateDungeonImages(dungeonData);
|
||||||
|
if (mapPath) dungeonData.map = mapPath;
|
||||||
dungeonData.map = mapPath;
|
|
||||||
|
|
||||||
// Generate PDF filename based on the title
|
// Generate PDF filename based on the title
|
||||||
const filename = `${slugify(dungeonData.title)}.pdf`;
|
const filename = `${slugify(dungeonData.title)}.pdf`;
|
||||||
|
|||||||
Generated
+299
-286
File diff suppressed because it is too large
Load Diff
+103
-134
@@ -117,163 +117,132 @@ Output ONLY the two numbered items, one per line. Use colons (:) to separate roo
|
|||||||
console.log("Climax Room:", climaxRoom);
|
console.log("Climax Room:", climaxRoom);
|
||||||
|
|
||||||
// Step 5: Main Content (Locations, Encounters, NPCs, Treasures, Random Events)
|
// Step 5: Main Content (Locations, Encounters, NPCs, Treasures, Random Events)
|
||||||
// To avoid overloading the AI server with a single huge prompt, we generate
|
const mainContentRaw = await callOllama(
|
||||||
// each section in smaller, focused calls and then stitch them together.
|
`Based on the following dungeon elements and the need for narrative flow:
|
||||||
|
Title: "${title}"
|
||||||
const sharedContext = `Title: "${title}"
|
|
||||||
Description: "${flavor}"
|
Description: "${flavor}"
|
||||||
Core Concepts:
|
Core Concepts:
|
||||||
${coreConcepts}
|
${coreConcepts}
|
||||||
Entrance Room: ${JSON.stringify(entranceRoom)}
|
Entrance Room: ${JSON.stringify(entranceRoom)}
|
||||||
Climax Room: ${JSON.stringify(climaxRoom)}`;
|
Climax Room: ${JSON.stringify(climaxRoom)}
|
||||||
|
|
||||||
const locationsRaw = await callOllama(
|
Generate the rest of the dungeon's content to fill the space between the entrance and the climax. CRITICAL: All content must fit on a single one-page dungeon layout with three columns. Keep descriptions rich and evocative with tactical/environmental details.
|
||||||
`${sharedContext}
|
|
||||||
|
|
||||||
Generate EXACTLY 3 intermediate dungeon locations between the entrance and climax.
|
- **Strictly 3 Locations (EXACTLY 3, no more, no less):** Each with a name (max 6 words) and a description (25-35 words). Each room MUST include:
|
||||||
|
- Rich environmental features that affect gameplay (lighting, sounds, smells, textures, temperature, visibility)
|
||||||
|
- Interactable elements that players can use (levers, objects, portals, mechanisms, environmental hazards)
|
||||||
|
- Multiple approaches or solutions to challenges in the room
|
||||||
|
- Tactical considerations (cover, elevation, movement restrictions, line of sight)
|
||||||
|
- Hidden aspects discoverable through interaction or investigation
|
||||||
|
Format as "Name: description" using colons, NOT em-dashes.
|
||||||
|
|
||||||
Requirements:
|
EXAMPLE LOCATION:
|
||||||
- Each location gets a unique name (max 6 words) and a description (25-35 words).
|
"Whispering Gallery: Dim phosphorescent fungi line the walls, casting an eerie green glow. The air hums with a low-frequency vibration that makes conversation difficult. Two collapsed pillars create natural cover, while a narrow ledge 10 feet up offers a sniper position. A hidden pressure plate near the entrance triggers a portcullis trap."
|
||||||
- Include sensory details and environmental features that affect gameplay (lighting, sounds, smells, textures, temperature, visibility).
|
|
||||||
- Include interactable elements (levers, objects, portals, mechanisms, environmental hazards).
|
|
||||||
- Include tactical considerations (cover, elevation, movement restrictions, line of sight) and at least one hidden aspect per room.
|
|
||||||
|
|
||||||
Format:
|
- **Strictly 6 Encounters:** Numbered 1-6 (for d6 rolling). Name (max 6 words) and details (2 sentences MAX, approximately 25-40 words). Each encounter MUST:
|
||||||
1. Room Name: Description text.
|
- Start with the room/location name followed by a colon, then the details (e.g., "Location Name: Details text")
|
||||||
2. Room Name: Description text.
|
- The location name must match one of the actual room names from this dungeon
|
||||||
3. Room Name: Description text.
|
- Include environmental hazards/opportunities (cover, elevation, traps, interactable objects, terrain features)
|
||||||
|
- Include tactical considerations (positioning, line of sight, escape routes, bottlenecks, high ground)
|
||||||
|
- Offer multiple resolution options (combat, negotiation, stealth, puzzle-solving, environmental manipulation, timing-based solutions)
|
||||||
|
- Include consequences and outcomes tied to player choices
|
||||||
|
- Integrate with the environmental dynamic element from core concepts
|
||||||
|
- At least two encounters must be directly tied to the primary faction
|
||||||
|
Format as "Name: Location Name: details" using colons, NOT em-dashes. CRITICAL: Always start encounter details with the location name and a colon.
|
||||||
|
|
||||||
Plain text only. Do not use em-dashes (—). Absolutely do not use the word "Obsidian" or "obsidian" anywhere in the output.`,
|
EXAMPLE ENCOUNTER:
|
||||||
undefined,
|
"Guardian Golem: Chamber of Echoes: The golem activates when the lever is pulled, blocking the exit. It's vulnerable to water damage from the dripping stalactites. Players can use the pillars for cover or try to disable it by breaking the rune on its back. If defeated peacefully, it reveals a hidden passage."
|
||||||
5,
|
|
||||||
"Step 5a: Locations"
|
|
||||||
);
|
|
||||||
|
|
||||||
const encountersRaw = await callOllama(
|
- **Strictly 4-5 NPCs:** Proper name (max 4 words) and a description (50-65 words). Each NPC MUST include:
|
||||||
`${sharedContext}
|
- Clear motivation or goal
|
||||||
|
- Relationship to primary faction
|
||||||
|
- How they can help or hinder the party
|
||||||
|
- Quirks or memorable traits
|
||||||
|
- Multiple interaction possibilities (negotiation, intimidation, help, betrayal)
|
||||||
|
- One NPC should be a key figure tied to the central conflict
|
||||||
|
- One should be a member of the primary faction, one should be a potential ally, one should be a rival
|
||||||
|
Format as "Name: description" using colons, NOT em-dashes.
|
||||||
|
|
||||||
Existing rooms:
|
EXAMPLE NPC:
|
||||||
- Entrance: ${entranceRoom?.name}
|
"Kaelen the Warden: A former guard who was left behind when the faction retreated. He knows the secret passages but demands the party help him escape. He's paranoid and checks over his shoulder constantly. Can be bribed with food or convinced through shared stories of betrayal. Will turn on the party if he thinks they're working with the faction."
|
||||||
- Climax: ${climaxRoom?.name}
|
|
||||||
You will add 3 more locations (from the locations list) and must reference only real room names.
|
|
||||||
|
|
||||||
Generate EXACTLY 6 encounters, numbered 1-6 for a d6 table.
|
- **Strictly 4-5 Treasures:** Name (max 5 words) and a description (30-40 words). Each treasure MUST:
|
||||||
|
- Include a clear danger or side-effect
|
||||||
|
- Be connected to a specific encounter, NPC, or room
|
||||||
|
- Have story significance beyond just value
|
||||||
|
- Have potential for creative use beyond obvious purpose
|
||||||
|
- Some should be cursed, have activation requirements, or serve dual purposes
|
||||||
|
Format as "Name — Description" using em-dash.
|
||||||
|
|
||||||
Requirements:
|
EXAMPLE TREASURE:
|
||||||
- Name (max 6 words) and details (2 sentences MAX, ~25-40 words).
|
"Whispering Blade — This dagger amplifies the wielder's voice to a deafening roar when drawn. Found in the Guardian Golem's chamber, it was used to command the construct. The blade is cursed: each use permanently reduces the wielder's hearing. Can be used to shatter glass or stun enemies, but the curse cannot be removed."
|
||||||
- Each encounter MUST start with the room/location name followed by a colon, then the details (e.g., "Room Name: details").
|
|
||||||
- The location name must match either the entrance room, climax room, or one of the 3 new locations.
|
|
||||||
- Include environmental hazards/opportunities and tactical considerations (cover, elevation, traps, bottlenecks, escape routes, high ground).
|
|
||||||
- Offer multiple resolution options (combat, negotiation, stealth, puzzle-solving, environmental manipulation, timing, etc.).
|
|
||||||
- At least two encounters must be directly tied to the primary faction from the core concepts.
|
|
||||||
|
|
||||||
Format:
|
- **Strictly 1 Random Events Table:** A d6 table (EXACTLY 6 entries, no more, no less) with random events/wandering encounters. Each entry MUST:
|
||||||
1. Encounter Name: Room Name: Details text.
|
- Have a short, evocative event name (max 4 words)
|
||||||
2. Encounter Name: Room Name: Details text.
|
- Provide interesting complications or opportunities (not just combat)
|
||||||
3. Encounter Name: Room Name: Details text.
|
- Tie to the core concepts and dynamic element
|
||||||
4. Encounter Name: Room Name: Details text.
|
- Add replayability and surprise
|
||||||
5. Encounter Name: Room Name: Details text.
|
- Description should be 15-20 words maximum
|
||||||
6. Encounter Name: Room Name: Details text.
|
- Be UNIQUE and DIFFERENT from each other (no duplicates or generic placeholders)
|
||||||
|
- Be SPECIFIC to this dungeon's theme, conflict, and dynamic element
|
||||||
|
Format as numbered 1-6 list under "Random Events:" label. Each event must be formatted as "Event Name: Description text" using colons, NOT em-dashes.
|
||||||
|
|
||||||
Plain text only. Use colons, NOT em-dashes. Absolutely do not use the word "Obsidian" or "obsidian" anywhere in the output.`,
|
CRITICAL: Each item must be on its own numbered line. DO NOT combine multiple items into a single numbered entry.
|
||||||
undefined,
|
|
||||||
5,
|
|
||||||
"Step 5b: Encounters"
|
|
||||||
);
|
|
||||||
|
|
||||||
const npcsRaw = await callOllama(
|
EXACT FORMAT REQUIRED (DO NOT use placeholder names like "Location Name", "NPC Name", or "Treasure Name" - use actual creative names):
|
||||||
`${sharedContext}
|
Locations:
|
||||||
|
1. Actual Room Name: Description text.
|
||||||
|
2. Actual Room Name: Description text.
|
||||||
|
3. Actual Room Name: Description text.
|
||||||
|
|
||||||
Generate 4-5 important NPCs tied to this dungeon.
|
Encounters:
|
||||||
|
1. Actual Encounter Name: Actual Room Name: Details text.
|
||||||
|
2. Actual Encounter Name: Actual Room Name: Details text.
|
||||||
|
3. Actual Encounter Name: Actual Room Name: Details text.
|
||||||
|
4. Actual Encounter Name: Actual Room Name: Details text.
|
||||||
|
5. Actual Encounter Name: Actual Room Name: Details text.
|
||||||
|
6. Actual Encounter Name: Actual Room Name: Details text.
|
||||||
|
|
||||||
Requirements:
|
NPCs:
|
||||||
- Proper name (max 4 words) and a description (50-65 words).
|
1. Actual Character Name: Description text.
|
||||||
- Each NPC must have: clear motivation, relationship to the primary faction, how they can help or hinder the adventurers, and memorable quirks/traits.
|
2. Actual Character Name: Description text.
|
||||||
- Include multiple interaction possibilities (negotiation, intimidation, help, betrayal).
|
3. Actual Character Name: Description text.
|
||||||
- At least one NPC is a key figure tied to the central conflict.
|
4. Actual Character Name: Description text.
|
||||||
- At least one NPC is a member of the primary faction, one is a potential ally, and one is a rival.
|
|
||||||
|
|
||||||
Format:
|
Treasures:
|
||||||
1. NPC Name: Description text.
|
1. Actual Item Name — Description text.
|
||||||
2. NPC Name: Description text.
|
2. Actual Item Name — Description text.
|
||||||
3. NPC Name: Description text.
|
3. Actual Item Name — Description text.
|
||||||
4. NPC Name: Description text.
|
4. Actual Item Name — Description text.
|
||||||
5. NPC Name: Description text. (omit the 5th if only 4 NPCs)
|
|
||||||
|
|
||||||
Plain text only. Use colons, NOT em-dashes. Absolutely do not use the word "Obsidian" or "obsidian" anywhere in the output.`,
|
|
||||||
undefined,
|
|
||||||
5,
|
|
||||||
"Step 5c: NPCs"
|
|
||||||
);
|
|
||||||
|
|
||||||
const treasuresRaw = await callOllama(
|
|
||||||
`${sharedContext}
|
|
||||||
|
|
||||||
Generate 4-5 unique treasures for this dungeon.
|
|
||||||
|
|
||||||
Requirements:
|
|
||||||
- Each treasure has a name (max 5 words) and a description (30-40 words).
|
|
||||||
- Each treasure includes a clear danger or side-effect.
|
|
||||||
- Each treasure is connected to a specific encounter, NPC, or room.
|
|
||||||
- Each has story significance beyond raw value and potential for creative non-obvious uses.
|
|
||||||
- Some should be cursed, have activation requirements, or serve dual purposes.
|
|
||||||
|
|
||||||
Format:
|
|
||||||
1. Item Name — Description text.
|
|
||||||
2. Item Name — Description text.
|
|
||||||
3. Item Name — Description text.
|
|
||||||
4. Item Name — Description text.
|
|
||||||
5. Item Name — Description text. (omit the 5th if only 4 treasures)
|
|
||||||
|
|
||||||
Plain text only. Use an em-dash (—) between name and description. Absolutely do not use the word "Obsidian" or "obsidian" anywhere in the output.`,
|
|
||||||
undefined,
|
|
||||||
5,
|
|
||||||
"Step 5d: Treasures"
|
|
||||||
);
|
|
||||||
|
|
||||||
const randomEventsRaw = await callOllama(
|
|
||||||
`${sharedContext}
|
|
||||||
|
|
||||||
Generate a d6 Random Events table for this dungeon (EXACTLY 6 entries).
|
|
||||||
|
|
||||||
Requirements:
|
|
||||||
- Short, evocative event name (max 4 words) plus description (15-20 words).
|
|
||||||
- Provide interesting complications or opportunities (not just combat).
|
|
||||||
- Tie directly to the core concepts and the dynamic environmental element.
|
|
||||||
- Each event must be UNIQUE and clearly different from the others.
|
|
||||||
|
|
||||||
Format:
|
|
||||||
Random Events:
|
Random Events:
|
||||||
1. Event Name: Description text.
|
1. Event Name: Event description.
|
||||||
2. Event Name: Description text.
|
2. Event Name: Event description.
|
||||||
3. Event Name: Description text.
|
3. Event Name: Event description.
|
||||||
4. Event Name: Description text.
|
4. Event Name: Event description.
|
||||||
5. Event Name: Description text.
|
5. Event Name: Event description.
|
||||||
6. Event Name: Description text.
|
6. Event Name: Event description.
|
||||||
|
|
||||||
Plain text only. Use colons, NOT em-dashes. Absolutely do not use the word "Obsidian" or "obsidian" anywhere in the output.`,
|
CRITICAL: Every name must be unique and creative. Never use generic placeholders like "Location Name", "NPC Name", "Encounter Name", or "Treasure Name". Use actual descriptive names that fit the dungeon's theme.
|
||||||
undefined,
|
|
||||||
5,
|
CRITICAL: Ensure all spelling is correct. Double-check all words, especially proper nouns, character names, and location names. Verify consistency of names across all sections.
|
||||||
"Step 5e: Random Events"
|
|
||||||
|
CRITICAL: Location name matching - When writing encounters, the location name in the encounter details MUST exactly match one of the room names you've created (Entrance Room, Climax Room, or one of the 3 Locations). Double-check that every encounter location matches an actual room name.
|
||||||
|
|
||||||
|
CRITICAL: Avoid vague language - Do not use words like "some", "various", "several", "many", "few", "things", "stuff", "items", or "objects" without specific details. Be concrete and specific in all descriptions.
|
||||||
|
|
||||||
|
CRITICAL: All names required - Every room, encounter, NPC, and treasure MUST have a name. Do not leave names blank or use placeholders. If you cannot think of a name, create one based on the dungeon's theme.
|
||||||
|
|
||||||
|
CRITICAL: You MUST output exactly five separate sections with these exact labels on their own lines:
|
||||||
|
"Locations:"
|
||||||
|
"Encounters:"
|
||||||
|
"NPCs:"
|
||||||
|
"Treasures:"
|
||||||
|
"Random Events:"
|
||||||
|
|
||||||
|
Each section must start with its label on its own line, followed by numbered items. Do NOT combine sections. Do NOT embed encounters in location descriptions. Each item must be on its own numbered line. Do not use any bolding, preambles, or extra text. Do not use em-dashes (—) in encounters or NPCs, only use colons for those sections. Absolutely do not use the word "Obsidian" or "obsidian" anywhere in the output.`,
|
||||||
|
undefined, 5, "Step 5: Main Content"
|
||||||
);
|
);
|
||||||
|
|
||||||
const mainContentRaw = [
|
|
||||||
"Locations:",
|
|
||||||
locationsRaw.trim(),
|
|
||||||
"",
|
|
||||||
"Encounters:",
|
|
||||||
encountersRaw.trim(),
|
|
||||||
"",
|
|
||||||
"NPCs:",
|
|
||||||
npcsRaw.trim(),
|
|
||||||
"",
|
|
||||||
"Treasures:",
|
|
||||||
treasuresRaw.trim(),
|
|
||||||
"",
|
|
||||||
"Random Events:",
|
|
||||||
randomEventsRaw.replace(/Random Events:\s*/i, "").trim(),
|
|
||||||
].join("\n");
|
|
||||||
|
|
||||||
const { intermediateRoomsSection, encountersSection, npcsSection, treasureSection, randomEventsSection } =
|
const { intermediateRoomsSection, encountersSection, npcsSection, treasureSection, randomEventsSection } =
|
||||||
parseMainContentSections(mainContentRaw);
|
parseMainContentSections(mainContentRaw);
|
||||||
|
|
||||||
|
|||||||
+17
-17
@@ -2,7 +2,7 @@ import sharp from 'sharp';
|
|||||||
import path from "path";
|
import path from "path";
|
||||||
import { mkdir, writeFile } from "fs/promises";
|
import { mkdir, writeFile } from "fs/promises";
|
||||||
import { fileURLToPath } from "url";
|
import { fileURLToPath } from "url";
|
||||||
import { callOllama, OLLAMA_MODEL } from "./ollamaClient.js";
|
import { callOllama } from "./ollamaClient.js";
|
||||||
|
|
||||||
const COMFYUI_ENABLED = process.env.COMFYUI_ENABLED !== 'false';
|
const COMFYUI_ENABLED = process.env.COMFYUI_ENABLED !== 'false';
|
||||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||||
@@ -63,7 +63,7 @@ Input:
|
|||||||
${flavor}
|
${flavor}
|
||||||
|
|
||||||
Output:`,
|
Output:`,
|
||||||
OLLAMA_MODEL,
|
undefined,
|
||||||
3,
|
3,
|
||||||
"Generate Visual Prompt"
|
"Generate Visual Prompt"
|
||||||
);
|
);
|
||||||
@@ -239,22 +239,22 @@ export async function generateDungeonImages({ flavor }) {
|
|||||||
return path.join(__dirname, "dungeon_upscaled.png");
|
return path.join(__dirname, "dungeon_upscaled.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
const finalPrompt = await generateVisualPrompt(flavor);
|
try {
|
||||||
console.log("Engineered visual prompt:\n", finalPrompt);
|
const finalPrompt = await generateVisualPrompt(flavor);
|
||||||
|
console.log("Engineered visual prompt:\n", finalPrompt);
|
||||||
|
|
||||||
const baseFilename = `dungeon.png`;
|
const baseFilename = `dungeon.png`;
|
||||||
const upscaledFilename = `dungeon_upscaled.png`;
|
const upscaledFilename = `dungeon_upscaled.png`;
|
||||||
|
|
||||||
const filepath = await generateImageViaComfyUI(finalPrompt, baseFilename);
|
const filepath = await generateImageViaComfyUI(finalPrompt, baseFilename);
|
||||||
if (!filepath) {
|
if (!filepath) return null;
|
||||||
throw new Error("Failed to generate dungeon image.");
|
|
||||||
|
const upscaledPath = await upscaleImage(filepath, upscaledFilename, 1456, 1024);
|
||||||
|
if (!upscaledPath) return null;
|
||||||
|
|
||||||
|
return upscaledPath;
|
||||||
|
} catch (err) {
|
||||||
|
console.warn("Map image failed:", err.message);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Upscale 2x (half of A4 at 300dpi)
|
|
||||||
const upscaledPath = await upscaleImage(filepath, upscaledFilename, 1456, 1024);
|
|
||||||
if (!upscaledPath) {
|
|
||||||
throw new Error("Failed to upscale dungeon image.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return upscaledPath;
|
|
||||||
}
|
}
|
||||||
|
|||||||
+27
-13
@@ -1,10 +1,16 @@
|
|||||||
import { cleanText } from "./textUtils.js";
|
import { cleanText } from "./textUtils.js";
|
||||||
|
|
||||||
const OLLAMA_API_URL = process.env.OLLAMA_API_URL;
|
const OLLAMA_API_URL = process.env.OLLAMA_API_URL;
|
||||||
export let OLLAMA_MODEL = process.env.OLLAMA_MODEL || "qwen3.6-35b-a3b";
|
|
||||||
|
export const OLLAMA_MODEL = "qwen3.6-35b-a3b";
|
||||||
|
|
||||||
|
function effectiveModel(explicit) {
|
||||||
|
if (explicit !== undefined && explicit !== null) return explicit;
|
||||||
|
return process.env.OLLAMA_MODEL || OLLAMA_MODEL;
|
||||||
|
}
|
||||||
|
|
||||||
export async function initializeModel() {
|
export async function initializeModel() {
|
||||||
if (process.env.OLLAMA_MODEL) return;
|
if (process.env.OLLAMA_MODEL) return process.env.OLLAMA_MODEL;
|
||||||
try {
|
try {
|
||||||
const apiUrl = process.env.OLLAMA_API_URL;
|
const apiUrl = process.env.OLLAMA_API_URL;
|
||||||
const isOpenWebUI = apiUrl?.includes("/api/chat/completions");
|
const isOpenWebUI = apiUrl?.includes("/api/chat/completions");
|
||||||
@@ -20,13 +26,16 @@ export async function initializeModel() {
|
|||||||
? data.data?.[0]?.id || data.data?.[0]?.name
|
? data.data?.[0]?.id || data.data?.[0]?.name
|
||||||
: data.models?.[0]?.name;
|
: data.models?.[0]?.name;
|
||||||
if (model) {
|
if (model) {
|
||||||
OLLAMA_MODEL = model;
|
process.env.OLLAMA_MODEL = model;
|
||||||
console.log(`Using default model: ${model}`);
|
console.log(`Using default model: ${model}`);
|
||||||
|
return model;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
console.warn(`Could not fetch default model, using: ${OLLAMA_MODEL}`);
|
// fall through to warn below
|
||||||
}
|
}
|
||||||
|
console.warn(`Could not fetch default model, using: ${OLLAMA_MODEL}`);
|
||||||
|
return OLLAMA_MODEL;
|
||||||
}
|
}
|
||||||
|
|
||||||
export { cleanText };
|
export { cleanText };
|
||||||
@@ -45,8 +54,10 @@ async function sleep(ms) {
|
|||||||
async function callOllamaBase(prompt, model, retries, stepName, apiType) {
|
async function callOllamaBase(prompt, model, retries, stepName, apiType) {
|
||||||
const isUsingOpenWebUI = apiType === "open-webui";
|
const isUsingOpenWebUI = apiType === "open-webui";
|
||||||
const isUsingOllamaChat = apiType === "ollama-chat";
|
const isUsingOllamaChat = apiType === "ollama-chat";
|
||||||
|
const resolvedModel = effectiveModel(model);
|
||||||
|
const attempts = Array.from({ length: retries }, (_, index) => index + 1);
|
||||||
|
|
||||||
for (let attempt = 1; attempt <= retries; attempt++) {
|
for (const attempt of attempts) {
|
||||||
try {
|
try {
|
||||||
const promptCharCount = prompt.length;
|
const promptCharCount = prompt.length;
|
||||||
const promptWordCount = prompt.split(/\s+/).length;
|
const promptWordCount = prompt.split(/\s+/).length;
|
||||||
@@ -58,14 +69,17 @@ async function callOllamaBase(prompt, model, retries, stepName, apiType) {
|
|||||||
`Prompt: ${promptCharCount} chars, ~${promptWordCount} words`,
|
`Prompt: ${promptCharCount} chars, ~${promptWordCount} words`,
|
||||||
);
|
);
|
||||||
|
|
||||||
const headers = { "Content-Type": "application/json" };
|
const headers =
|
||||||
if (isUsingOpenWebUI && process.env.OLLAMA_API_KEY) {
|
isUsingOpenWebUI && process.env.OLLAMA_API_KEY
|
||||||
headers["Authorization"] = `Bearer ${process.env.OLLAMA_API_KEY}`;
|
? {
|
||||||
}
|
"Content-Type": "application/json",
|
||||||
|
"Authorization": `Bearer ${process.env.OLLAMA_API_KEY}`,
|
||||||
|
}
|
||||||
|
: { "Content-Type": "application/json" };
|
||||||
|
|
||||||
const body = isUsingOpenWebUI || isUsingOllamaChat
|
const body = isUsingOpenWebUI || isUsingOllamaChat
|
||||||
? { model, messages: [{ role: "user", content: prompt }] }
|
? { model: resolvedModel, messages: [{ role: "user", content: prompt }] }
|
||||||
: { model, prompt, stream: false };
|
: { model: resolvedModel, prompt, stream: false };
|
||||||
|
|
||||||
const response = await fetch(OLLAMA_API_URL, {
|
const response = await fetch(OLLAMA_API_URL, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@@ -108,7 +122,7 @@ async function callOllamaBase(prompt, model, retries, stepName, apiType) {
|
|||||||
|
|
||||||
export async function callOllama(
|
export async function callOllama(
|
||||||
prompt,
|
prompt,
|
||||||
model = OLLAMA_MODEL,
|
model,
|
||||||
retries = 5,
|
retries = 5,
|
||||||
stepName = "unknown",
|
stepName = "unknown",
|
||||||
) {
|
) {
|
||||||
@@ -118,7 +132,7 @@ export async function callOllama(
|
|||||||
|
|
||||||
export async function callOllamaExplicit(
|
export async function callOllamaExplicit(
|
||||||
prompt,
|
prompt,
|
||||||
model = OLLAMA_MODEL,
|
model,
|
||||||
retries = 5,
|
retries = 5,
|
||||||
stepName = "unknown",
|
stepName = "unknown",
|
||||||
apiType = "ollama-generate",
|
apiType = "ollama-generate",
|
||||||
|
|||||||
@@ -6,46 +6,46 @@ import path from "path";
|
|||||||
|
|
||||||
const hasOllama = !!process.env.OLLAMA_API_URL;
|
const hasOllama = !!process.env.OLLAMA_API_URL;
|
||||||
|
|
||||||
describe.skipIf(!hasOllama)("Dungeon generation (Ollama)", () => {
|
describe.skipIf(!hasOllama)("Dungeon generation (Ollama)", { timeout: 120000 }, () => {
|
||||||
let dungeonData;
|
const fixture = {};
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
dungeonData = await generateDungeon();
|
fixture.dungeon = await generateDungeon();
|
||||||
}, 120000);
|
});
|
||||||
|
|
||||||
it("generates dungeon data", () => {
|
it("generates dungeon data", () => {
|
||||||
expect(dungeonData).toBeDefined();
|
expect(fixture.dungeon).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("title is 2-4 words, no colons", () => {
|
it("title is 2-4 words, no colons", () => {
|
||||||
expect(dungeonData.title).toBeTruthy();
|
expect(fixture.dungeon.title).toBeTruthy();
|
||||||
const words = dungeonData.title.split(/\s+/);
|
const words = fixture.dungeon.title.split(/\s+/);
|
||||||
expect(words.length).toBeGreaterThanOrEqual(2);
|
expect(words.length).toBeGreaterThanOrEqual(2);
|
||||||
expect(words.length).toBeLessThanOrEqual(4);
|
expect(words.length).toBeLessThanOrEqual(4);
|
||||||
expect(dungeonData.title).not.toContain(":");
|
expect(fixture.dungeon.title).not.toContain(":");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("flavor text is ≤60 words", () => {
|
it("flavor text is ≤60 words", () => {
|
||||||
expect(dungeonData.flavor).toBeTruthy();
|
expect(fixture.dungeon.flavor).toBeTruthy();
|
||||||
const words = dungeonData.flavor.split(/\s+/);
|
const words = fixture.dungeon.flavor.split(/\s+/);
|
||||||
expect(words.length).toBeLessThanOrEqual(60);
|
expect(words.length).toBeLessThanOrEqual(60);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("hooks have no title prefixes", () => {
|
it("hooks have no title prefixes", () => {
|
||||||
expect(dungeonData.hooksRumors).toBeDefined();
|
expect(fixture.dungeon.hooksRumors).toBeDefined();
|
||||||
dungeonData.hooksRumors.forEach((hook) => {
|
fixture.dungeon.hooksRumors.forEach((hook) => {
|
||||||
expect(hook).not.toMatch(/^[^:]+:\s/);
|
expect(hook).not.toMatch(/^[^:]+:\s/);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("has exactly 6 random events", () => {
|
it("has exactly 6 random events", () => {
|
||||||
expect(dungeonData.randomEvents).toBeDefined();
|
expect(fixture.dungeon.randomEvents).toBeDefined();
|
||||||
expect(dungeonData.randomEvents.length).toBe(6);
|
expect(fixture.dungeon.randomEvents.length).toBe(6);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("encounter details do not start with encounter name", () => {
|
it("encounter details do not start with encounter name", () => {
|
||||||
expect(dungeonData.encounters).toBeDefined();
|
expect(fixture.dungeon.encounters).toBeDefined();
|
||||||
dungeonData.encounters.forEach((encounter) => {
|
fixture.dungeon.encounters.forEach((encounter) => {
|
||||||
if (encounter.details) {
|
if (encounter.details) {
|
||||||
const detailsLower = encounter.details.toLowerCase();
|
const detailsLower = encounter.details.toLowerCase();
|
||||||
const nameLower = encounter.name.toLowerCase();
|
const nameLower = encounter.name.toLowerCase();
|
||||||
@@ -55,8 +55,8 @@ describe.skipIf(!hasOllama)("Dungeon generation (Ollama)", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("treasure descriptions do not start with 'description'", () => {
|
it("treasure descriptions do not start with 'description'", () => {
|
||||||
expect(dungeonData.treasure).toBeDefined();
|
expect(fixture.dungeon.treasure).toBeDefined();
|
||||||
dungeonData.treasure.forEach((item) => {
|
fixture.dungeon.treasure.forEach((item) => {
|
||||||
if (typeof item === "object" && item.description) {
|
if (typeof item === "object" && item.description) {
|
||||||
expect(item.description.toLowerCase().startsWith("description")).toBe(false);
|
expect(item.description.toLowerCase().startsWith("description")).toBe(false);
|
||||||
}
|
}
|
||||||
@@ -64,8 +64,8 @@ describe.skipIf(!hasOllama)("Dungeon generation (Ollama)", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("NPC traits do not start with 'description'", () => {
|
it("NPC traits do not start with 'description'", () => {
|
||||||
expect(dungeonData.npcs).toBeDefined();
|
expect(fixture.dungeon.npcs).toBeDefined();
|
||||||
dungeonData.npcs.forEach((npc) => {
|
fixture.dungeon.npcs.forEach((npc) => {
|
||||||
if (npc.trait) {
|
if (npc.trait) {
|
||||||
expect(npc.trait.toLowerCase().startsWith("description")).toBe(false);
|
expect(npc.trait.toLowerCase().startsWith("description")).toBe(false);
|
||||||
}
|
}
|
||||||
@@ -75,11 +75,11 @@ describe.skipIf(!hasOllama)("Dungeon generation (Ollama)", () => {
|
|||||||
it("PDF fits on one page", async () => {
|
it("PDF fits on one page", async () => {
|
||||||
const testPdfPath = path.join(process.cwd(), "test-output.pdf");
|
const testPdfPath = path.join(process.cwd(), "test-output.pdf");
|
||||||
try {
|
try {
|
||||||
await generatePDF(dungeonData, testPdfPath);
|
await generatePDF(fixture.dungeon, testPdfPath);
|
||||||
const pdfBuffer = await fs.readFile(testPdfPath);
|
const pdfBuffer = await fs.readFile(testPdfPath);
|
||||||
const pdfText = pdfBuffer.toString("binary");
|
const pdfText = pdfBuffer.toString("binary");
|
||||||
const pageCount = (pdfText.match(/\/Type\s*\/Page[^s]/g) || []).length;
|
const pageCount = (pdfText.match(/\/Type\s*\/Page[^s]/g) || []).length;
|
||||||
const expectedPages = dungeonData.map ? 2 : 1;
|
const expectedPages = fixture.dungeon.map ? 2 : 1;
|
||||||
expect(pageCount).toBeLessThanOrEqual(expectedPages);
|
expect(pageCount).toBeLessThanOrEqual(expectedPages);
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -203,16 +203,16 @@ describe("initializeModel (mocked fetch)", () => {
|
|||||||
expect(globalThis.fetch).not.toHaveBeenCalled();
|
expect(globalThis.fetch).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("leaves OLLAMA_MODEL unchanged when fetch returns not ok", async () => {
|
it("does not set env when fetch returns not ok", async () => {
|
||||||
process.env.OLLAMA_MODEL = "";
|
process.env.OLLAMA_MODEL = "";
|
||||||
const before = OLLAMA_MODEL;
|
|
||||||
vi.mocked(globalThis.fetch).mockResolvedValueOnce({
|
vi.mocked(globalThis.fetch).mockResolvedValueOnce({
|
||||||
ok: false,
|
ok: false,
|
||||||
status: 404,
|
status: 404,
|
||||||
json: () => Promise.resolve({}),
|
json: () => Promise.resolve({}),
|
||||||
});
|
});
|
||||||
await initializeModel();
|
const resolved = await initializeModel();
|
||||||
expect(OLLAMA_MODEL).toBe(before);
|
expect(resolved).toBe(OLLAMA_MODEL);
|
||||||
|
expect(process.env.OLLAMA_MODEL).toBe("");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fetches /api/tags when OLLAMA_MODEL not set", async () => {
|
it("fetches /api/tags when OLLAMA_MODEL not set", async () => {
|
||||||
@@ -222,11 +222,13 @@ describe("initializeModel (mocked fetch)", () => {
|
|||||||
ok: true,
|
ok: true,
|
||||||
json: () => Promise.resolve({ models: [{ name: "test-model" }] }),
|
json: () => Promise.resolve({ models: [{ name: "test-model" }] }),
|
||||||
});
|
});
|
||||||
await initializeModel();
|
const resolved = await initializeModel();
|
||||||
expect(globalThis.fetch).toHaveBeenCalled();
|
expect(globalThis.fetch).toHaveBeenCalled();
|
||||||
const [url, opts] = vi.mocked(globalThis.fetch).mock.calls[0];
|
const [url, opts] = vi.mocked(globalThis.fetch).mock.calls[0];
|
||||||
expect(String(url)).toMatch(/\/api\/tags$/);
|
expect(String(url)).toMatch(/\/api\/tags$/);
|
||||||
expect(opts?.method || "GET").toBe("GET");
|
expect(opts?.method || "GET").toBe("GET");
|
||||||
|
expect(resolved).toBe("test-model");
|
||||||
|
expect(process.env.OLLAMA_MODEL).toBe("test-model");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fetches /api/v1/models when URL has open-webui path and sets model from data.data id", async () => {
|
it("fetches /api/v1/models when URL has open-webui path and sets model from data.data id", async () => {
|
||||||
@@ -239,7 +241,7 @@ describe("initializeModel (mocked fetch)", () => {
|
|||||||
await initializeModel();
|
await initializeModel();
|
||||||
const [url] = vi.mocked(globalThis.fetch).mock.calls[0];
|
const [url] = vi.mocked(globalThis.fetch).mock.calls[0];
|
||||||
expect(String(url)).toMatch(/\/api\/v1\/models$/);
|
expect(String(url)).toMatch(/\/api\/v1\/models$/);
|
||||||
expect(OLLAMA_MODEL).toBe("webui-model");
|
expect(process.env.OLLAMA_MODEL).toBe("webui-model");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("sets model from data.data[0].name when id missing", async () => {
|
it("sets model from data.data[0].name when id missing", async () => {
|
||||||
@@ -250,7 +252,7 @@ describe("initializeModel (mocked fetch)", () => {
|
|||||||
json: () => Promise.resolve({ data: [{ name: "webui-model-name" }] }),
|
json: () => Promise.resolve({ data: [{ name: "webui-model-name" }] }),
|
||||||
});
|
});
|
||||||
await initializeModel();
|
await initializeModel();
|
||||||
expect(OLLAMA_MODEL).toBe("webui-model-name");
|
expect(process.env.OLLAMA_MODEL).toBe("webui-model-name");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("catches fetch failure and warns", async () => {
|
it("catches fetch failure and warns", async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user