cmd

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 20, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AccountCmd = &cobra.Command{
	Use:     "account",
	Short:   `Alias for "accounts current"`,
	Aliases: []string{"profile", "whoami"},
	RunE:    account.CurrentCmd.RunE,
}
View Source
var RunCmd = &cobra.Command{
	Use:   "run <owner/model[:version]> [input=value] ... [flags]",
	Short: `Alias for "prediction create"`,
	Args:  cobra.MinimumNArgs(1),
	RunE:  prediction.CreateCmd.RunE,
}
View Source
var ScaffoldCmd = &cobra.Command{
	Use:   "scaffold <prediction-ID-or-URL> [<directory>] [--template=<template>]",
	Short: "Create a new local development environment from a prediction",
	Args:  cobra.RangeArgs(1, 2),
	RunE: func(cmd *cobra.Command, args []string) error {
		ctx := cmd.Context()

		apiToken := os.Getenv("REPLICATE_API_TOKEN")
		if apiToken == "" {
			return fmt.Errorf("REPLICATE_API_TOKEN environment variable not set. Please set this to your Replicate API token")
		}

		client, err := replicate.NewClient(replicate.WithToken(apiToken))
		if err != nil {
			return err
		}

		predictionID, err := parsePredictionID(args[0])
		if err != nil {
			return fmt.Errorf("failed to parse prediction ID: %w", err)
		}
		prediction, err := client.GetPrediction(ctx, predictionID)
		if prediction == nil || err != nil {
			return fmt.Errorf("failed to get prediction: %w", err)
		}

		var directory string
		if len(args) == 2 {
			directory = args[1]
		} else {
			directory = predictionID
		}

		template, _ := cmd.Flags().GetString("template")

		switch template {
		case "node", "nodejs", "js", "":
			return handleNodeTemplate(ctx, prediction, directory, apiToken)
		case "python":
			return handlePythonTemplate(ctx, prediction, directory, apiToken)
		default:
			return fmt.Errorf("unsupported template: %s, expected one of: node, python", template)
		}
	},
}
View Source
var StreamCmd = &cobra.Command{
	Use:   "stream <owner/model[:version]> [input=value] ... [flags]",
	Short: `Alias for "prediction create --stream"`,
	Args:  cobra.MinimumNArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		err := cmd.Flags().Set("stream", "true")
		if err != nil {
			return err
		}

		return prediction.CreateCmd.RunE(cmd, args)
	},
}
View Source
var TrainCmd = &cobra.Command{
	Use:   "train <owner/model[:version]> [input=value] ... [flags]",
	Short: `Alias for "training create"`,
	Args:  cobra.MinimumNArgs(1),
	RunE:  training.CreateCmd.RunE,
}

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL