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

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>