Skip to content

Commit 8331075

Browse files
committed
docs(samples): Add Sample for Gen App Builder - Search
- Added .DS_Store to .gitignore (Macos file) - Adds Introduction Sample for Generative AI App Builder (Gen App Builder) - NOTE: Test project needs the Discovery Engine API to be enabled (possibly allowlisted for Gen AI) - Test project also needs a search engine to be created. - Generative AI App Builder uses the Discovery Engine API, but has its own region tag `genappbuilder`
1 parent 548508b commit 8331075

10 files changed

+233
-0
lines changed

.github/auto-label.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ path:
3737
datastore: "datastore"
3838
dialogflow: "dialogflow"
3939
dialogflow-cx: "dialogflow"
40+
discoveryengine: "discoveryengine"
4041
dlp: "dlp"
4142
document-ai: "documentai"
4243
endpoints: "endpoints"
+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Copyright 2023 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: discoveryengine
16+
on:
17+
push:
18+
branches:
19+
- main
20+
paths:
21+
- 'discoveryengine/**'
22+
- '.github/workflows/discoveryengine.yaml'
23+
pull_request:
24+
paths:
25+
- 'discoveryengine/**'
26+
- '.github/workflows/discoveryengine.yaml'
27+
pull_request_target:
28+
types: [labeled]
29+
paths:
30+
- 'discoveryengine/**'
31+
- '.github/workflows/discoveryengine.yaml'
32+
schedule:
33+
- cron: '0 0 * * 0'
34+
jobs:
35+
test:
36+
if: github.event.action != 'labeled' || github.event.label.name == 'actions:force-run'
37+
uses: ./.github/workflows/test.yaml
38+
with:
39+
name: 'discoveryengine'
40+
path: 'discoveryengine'
41+
remove_label:
42+
if: |
43+
github.event.action == 'labeled' &&
44+
github.event.label.name == 'actions:force-run' &&
45+
always()
46+
uses: ./.github/workflows/remove-label.yaml
47+
flakybot:
48+
if: github.event_name == 'schedule' && always() # always() submits logs even if tests fail
49+
uses: ./.github/workflows/flakybot.yaml
50+
needs: [test]

.github/workflows/utils/workflows.json

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"dataproc",
3737
"datastore/functions",
3838
"dialogflow",
39+
"discoveryengine",
3940
"dlp",
4041
"document-ai",
4142
"endpoints/getting-started",

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ logs/
1111
yarn.lock
1212
package-lock.json
1313
.envrc
14+
15+
.DS_Store

CODEOWNERS

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ contact-center-insights @GoogleCloudPlatform/dee-data-ai @GoogleCloudPlatform/no
6363
datalabeling @GoogleCloudPlatform/dee-data-ai @GoogleCloudPlatform/nodejs-samples-reviewers
6464
dialogflow @GoogleCloudPlatform/dee-data-ai @GoogleCloudPlatform/nodejs-samples-reviewers
6565
dialogflow-cx @GoogleCloudPlatform/dee-data-ai @GoogleCloudPlatform/nodejs-samples-reviewers
66+
discoveryengine @GoogleCloudPlatform/dee-data-ai @GoogleCloudPlatform/nodejs-samples-reviewers
6667
document-ai @GoogleCloudPlatform/dee-data-ai @GoogleCloudPlatform/nodejs-samples-reviewers
6768
mediatranslation @GoogleCloudPlatform/dee-data-ai @GoogleCloudPlatform/nodejs-samples-reviewers
6869
notebooks @GoogleCloudPlatform/dee-data-ai @GoogleCloudPlatform/nodejs-samples-reviewers

discoveryengine/.eslintrc.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright 2023 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
---
16+
rules:
17+
no-console: off
18+
node/no-unsupported-features/node-builtins: off

discoveryengine/package.json

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "nodejs-genappbuilder-samples",
3+
"private": true,
4+
"license": "Apache-2.0",
5+
"author": "Google LLC",
6+
"engines": {
7+
"node": ">=12.0.0"
8+
},
9+
"files": [
10+
"*.js"
11+
],
12+
"scripts": {
13+
"test": "mocha test/*.js --timeout 600000"
14+
},
15+
"dependencies": {
16+
"@google-cloud/discoveryengine": "^0.5.0",
17+
"p-queue": "^6.6.2"
18+
},
19+
"devDependencies": {
20+
"chai": "^4.2.0",
21+
"mocha": "^10.0.0",
22+
"uuid": "^9.0.0"
23+
}
24+
}

discoveryengine/search.js

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
* Copyright 2023 Google LLC
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
'use strict';
17+
18+
async function main(
19+
projectId,
20+
location,
21+
searchEngineId,
22+
servingConfigId,
23+
searchQuery
24+
) {
25+
// [START genappbuilder_search]
26+
/**
27+
* TODO(developer): Uncomment these variables before running the sample.
28+
*/
29+
// const projectId = 'YOUR_PROJECT_ID';
30+
// const location = 'YOUR_LOCATION'; // Options: 'global'
31+
// const searchEngineId = 'YOUR_SEARCH_ENGINE_ID' // Create in Cloud Console
32+
// const servingConfigId = 'default_config'; // Options: 'default_config'
33+
// const searchQuery = 'Google';
34+
35+
const {SearchServiceClient} = require('@google-cloud/discoveryengine').v1beta;
36+
37+
// Instantiates a client
38+
const client = new SearchServiceClient();
39+
40+
async function search() {
41+
// The full resource name of the search engine serving configuration.
42+
// Example: projects/{projectId}/locations/{location}/dataStores/{searchEngineId}/servingConfigs/{servingConfigId}
43+
// You must create a search engine in the Cloud Console first.
44+
const name = client.projectLocationDataStoreServingConfigPath(
45+
projectId,
46+
location,
47+
searchEngineId,
48+
servingConfigId
49+
);
50+
51+
const request = {
52+
name,
53+
query: searchQuery,
54+
};
55+
56+
// Perform search request
57+
const response = await client.search(request);
58+
59+
for (const result of response) {
60+
console.log(result);
61+
}
62+
}
63+
// [END genappbuilder_search]
64+
await search();
65+
}
66+
67+
main(...process.argv.slice(2)).catch(err => {
68+
console.error(err);
69+
process.exitCode = 1;
70+
});

discoveryengine/test/.eslintrc.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright 2023 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
---
16+
env:
17+
mocha: true
18+
rules:
19+
node/no-extraneous-require: off

discoveryengine/test/search.test.js

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* Copyright 2023 Google LLC
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
'use strict';
17+
18+
const path = require('path');
19+
const assert = require('assert');
20+
const cp = require('child_process');
21+
22+
const {SearchServiceClient} = require('@google-cloud/discoveryengine').v1beta;
23+
const client = new SearchServiceClient();
24+
25+
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
26+
27+
const cwd = path.join(__dirname, '..');
28+
const LOCATION = 'global';
29+
const SEARCH_ENGINE_ID = '';
30+
const SERVING_CONFIG_ID = 'default_config';
31+
const SEARCH_QUERY = 'Google';
32+
33+
describe('Search', () => {
34+
let projectId;
35+
before(async () => {
36+
projectId = await client.getProjectId();
37+
});
38+
it('should run genappbuilder search (v1beta)', async () => {
39+
const stdout = execSync(
40+
`node ./search.js ${projectId} ${LOCATION} ${SEARCH_ENGINE_ID} ${SERVING_CONFIG_ID} ${SEARCH_QUERY}`,
41+
{
42+
cwd,
43+
}
44+
);
45+
assert.match(stdout.toString(), /Google/);
46+
});
47+
});

0 commit comments

Comments
 (0)