diff --git a/cli/cmd/predict.go b/cli/cmd/predict.go deleted file mode 100644 index 8d3a7e6e88..0000000000 --- a/cli/cmd/predict.go +++ /dev/null @@ -1,130 +0,0 @@ -/* -Copyright 2020 Cortex Labs, Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package cmd - -import ( - "bytes" - "fmt" - "net/http" - - "github.com/cortexlabs/cortex/cli/cluster" - "github.com/cortexlabs/cortex/pkg/lib/errors" - "github.com/cortexlabs/cortex/pkg/lib/exit" - "github.com/cortexlabs/cortex/pkg/lib/files" - "github.com/cortexlabs/cortex/pkg/lib/json" - "github.com/cortexlabs/cortex/pkg/lib/telemetry" - "github.com/cortexlabs/cortex/pkg/types/userconfig" - "github.com/spf13/cobra" -) - -var ( - _flagPredictEnv string -) - -func predictInit() { - _predictCmd.Flags().SortFlags = false - _predictCmd.Flags().StringVarP(&_flagPredictEnv, "env", "e", "", "environment to use") -} - -var _predictCmd = &cobra.Command{ - Use: "predict API_NAME JSON_FILE", - Short: "make a prediction request using a json file", - Args: cobra.ExactArgs(2), - Run: func(cmd *cobra.Command, args []string) { - envName, err := getEnvFromFlag(_flagPredictEnv) - if err != nil { - telemetry.Event("cli.predict") - exit.Error(err) - } - - env, err := ReadOrConfigureEnv(envName) - if err != nil { - telemetry.Event("cli.predict") - exit.Error(err) - } - telemetry.Event("cli.predict", map[string]interface{}{"provider": env.Provider.String(), "env_name": env.Name}) - - err = printEnvIfNotSpecified(env.Name, cmd) - if err != nil { - exit.Error(err) - } - - apiName := args[0] - jsonPath := args[1] - - apisRes, err := cluster.GetAPI(MustGetOperatorConfig(env.Name), apiName) - if err != nil { - exit.Error(err) - } - - if len(apisRes) == 0 { - exit.Error(errors.ErrorUnexpected(fmt.Sprintf("unable to find API %s", apiName))) - } - - apiRes := apisRes[0] - - if apiRes.Spec.Kind != userconfig.RealtimeAPIKind { - exit.Error(errors.ErrorUnexpected("unable to get api", apiName)) // unexpected - } - - totalReady := apiRes.Status.Updated.Ready + apiRes.Status.Stale.Ready - if totalReady == 0 { - exit.Error(ErrorAPINotReady(apiName, apiRes.Status.Message())) - } - - predictResponse, err := makePredictRequest(apiRes.Endpoint, jsonPath) - if err != nil { - exit.Error(err) - } - - prettyResp, err := json.Pretty(predictResponse) - if err != nil { - exit.Error(err) - } - fmt.Println(prettyResp) - }, -} - -func makePredictRequest(apiEndpoint string, jsonPath string) (interface{}, error) { - jsonBytes, err := files.ReadFileBytes(jsonPath) - if err != nil { - exit.Error(err) - } - - payload := bytes.NewBuffer(jsonBytes) - req, err := http.NewRequest("POST", apiEndpoint, payload) - if err != nil { - return nil, errors.Wrap(err, _errStrCantMakeRequest) - } - - req.Header.Set("Content-Type", "application/json") - header, httpResponseBody, err := makeRequest(req) - if err != nil { - return nil, err - } - - if header.Get("Content-Type") == "application/json" { - var predictResponse interface{} - err = json.DecodeWithNumber(httpResponseBody, &predictResponse) - if err != nil { - return nil, errors.Wrap(err, "prediction response") - } - return predictResponse, nil - } - - return string(httpResponseBody), nil -} diff --git a/cli/cmd/root.go b/cli/cmd/root.go index c7abc34371..ecaefcbf03 100644 --- a/cli/cmd/root.go +++ b/cli/cmd/root.go @@ -120,7 +120,6 @@ func init() { getInit() logsInit() patchInit() - predictInit() refreshInit() versionInit() } @@ -162,7 +161,6 @@ func Execute() { _rootCmd.AddCommand(_patchCmd) _rootCmd.AddCommand(_logsCmd) _rootCmd.AddCommand(_refreshCmd) - _rootCmd.AddCommand(_predictCmd) _rootCmd.AddCommand(_deleteCmd) _rootCmd.AddCommand(_clusterCmd) diff --git a/docs/clients/cli.md b/docs/clients/cli.md index 1859409d32..04804df513 100644 --- a/docs/clients/cli.md +++ b/docs/clients/cli.md @@ -75,19 +75,6 @@ Flags: -h, --help help for refresh ``` -## predict - -```text -make a prediction request using a json file - -Usage: - cortex predict API_NAME JSON_FILE [flags] - -Flags: - -e, --env string environment to use - -h, --help help for predict -``` - ## delete ```text