Skip to content

Conversation

@jakedahn
Copy link
Contributor

@jakedahn jakedahn commented Nov 17, 2023

This PR introduces a new scaffold command to the Replicate CLI.

You can use this command to bootstrap a completely functional development environment from a given prediction ID or URL.

To start, support is limited to javascript via the https://github.com/replicate/node-starter repo and python via the https://github.com/replicate/python-starter repo.

Usage

Scaffold via prediction URL

  • replicate scaffold https://replicate.com/p/z5kvo4tb6mhb7xnpxpjpfxlzxe /path/to/repo (default uses node)
  • replicate scaffold --template node https://replicate.com/p/z5kvo4tb6mhb7xnpxpjpfxlzxe /path/to/repo (node)
  • replicate scaffold --template python https://replicate.com/p/z5kvo4tb6mhb7xnpxpjpfxlzxe /path/to/repo (python)

Scaffold via prediction ID

  • replicate scaffold z5kvo4tb6mhb7xnpxpjpfxlzxe /path/to/repo (default uses node)
  • replicate scaffold --template node z5kvo4tb6mhb7xnpxpjpfxlzxe /path/to/repo (node)
  • replicate scaffold --template python z5kvo4tb6mhb7xnpxpjpfxlzxe /path/to/repo (python)

`replicate clone --template node [prediction] [output path]`
`replicate clone --template python [prediction] [output path]`
@jakedahn jakedahn requested a review from mattt November 17, 2023 04:10
@zeke
Copy link
Member

zeke commented Nov 17, 2023

Should we also support this other format of prediction URL?

https://replicate.com/stability-ai/stable-diffusion?prediction=emeqxllb6c4uxjy2dbun6yk62u

Copy link
Contributor

@mattt mattt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, @jakedahn. Thank you so much for working on this. I left some specific code review suggestions for your consideration.

Some more high-level feedback:

  • I'm not sure clone is the right spelling for this command. I slightly prefer scaffold, but maybe there's another option bootstrap? project init?

    • If project init, then maybe the prediction is optional, and you just use a default example, like SDXL.
  • Looking what's in the starter repos, I think it might make sense to embed them in the CLI itself. Go has a nice affordance for embedding source files as string constants to make that convenient.

    • If the concern is future-proofing, then we could put the template files in the CLI repo and fetch the latest versions.

Comment on lines 115 to 128
// Run the example prediction
fmt.Println("Running example prediction...")
commands = []string{
fmt.Sprintf("cd %s && node prediction.py", outputClonePath),
}
for _, command := range commands {
cmd := exec.Command("bash", "-c", command)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
return err
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this last step of running the prediction to be unexpected. Instead, I think we should print the output path and provide instructions for what to do next.

Copy link
Contributor

@mattt mattt Nov 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jakedahn Any objections to skipping this last step?

@bfirsh
Copy link
Member

bfirsh commented Nov 17, 2023

Agreed clone feels a bit funny. Not sure why. Perhaps because it's a bit of a different intent from Git? Perhaps because having it as a top-level command implies it's a primary action of Replicate the product? Run, models, deployments... clone?

init is a pattern we have in Cog. Scaffold and bootstrap both seem pretty good too. No strong feelings overall.

jakedahn and others added 10 commits November 17, 2023 09:16
…e optional argument, and change to kebab case.

Co-authored-by: Mattt <mattt@replicate.com>
Co-authored-by: Mattt <mattt@replicate.com>
…default name should be generated based on the prediction ID

Co-authored-by: Mattt <mattt@replicate.com>
Co-authored-by: Mattt <mattt@replicate.com>
Co-authored-by: Mattt <mattt@replicate.com>
Co-authored-by: Mattt <mattt@replicate.com>
Co-authored-by: Mattt <mattt@replicate.com>
Co-authored-by: Mattt <mattt@replicate.com>
@zeke
Copy link
Member

zeke commented Nov 17, 2023

Looking what's in the starter repos, I think it might make sense to embed them in the CLI itself.

I tend to agree.

@jakedahn
Copy link
Contributor Author

jakedahn commented Nov 17, 2023

Looking what's in the starter repos, I think it might make sense to embed them in the CLI itself.

I tend to agree.

I disagree here.

The hope behind using actual git repos here is that in a future iteration, someone could say replicate init --template https://github.com/cbh123/replicate-elixir.git <prediction id> /path/to/checkout. Allowing anybody the ability to create their own starter templates that hook into the same cli.

I think it's a strange experience to be like "oh I would really love to add a starter template for elixir", and then be forced to vendor everything inside of a golang codebase where it never gets updated because doing so inside of a golang codebase feels foreign.

This pattern is not implemented in this PR as-is, but this is a future I think is worth heading towards.

@jakedahn
Copy link
Contributor Author

I've renamed everything to replicate init 🙌

@mattt
Copy link
Contributor

mattt commented Nov 19, 2023

The hope behind using actual git repos here is that in a future iteration, someone could say replicate init --template https://github.com/cbh123/replicate-elixir.git <prediction id> /path/to/checkout. Allowing anybody the ability to create their own starter templates that hook into the same cli.

@jakedahn 100% with you. We can get the best of both worlds by locating built-in templates (python, node) in CLI repo, and eventually allowing user-provided URLs to repos.

You could even implement this internally by routing aliases like python to the full path in the CLI repo on GitHub. You'd just need to support paths to subdirectories.

@mattt
Copy link
Contributor

mattt commented Nov 20, 2023

@jakedahn Thanks again for your great work on this. I'm excited to have this in the CLI.

I was thinking about this some more the other day, and came up with a slightly different interface:

# Generate from a prediction
replicate prediction scaffold z5kvo4tb6mhb7xnpxpjpfxlzxe # also supports URLs


# Generate from a model's default example
replicate model scaffold stability-ai/sdxl # also supports URLs, optional version


# Top-level alias that automatically does the right thing
replicate scaffold z5kvo4tb6mhb7xnpxpjpfxlzxe # prediction ID
replicate scaffold stability-ai/sdxl # model name
replicate scaffold # default project template 

In the interest of shipping fast and iterating, the minimal change would be to rename init to scaffold. From there, we could fill in the respective subcommands and update the top-level command to support no argument and a model argument.

How does that sound?

@mattt mattt changed the title Adding a new clone command to the CLI Add a new scaffold command to the CLI Nov 20, 2023
@mattt mattt merged commit c2aa540 into main Nov 20, 2023
@mattt mattt deleted the replicate-clone branch November 20, 2023 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants