关于JSON和GCP的问题

发布于 2025-02-02 18:25:17 字数 2337 浏览 6 评论 0原文

因此,我有此代码写出一个通过端点连接到的JSON文件。该文件是非常标准的,因为它具有如何连接到端点以及某些数据的位置。

%%writefile default-pred.json
{   PROJECT_ID:"msds434-gcp",
    REGION:"us-central1",
    ENDPOINT_ID:"2857701089334001664",
    INPUT_DATA_FILE:"INPUT-JSON",
    "instances": [
    {"age": 39,
    "bill_amt_1": 47174,
    "bill_amt_2": 47974,
    "bill_amt_3": 48630,
    "bill_amt_4": 50803,
    "bill_amt_5": 30789,
    "bill_amt_6": 15874,
    "education_level": "1",
    "limit_balance": 50000,
    "marital_status": "2",
    "pay_0": 0,
    "pay_2":0,
    "pay_3": 0,
    "pay_4": 0,
    "pay_5": "0",
    "pay_6": "0",
    "pay_amt_1": 1800,
    "pay_amt_2": 2000,
    "pay_amt_3": 3000,
    "pay_amt_4": 2000,
    "pay_amt_5": 2000,
    "pay_amt_6": 2000,
    "sex": "1"
    }
  ]
    }

然后,我将尝试连接到文件,然后将信息连接到有关终点。我知道信息是正确的,因为这是GCP的确切代码。

!curl \
-X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
https://us-central1-prediction-aiplatform.googleapis.com/v1alpha1/projects/$PROJECT_ID/locations/$REGION/endpoints/$ENDPOINT_ID:predict \
-d "@default-pred.json"

因此,从信息中,我希望它可以解析我拥有的信息并连接到端点,但是显然我以某种方式有错误的文件。知道这是什么吗?

{
  "error": {
    "code": 400,
    "message": "Invalid JSON payload received. Unknown name \"PROJECT_ID\": Cannot find field.\nInvalid JSON payload received. Unknown name \"REGION\": Cannot find field.\nInvalid JSON payload received. Unknown name \"ENDPOINT_ID\": Cannot find field.\nInvalid JSON payload received. Unknown name \"INPUT_DATA_FILE\": Cannot find field.",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.BadRequest",
        "fieldViolations": [
          {
            "description": "Invalid JSON payload received. Unknown name \"PROJECT_ID\": Cannot find field."
          },
          {
            "description": "Invalid JSON payload received. Unknown name \"REGION\": Cannot find field."
          },
          {
            "description": "Invalid JSON payload received. Unknown name \"ENDPOINT_ID\": Cannot find field."
          },
          {
            "description": "Invalid JSON payload received. Unknown name \"INPUT_DATA_FILE\": Cannot find field."
          }
        ]
      }
    ]
  }
}

我在这里想念什么?

So I have this code to write out a json file to be connected to via endpoint. The file is pretty standard in that it has the location of how to connect to the endpoint as well as some data.

%%writefile default-pred.json
{   PROJECT_ID:"msds434-gcp",
    REGION:"us-central1",
    ENDPOINT_ID:"2857701089334001664",
    INPUT_DATA_FILE:"INPUT-JSON",
    "instances": [
    {"age": 39,
    "bill_amt_1": 47174,
    "bill_amt_2": 47974,
    "bill_amt_3": 48630,
    "bill_amt_4": 50803,
    "bill_amt_5": 30789,
    "bill_amt_6": 15874,
    "education_level": "1",
    "limit_balance": 50000,
    "marital_status": "2",
    "pay_0": 0,
    "pay_2":0,
    "pay_3": 0,
    "pay_4": 0,
    "pay_5": "0",
    "pay_6": "0",
    "pay_amt_1": 1800,
    "pay_amt_2": 2000,
    "pay_amt_3": 3000,
    "pay_amt_4": 2000,
    "pay_amt_5": 2000,
    "pay_amt_6": 2000,
    "sex": "1"
    }
  ]
    }

Then I have this trying to connect to the file and then taking the information to connect to the end point in question. I know the information is right as it's the exact code from GCP.

!curl \
-X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
https://us-central1-prediction-aiplatform.googleapis.com/v1alpha1/projects/$PROJECT_ID/locations/$REGION/endpoints/$ENDPOINT_ID:predict \
-d "@default-pred.json"

