Learn how to create powerful scripts that combine SPOUT's core modules into sophisticated text processing pipelines.
Basic Script Structure
Create a new script directory following this pattern:
scripting/
└── my_script/
├── my_script.mjs # Main script file
├── README.md # Documentation
└── config.json # Optional configuration
Script Template
#!/usr/bin/env zx
// Import utilities
import 'zx/globals'
import { parseArgs } from 'node:util'
// Parse command line arguments
const options = {
threads: 2,
output: './output',
model: 'gpt-4'
}
// Basic pipeline example
async function processText(input) {
// Reduce the input
const summary = await $`spout reduce --input "${input}" --quiet`
// Enhance the summary
const enhanced = await $`spout enhance --input "${summary}" --quiet`
// Generate final output
return await $`spout generate --description "${enhanced}" --style "creative"`
}
Common Patterns
Sequential Processing
Chain modules in sequence for step-by-step transformations:
async function refineText(input) {
const reduced = await $`spout reduce --input "${input}"`
const enhanced = await $`spout enhance --input "${reduced}"`
const translated = await $`spout translate --input "${enhanced}" --target "Spanish"`
return translated
}
Parallel Processing
Process multiple items simultaneously:
async function batchProcess(items, threads = 2) {
const chunks = chunk(items, threads)
const promises = chunks.map(async (chunk) => {
return Promise.all(chunk.map(processText))
})
return (await Promise.all(promises)).flat()
}
Evaluation Loops
Use the Evaluate module to select best outputs:
async function evolveText(input, generations = 3) {
let current = input
for (let i = 0; i < generations; i++) {
const variants = await $`spout mutate --input "${current}" --num_variants 5`
const scores = await $`spout evaluate --input "${variants}"`
current = selectBest(variants, scores)
}
return current
}
Script Ideas to Try
Content Factory
Generate varied content with consistent style:
- Use Generate for initial drafts
- Enhance for quality
- Evaluate for consistency
- Parse for validation
Language Learning Assistant
Create interactive language exercises:
- Translate source material
- Generate practice questions
- Evaluate user responses
- Provide corrections
Story Evolution System
Evolve narratives through iterations:
- Generate initial plots
- Expand key scenes
- Mutate for variations
- Evaluate reader engagement
Research Assistant
Build a research workflow:
- Search for topics
- Reduce findings
- Enhance clarity
- Parse key points
Best Practices
- Error Handling
try {
await processText(input)
} catch (error) {
console.error(`Processing failed: ${error.message}`)
process.exit(1)
}
- Configuration Management
const config = JSON.parse(await fs.readFile('./config.json'))
const { apiKey, model, maxTokens } = config
- Progress Tracking
function showProgress(current, total) {
const percent = Math.round((current / total) * 100)
console.log(`Progress: ${percent}% (${current}/${total})`)
}
Ideas for Possible custom Scripts:
- Create a script to generate a list of possible prompts for a given topic
- Autogenerate new specialized Hotkey Consoles using existing examples
- generate new addons using core modules as examples
- generate new spoutlets using existing spoutlets as examples
- iteratively test different spoutlet config settings to find optimal configurations