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?
CodePudding user response:
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.