Skip to content

Commit

Permalink
set default model at the ARGV level
Browse files Browse the repository at this point in the history
minimist has a way to set the default values for command line position arguments and flags. let's use it!
  • Loading branch information
zeke committed Feb 7, 2024
1 parent cdd243c commit 63375cc
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,33 @@ const __dirname = dirname(__filename)

const args = minimist(process.argv.slice(2), {
boolean: ['run-after-setup'],
default: { 'run-after-setup': true }
default: {
'run-after-setup': true,
model: 'stability-ai/sdxl'

}
})

console.log({ args })

const targetAppName = args._[0] || 'my-replicate-app'
const modelName = args.model || 'stability-ai/sdxl'

let model
try {
model = getModel(modelName)
model = getModel(args.model)
} catch (e) {
console.error('Model not found:', modelName)
console.error('Model not found:', args.model)
process.exit()
}

// If user has provided a model version, use it. Otherwise, use the latest version
const modelVersionRegexp = /.*:[a-fA-F0-9]{64}$/
const modelNameWithVersion = modelName.match(modelVersionRegexp) ? modelName : getModelNameWithVersion(model)
const modelNameWithVersion = args.model.match(modelVersionRegexp) ? args.model : getModelNameWithVersion(model)

const inputs = getModelInputs(model)

console.log(`Creating project "${targetAppName}"...`)
console.log(`Model: ${modelName}...`)
console.log(`Model: ${args.model}...`)
console.log('Copying files...')
const templateDir = path.join(__dirname, 'template')
const targetDir = path.join(process.cwd(), targetAppName)
Expand Down

0 comments on commit 63375cc

Please sign in to comment.