谷歌云顶点 AI 与 Golang : rpc error: code = Unimplemented desc = unexpected HTTP status code received from server: 404 (Not Found)

标签 go grpc gcloud google-cloud-vertex-ai google-ai-platform

我在端点上部署了一个 Vertex AI 模型,并希望通过我在 Golang 中的应用程序进行一些预测。

为此,我创建了受此示例启发的代码:https://cloud.google.com/go/docs/reference/cloud.google.com/go/aiplatform/latest/apiv1?hl=en

const file = "MY_BASE64_IMAGE"

func main() {

    ctx := context.Background()

    c, err := aiplatform.NewPredictionClient(cox)
    if err != nil {
        log.Printf("QueryVertex NewPredictionClient - Err:%s", err)
    }
    defer c.Close()

    parameters, err := structpb.NewValue(map[string]interface{}{
        "confidenceThreshold": 0.2,
        "maxPredictions":      5,
    })
    if err != nil {
        log.Printf("QueryVertex structpb.NewValue parameters - Err:%s", err)
    }

    instance, err := structpb.NewValue(map[string]interface{}{
        "content": file,
    })
    if err != nil {
        log.Printf("QueryVertex structpb.NewValue instance - Err:%s", err)
    }

    reqP := &aiplatformpb.PredictRequest{
        Endpoint:   "projects/PROJECT_ID/locations/LOCATION_ID/endpoints/ENDPOINT_ID",
        Instances:  []*structpb.Value{instance},
        Parameters: parameters,
    }

    resp, err := c.Predict(cox, reqP)
    if err != nil {
        log.Printf("QueryVertex Predict - Err:%s", err)
    }

    log.Printf("QueryVertex Res:%+v", resp)
}

我将我的服务帐户 JSON 文件的路径放在 GOOGLE_APPLICATION_CREDENTIALS 环境变量中。 但是当我运行我的测试应用程序时,我收到了这条错误消息:

QueryVertex Predict - Err:rpc error: code = Unimplemented desc = unexpected HTTP status code received from server: 404 (Not Found); transport: received unexpected content-type "text/html; charset=UTF-8"
QueryVertex Res:<nil>

最佳答案

正如@DazWilkin 所建议的,配置客户端选项以指定特定的 regional endpoint使用端口 443:

option.WithEndpoint("<region>-aiplatform.googleapis.com:443")

尝试如下:

func main() {
 
   ctx := context.Background()
   c, err := aiplatform.NewPredictionClient(
       ctx,
       option.WithEndpoint("<region>-aiplatform.googleapis.com:443"),
   )
   if err != nil {
       log.Printf("QueryVertex NewPredictionClient - Err:%s", err)
   }
   defer c.Close()
       .
       .

关于谷歌云顶点 AI 与 Golang : rpc error: code = Unimplemented desc = unexpected HTTP status code received from server: 404 (Not Found),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72122744/

相关文章:

c++ - C/C++能否将所有动态库构建到一个bin文件中?

node.js - 序列化失败(grpc/node)

go - 将 YAML 解码为未知结构

go - 在 golang 中,如果其中一个方法必须具有指针接收器,是否有必要将一种类型的所有方法更改为具有指针接收器?

c++ - 在 C++ 中使用 gRPC 时未解析的外部符号

python - 如何使用结构化数据创建 ClassificationRequest 以使用 gRPC 发送到 TensorFlow Serving

java - 如何使用 Java 以编程方式获取 GCP Bearer token

parameters - 在 google dataproc 上执行 Pig 作业时,如何使用 params 标志来表示多个以逗号分隔的值?

ruby-on-rails - 将 Rails 6 应用程序部署到 Google Cloud Platform App Engine 时出错

tcp - 即使端口上没有任何运行,绑定(bind)地址已在使用中的 golang 错误