So from the information I have I would expect it to parse the information I have and connect to the endpoint, but obviously I have my file wrong somehow. Any idea what it is?

{
  "error": {
    "code": 400,
    "message": "Invalid JSON payload received. Unknown name \"PROJECT_ID\": Cannot find field.\nInvalid JSON payload received. Unknown name \"REGION\": Cannot find field.\nInvalid JSON payload received. Unknown name \"ENDPOINT_ID\": Cannot find field.\nInvalid JSON payload received. Unknown name \"INPUT_DATA_FILE\": Cannot find field.",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.BadRequest",
        "fieldViolations": [
          {
            "description": "Invalid JSON payload received. Unknown name \"PROJECT_ID\": Cannot find field."
          },
          {
            "description": "Invalid JSON payload received. Unknown name \"REGION\": Cannot find field."
          },
          {
            "description": "Invalid JSON payload received. Unknown name \"ENDPOINT_ID\": Cannot find field."
          },
          {
            "description": "Invalid JSON payload received. Unknown name \"INPUT_DATA_FILE\": Cannot find field."
          }
        ]
      }
    ]
  }
}

What am I missing here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北方的巷 2025-02-09 18:25:17

数据文件应仅包括数据。

您已包括Project_IDregionendpoint不应该。

这些需要在(bash)环境 之前您发行curl命令:

PROJECT_ID="msds434-gcp"
REGION="us-central1"
ENDPOINT_ID="2857701089334001664"

curl \
--request POST \
--header "Authorization: Bearer $(gcloud auth print-access-token)" \
--header "Content-Type: application/json" \
https://us-central1-prediction-aiplatform.googleapis.com/v1alpha1/projects/$PROJECT_ID/locations/$REGION/endpoints/$ENDPOINT_ID:predict \
--data "@default-pred.json"

文件default-pred.json应该可能(我在

{
  instances": [
    { "age": 39,
      "bill_amt_1": 47174,
      "bill_amt_2": 47974,
      "bill_amt_3": 48630,
      "bill_amt_4": 50803,
      "bill_amt_5": 30789,
      "bill_amt_6": 15874,
      "education_level": "1",
      "limit_balance": 50000,
      "marital_status": "2",
      "pay_0": 0,
      "pay_2":0,
      "pay_3": 0,
      "pay_4": 0,
      "pay_5": "0",
      "pay_6": "0",
      "pay_amt_1": 1800,
      "pay_amt_2": 2000,
      "pay_amt_3": 3000,
      "pay_amt_4": 2000,
      "pay_amt_5": 2000,
      "pay_amt_6": 2000,
      "sex": "1"
    }
  ]
}

请参阅aiplatform 预测 方法,这解释了这一点。

The data file should only include the data.

You've included PROJECT_ID, REGION, ENDPOINT and should not.

These need to be set in the (bash) environment before you issue the curl command:

PROJECT_ID="msds434-gcp"
REGION="us-central1"
ENDPOINT_ID="2857701089334001664"

curl \
--request POST \
--header "Authorization: Bearer $(gcloud auth print-access-token)" \
--header "Content-Type: application/json" \
https://us-central1-prediction-aiplatform.googleapis.com/v1alpha1/projects/$PROJECT_ID/locations/$REGION/endpoints/$ENDPOINT_ID:predict \
--data "@default-pred.json"

The file default-pred.json should probably (I can never find this service's methods in APIs Explorer!) just be:

{
  instances": [
    { "age": 39,
      "bill_amt_1": 47174,
      "bill_amt_2": 47974,
      "bill_amt_3": 48630,
      "bill_amt_4": 50803,
      "bill_amt_5": 30789,
      "bill_amt_6": 15874,
      "education_level": "1",
      "limit_balance": 50000,
      "marital_status": "2",
      "pay_0": 0,
      "pay_2":0,
      "pay_3": 0,
      "pay_4": 0,
      "pay_5": "0",
      "pay_6": "0",
      "pay_amt_1": 1800,
      "pay_amt_2": 2000,
      "pay_amt_3": 3000,
      "pay_amt_4": 2000,
      "pay_amt_5": 2000,
      "pay_amt_6": 2000,
      "sex": "1"
    }
  ]
}

See the documentation for the aiplatform predict method as this explains this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文