Google Cloud Vertex AI 与 Golang:rpc 错误:代码 = 未实现的 desc = 从服务器收到的意外 HTTP 状态代码:404(未找到)

gar*_*rym 7 go gcloud grpc google-ai-platform google-cloud-vertex-ai

我在端点上部署了 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)
}
Run Code Online (Sandbox Code Playgroud)

我将服务帐户 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>
Run Code Online (Sandbox Code Playgroud)

Vis*_*l K 8

正如 @DazWilkin 建议的那样,配置客户端选项以指定具有端口 443 的特定区域端点:

option.WithEndpoint("<region>-aiplatform.googleapis.com:443")
Run Code Online (Sandbox Code Playgroud)

尝试如下:

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()
       .
       .
Run Code Online (Sandbox Code Playgroud)