Skip to content

Commit f08ea11

Browse files
suryaguthikondagcf-owl-bot[bot]junkourata
authored andcommitted
feat(samples): add feature apis samples (#340)
* added create-featurestore-sample.js and create-featurestore-sample.test.js * feat(samples): added createFeaturestore sample (#313) * feat(samples): added remaining featurestore samples (#313) * removed the extraneous files * feat(samples): add feature apis samples (#313) * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * feat(samples): updated feature-samples.test.js (#313) * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: junkourata <[email protected]>
1 parent b92bdec commit f08ea11

12 files changed

+1223
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/*
18+
* Creates a batch of Features in a given EntityType.
19+
* See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running
20+
* the code snippet
21+
*/
22+
23+
'use strict';
24+
25+
async function main(
26+
project,
27+
featurestoreId,
28+
entityTypeId,
29+
location = 'us-central1',
30+
apiEndpoint = 'us-central1-aiplatform.googleapis.com',
31+
timeout = 300000
32+
) {
33+
// [START aiplatform_batch_create_features_sample]
34+
/**
35+
* TODO(developer): Uncomment these variables before running the sample.\
36+
* (Not necessary if passing values as arguments)
37+
*/
38+
39+
// const project = 'YOUR_PROJECT_ID';
40+
// const featurestoreId = 'YOUR_FEATURESTORE_ID';
41+
// const entityTypeId = 'YOUR_ENTITY_TYPE_ID';
42+
// const location = 'YOUR_PROJECT_LOCATION';
43+
// const apiEndpoint = 'YOUR_API_ENDPOINT';
44+
// const timeout = <TIMEOUT_IN_MILLI_SECONDS>;
45+
46+
// Imports the Google Cloud Featurestore Service Client library
47+
const {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1;
48+
49+
// Specifies the location of the api endpoint
50+
const clientOptions = {
51+
apiEndpoint: apiEndpoint,
52+
};
53+
54+
// Instantiates a client
55+
const featurestoreServiceClient = new FeaturestoreServiceClient(
56+
clientOptions
57+
);
58+
59+
async function batchCreateFeatures() {
60+
// Configure the parent resource
61+
const parent = `projects/${project}/locations/${location}/featurestores/${featurestoreId}/entityTypes/${entityTypeId}`;
62+
63+
const ageFeature = {
64+
valueType: 'INT64',
65+
description: 'User age',
66+
};
67+
68+
const ageFeatureRequest = {
69+
feature: ageFeature,
70+
featureId: 'age',
71+
};
72+
73+
const genderFeature = {
74+
valueType: 'STRING',
75+
description: 'User gender',
76+
};
77+
78+
const genderFeatureRequest = {
79+
feature: genderFeature,
80+
featureId: 'gender',
81+
};
82+
83+
const likedGenresFeature = {
84+
valueType: 'STRING_ARRAY',
85+
description: 'An array of genres that this user liked',
86+
};
87+
88+
const likedGenresFeatureRequest = {
89+
feature: likedGenresFeature,
90+
featureId: 'liked_genres',
91+
};
92+
93+
const requests = [
94+
ageFeatureRequest,
95+
genderFeatureRequest,
96+
likedGenresFeatureRequest,
97+
];
98+
99+
const request = {
100+
parent: parent,
101+
requests: requests,
102+
};
103+
104+
// Batch Create Features request
105+
const [operation] = await featurestoreServiceClient.batchCreateFeatures(
106+
request,
107+
{timeout: Number(timeout)}
108+
);
109+
const [response] = await operation.promise();
110+
111+
console.log('Batch create features response');
112+
console.log('Raw response:');
113+
console.log(JSON.stringify(response, null, 2));
114+
}
115+
batchCreateFeatures();
116+
// [END aiplatform_batch_create_features_sample]
117+
}
118+
119+
process.on('unhandledRejection', err => {
120+
console.error(err.message);
121+
process.exitCode = 1;
122+
});
123+
124+
main(...process.argv.slice(2));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/*
18+
* Creates a new Feature in a given EntityType.
19+
* See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running
20+
* the code snippet
21+
*/
22+
23+
'use strict';
24+
25+
async function main(
26+
project,
27+
featurestoreId,
28+
entityTypeId,
29+
featureId,
30+
valueType,
31+
description,
32+
location = 'us-central1',
33+
apiEndpoint = 'us-central1-aiplatform.googleapis.com',
34+
timeout = 300000
35+
) {
36+
// [START aiplatform_create_feature_sample]
37+
/**
38+
* TODO(developer): Uncomment these variables before running the sample.\
39+
* (Not necessary if passing values as arguments)
40+
*/
41+
42+
// const project = 'YOUR_PROJECT_ID';
43+
// const featurestoreId = 'YOUR_FEATURESTORE_ID';
44+
// const entityTypeId = 'YOUR_ENTITY_TYPE_ID';
45+
// const featureId = 'YOUR_FEATURE_ID';
46+
// const valueType = 'FEATURE_VALUE_DATA_TYPE';
47+
// const description = 'YOUR_ENTITY_TYPE_DESCRIPTION';
48+
// const location = 'YOUR_PROJECT_LOCATION';
49+
// const apiEndpoint = 'YOUR_API_ENDPOINT';
50+
// const timeout = <TIMEOUT_IN_MILLI_SECONDS>;
51+
52+
// Imports the Google Cloud Featurestore Service Client library
53+
const {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1;
54+
55+
// Specifies the location of the api endpoint
56+
const clientOptions = {
57+
apiEndpoint: apiEndpoint,
58+
};
59+
60+
// Instantiates a client
61+
const featurestoreServiceClient = new FeaturestoreServiceClient(
62+
clientOptions
63+
);
64+
65+
async function createFeature() {
66+
// Configure the parent resource
67+
const parent = `projects/${project}/locations/${location}/featurestores/${featurestoreId}/entityTypes/${entityTypeId}`;
68+
69+
const feature = {
70+
valueType: valueType,
71+
description: description,
72+
};
73+
74+
const request = {
75+
parent: parent,
76+
feature: feature,
77+
featureId: featureId,
78+
};
79+
80+
// Create Feature request
81+
const [operation] = await featurestoreServiceClient.createFeature(request, {
82+
timeout: Number(timeout),
83+
});
84+
const [response] = await operation.promise();
85+
86+
console.log('Create feature response');
87+
console.log(`Name : ${response.name}`);
88+
console.log('Raw response:');
89+
console.log(JSON.stringify(response, null, 2));
90+
}
91+
createFeature();
92+
// [END aiplatform_create_feature_sample]
93+
}
94+
95+
process.on('unhandledRejection', err => {
96+
console.error(err.message);
97+
process.exitCode = 1;
98+
});
99+
100+
main(...process.argv.slice(2));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/*
18+
* Deletes a single Feature.
19+
* See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running
20+
* the code snippet
21+
*/
22+
23+
'use strict';
24+
25+
async function main(
26+
project,
27+
featurestoreId,
28+
entityTypeId,
29+
featureId,
30+
location = 'us-central1',
31+
apiEndpoint = 'us-central1-aiplatform.googleapis.com',
32+
timeout = 300000
33+
) {
34+
// [START aiplatform_delete_feature_sample]
35+
/**
36+
* TODO(developer): Uncomment these variables before running the sample.\
37+
* (Not necessary if passing values as arguments)
38+
*/
39+
40+
// const project = 'YOUR_PROJECT_ID';
41+
// const featurestoreId = 'YOUR_FEATURESTORE_ID';
42+
// const entityTypeId = 'YOUR_ENTITY_TYPE_ID';
43+
// const featureId = 'YOUR_FEATURE_ID';
44+
// const location = 'YOUR_PROJECT_LOCATION';
45+
// const apiEndpoint = 'YOUR_API_ENDPOINT';
46+
// const timeout = <TIMEOUT_IN_MILLI_SECONDS>;
47+
48+
// Imports the Google Cloud Featurestore Service Client library
49+
const {FeaturestoreServiceClient} = require('@google-cloud/aiplatform').v1;
50+
51+
// Specifies the location of the api endpoint
52+
const clientOptions = {
53+
apiEndpoint: apiEndpoint,
54+
};
55+
56+
// Instantiates a client
57+
const featurestoreServiceClient = new FeaturestoreServiceClient(
58+
clientOptions
59+
);
60+
61+
async function deleteFeature() {
62+
// Configure the name resource
63+
const name = `projects/${project}/locations/${location}/featurestores/${featurestoreId}/entityTypes/${entityTypeId}/features/${featureId}`;
64+
65+
const request = {
66+
name: name,
67+
};
68+
69+
// Delete Feature request
70+
const [operation] = await featurestoreServiceClient.deleteFeature(request, {
71+
timeout: Number(timeout),
72+
});
73+
const [response] = await operation.promise();
74+
75+
console.log('Delete feature response');
76+
console.log('Raw response:');
77+
console.log(JSON.stringify(response, null, 2));
78+
}
79+
deleteFeature();
80+
// [END aiplatform_delete_feature_sample]
81+
}
82+
83+
process.on('unhandledRejection', err => {
84+
console.error(err.message);
85+
process.exitCode = 1;
86+
});
87+
88+
main(...process.argv.slice(2));

0 commit comments

Comments
 (0)