Skip to content

Commit

Permalink
feat: use Replicate prediction id as filename prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
zeke committed Aug 1, 2024
1 parent 60f6074 commit e115794
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ export async function run ({ model, prompt, outputDir }) {
const input = { prompt }

let output
let predictionId
try {
output = await replicate.run(model, { input })
output = await replicate.run(model, { input }, ({ id }) => {
predictionId = id
})
console.log({ input, output })
} catch (error) {
console.error(error)
Expand All @@ -34,10 +37,8 @@ export async function run ({ model, prompt, outputDir }) {

for (const url of output) {
const urlPath = new URL(url).pathname
const segments = urlPath.split('/')
const secondToLastSegment = segments[segments.length - 2]
const fileExtension = path.extname(urlPath)
const filename = `${secondToLastSegment}-${slugify(input.prompt).substring(0, 100)}${fileExtension}`
const filename = `${predictionId}-${slugify(input.prompt).substring(0, 100)}${fileExtension}`

await download(url, outputDir, { filename })
}
Expand Down

0 comments on commit e115794

Please sign in to comment.