googleapis / google-cloud-go

Google Cloud Client Libraries for Go.
https://cloud.google.com/go/docs/reference
Apache License 2.0
3.72k stars 1.27k forks source link

automl.Predict: Unsupported payload type `text_snippet` #4231

Closed deanchou closed 3 years ago

deanchou commented 3 years ago

Client

PredictionClient

Environment

debian10

Go Environment

go version go1.16.2 linux/amd64
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/data/go/pkg/mod"
GONOPROXY="github.com/xrednine"
GONOSUMDB="github.com/xrednine"
GOOS="linux"
GOPATH="/data/go"
GOPRIVATE="github.com/xrednine"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/data/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/data/lib/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16.2"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/data/go/src/whatsapp/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build963304162=/tmp/go-build -gno-record-gcc-switches"

Code

e.g.

package main

import (
    "context"
    "fmt"

    automl "cloud.google.com/go/automl/apiv1"
    "google.golang.org/api/option"
    automlpb "google.golang.org/genproto/googleapis/cloud/automl/v1"
)

func main() {
    var content = `"undergraduate",
    "8",
    "84",
    "MOSLEM",
    "yes",
    "free_contact",
    "Single",
    "yes",
    "yes",
    "PMD",
    "",
    "8171025908800005",
    "female",
    "yes",
    "1980",
    "Friends",
    "4500000",
    "Parents",
    "SM-A750GN",
    "81"`
    var clientOpt option.ClientOption = option.WithCredentialsFile("service-account-key.json")
    var formattedName string = fmt.Sprintf("projects/%s/locations/%s/models/%s", "xxxxxxxxxxx", "us-central1", "xxxxxxxxxx")
    var request = &automlpb.PredictRequest{
        Name: formattedName,
        Payload: &automlpb.ExamplePayload{
            Payload: &automlpb.ExamplePayload_TextSnippet{
                TextSnippet: &automlpb.TextSnippet{
                    Content:  content,
                    MimeType: "text/plain", // Types: "text/plain", "text/html"
                },
            },
        },
    }

    c, err := automl.NewPredictionClient(context.Background(), clientOpt)
    if err != nil {
        fmt.Println(err.Error())
    }

    resp, err := c.Predict(context.Background(), request)
    if err != nil {
        fmt.Println(err.Error())
    }

    fmt.Println(resp.String())
}

Expected behavior

{
  "payload": [
    {
      "tables": {
        "score": 0.81621456,
        "value": "0"
      }
    },
    {
      "tables": {
        "score": 0.17538959,
        "value": "1"
      }
    },
    {
      "tables": {
        "score": 0.008395818,
        "value": "2"
      }
    }
  ]
}

Actual behavior

rpc error: code = InvalidArgument desc = Unsupported payload typetext_snippet. Please check the documentation.

codyoss commented 3 years ago

Hey @deanchou without knowing more details about your model it is a little tricky to debug. My best guess is that the input provided does not match the type of which your model was trained to handle.

From the docs:

Payload: Required. Payload to perform a prediction on. The payload must match the problem type that the model was trained to solve.

deanchou commented 3 years ago

vary thankful

I think it's a version problem

type ExamplePayload_Row in v1beta1 but not in v1

codyoss commented 3 years ago

@deanchou Glad you got it all figured out!