|
1 |
| -# Copyright 2024 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 |
| - |
17 |
| -def create_target_site( |
18 |
| - project_id: str, |
19 |
| - location: str, |
20 |
| - data_store_id: str, |
21 |
| - uri_pattern: str, |
22 |
| -): |
23 |
| - # [START genappbuilder_create_target_site] |
24 |
| - from google.api_core.client_options import ClientOptions |
25 |
| - |
26 |
| - from google.cloud import discoveryengine_v1 as discoveryengine |
27 |
| - |
28 |
| - # TODO(developer): Uncomment these variables before running the sample. |
29 |
| - # project_id = "YOUR_PROJECT_ID" |
30 |
| - # location = "YOUR_LOCATION" # Values: "global" |
31 |
| - # data_store_id = "YOUR_DATA_STORE_ID" |
32 |
| - # NOTE: Do not include http or https protocol in the URI pattern |
33 |
| - # uri_pattern = "cloud.google.com/generative-ai-app-builder/docs/*" |
34 |
| - |
35 |
| - # For more information, refer to: |
36 |
| - # https://cloud.google.com/generative-ai-app-builder/docs/locations#specify_a_multi-region_for_your_data_store |
37 |
| - client_options = ( |
38 |
| - ClientOptions(api_endpoint=f"{location}-discoveryengine.googleapis.com") |
39 |
| - if location != "global" |
40 |
| - else None |
41 |
| - ) |
42 |
| - |
43 |
| - # Create a client |
44 |
| - client = discoveryengine.SiteSearchEngineServiceClient( |
45 |
| - client_options=client_options |
46 |
| - ) |
47 |
| - |
48 |
| - # The full resource name of the data store |
49 |
| - # e.g. projects/{project}/locations/{location}/dataStores/{data_store_id} |
50 |
| - site_search_engine = client.site_search_engine_path( |
51 |
| - project=project_id, location=location, data_store=data_store_id |
52 |
| - ) |
53 |
| - |
54 |
| - # Target Site to index |
55 |
| - target_site = discoveryengine.TargetSite( |
56 |
| - provided_uri_pattern=uri_pattern, |
57 |
| - # Options: INCLUDE, EXCLUDE |
58 |
| - type_=discoveryengine.TargetSite.Type.INCLUDE, |
59 |
| - exact_match=False, |
60 |
| - ) |
61 |
| - |
62 |
| - # Make the request |
63 |
| - operation = client.create_target_site( |
64 |
| - parent=site_search_engine, |
65 |
| - target_site=target_site, |
66 |
| - ) |
67 |
| - |
68 |
| - print(f"Waiting for operation to complete: {operation.operation.name}") |
69 |
| - response = operation.result() |
70 |
| - |
71 |
| - # After the operation is complete, |
72 |
| - # get information from operation metadata |
73 |
| - metadata = discoveryengine.CreateTargetSiteMetadata(operation.metadata) |
74 |
| - |
75 |
| - # Handle the response |
76 |
| - print(response) |
77 |
| - print(metadata) |
78 |
| - # [END genappbuilder_create_target_site] |
79 |
| - |
80 |
| - return response |
81 |
| - |
82 |
| - |
83 |
| -def delete_target_site( |
84 |
| - project_id: str, |
85 |
| - location: str, |
86 |
| - data_store_id: str, |
87 |
| - target_site_id: str, |
88 |
| -): |
89 |
| - # [START genappbuilder_delete_target_site] |
90 |
| - from google.api_core.client_options import ClientOptions |
91 |
| - |
92 |
| - from google.cloud import discoveryengine_v1 as discoveryengine |
93 |
| - |
94 |
| - # TODO(developer): Uncomment these variables before running the sample. |
95 |
| - # project_id = "YOUR_PROJECT_ID" |
96 |
| - # location = "YOUR_LOCATION" # Values: "global" |
97 |
| - # data_store_id = "YOUR_DATA_STORE_ID" |
98 |
| - # target_site_id = "YOUR_TARGET_SITE_ID" |
99 |
| - |
100 |
| - # For more information, refer to: |
101 |
| - # https://cloud.google.com/generative-ai-app-builder/docs/locations#specify_a_multi-region_for_your_data_store |
102 |
| - client_options = ( |
103 |
| - ClientOptions(api_endpoint=f"{location}-discoveryengine.googleapis.com") |
104 |
| - if location != "global" |
105 |
| - else None |
106 |
| - ) |
107 |
| - |
108 |
| - # Create a client |
109 |
| - client = discoveryengine.SiteSearchEngineServiceClient( |
110 |
| - client_options=client_options |
111 |
| - ) |
112 |
| - |
113 |
| - # The full resource name of the data store |
114 |
| - # e.g. projects/{project}/locations/{location}/collections/{collection}/dataStores/{data_store_id}/siteSearchEngine/targetSites/{target_site} |
115 |
| - name = client.target_site_path( |
116 |
| - project=project_id, |
117 |
| - location=location, |
118 |
| - data_store=data_store_id, |
119 |
| - target_site=target_site_id, |
120 |
| - ) |
121 |
| - |
122 |
| - # Make the request |
123 |
| - operation = client.delete_target_site(name=name) |
124 |
| - |
125 |
| - print(f"Operation: {operation.operation.name}") |
126 |
| - # [END genappbuilder_delete_target_site] |
127 |
| - |
128 |
| - return operation.operation.name |
| 1 | +# # Copyright 2024 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 | +# |
| 17 | +# def create_target_site( |
| 18 | +# project_id: str, |
| 19 | +# location: str, |
| 20 | +# data_store_id: str, |
| 21 | +# uri_pattern: str, |
| 22 | +# ): |
| 23 | +# # [START genappbuilder_create_target_site] |
| 24 | +# from google.api_core.client_options import ClientOptions |
| 25 | +# |
| 26 | +# from google.cloud import discoveryengine_v1 as discoveryengine |
| 27 | +# |
| 28 | +# # TODO(developer): Uncomment these variables before running the sample. |
| 29 | +# # project_id = "YOUR_PROJECT_ID" |
| 30 | +# # location = "YOUR_LOCATION" # Values: "global" |
| 31 | +# # data_store_id = "YOUR_DATA_STORE_ID" |
| 32 | +# # NOTE: Do not include http or https protocol in the URI pattern |
| 33 | +# # uri_pattern = "cloud.google.com/generative-ai-app-builder/docs/*" |
| 34 | +# |
| 35 | +# # For more information, refer to: |
| 36 | +# # https://cloud.google.com/generative-ai-app-builder/docs/locations#specify_a_multi-region_for_your_data_store |
| 37 | +# client_options = ( |
| 38 | +# ClientOptions(api_endpoint=f"{location}-discoveryengine.googleapis.com") |
| 39 | +# if location != "global" |
| 40 | +# else None |
| 41 | +# ) |
| 42 | +# |
| 43 | +# # Create a client |
| 44 | +# client = discoveryengine.SiteSearchEngineServiceClient( |
| 45 | +# client_options=client_options |
| 46 | +# ) |
| 47 | +# |
| 48 | +# # The full resource name of the data store |
| 49 | +# # e.g. projects/{project}/locations/{location}/dataStores/{data_store_id} |
| 50 | +# site_search_engine = client.site_search_engine_path( |
| 51 | +# project=project_id, location=location, data_store=data_store_id |
| 52 | +# ) |
| 53 | +# |
| 54 | +# # Target Site to index |
| 55 | +# target_site = discoveryengine.TargetSite( |
| 56 | +# provided_uri_pattern=uri_pattern, |
| 57 | +# # Options: INCLUDE, EXCLUDE |
| 58 | +# type_=discoveryengine.TargetSite.Type.INCLUDE, |
| 59 | +# exact_match=False, |
| 60 | +# ) |
| 61 | +# |
| 62 | +# # Make the request |
| 63 | +# operation = client.create_target_site( |
| 64 | +# parent=site_search_engine, |
| 65 | +# target_site=target_site, |
| 66 | +# ) |
| 67 | +# |
| 68 | +# print(f"Waiting for operation to complete: {operation.operation.name}") |
| 69 | +# response = operation.result() |
| 70 | +# |
| 71 | +# # After the operation is complete, |
| 72 | +# # get information from operation metadata |
| 73 | +# metadata = discoveryengine.CreateTargetSiteMetadata(operation.metadata) |
| 74 | +# |
| 75 | +# # Handle the response |
| 76 | +# print(response) |
| 77 | +# print(metadata) |
| 78 | +# # [END genappbuilder_create_target_site] |
| 79 | +# |
| 80 | +# return response |
| 81 | +# |
| 82 | +# |
| 83 | +# def delete_target_site( |
| 84 | +# project_id: str, |
| 85 | +# location: str, |
| 86 | +# data_store_id: str, |
| 87 | +# target_site_id: str, |
| 88 | +# ): |
| 89 | +# # [START genappbuilder_delete_target_site] |
| 90 | +# from google.api_core.client_options import ClientOptions |
| 91 | +# |
| 92 | +# from google.cloud import discoveryengine_v1 as discoveryengine |
| 93 | +# |
| 94 | +# # TODO(developer): Uncomment these variables before running the sample. |
| 95 | +# # project_id = "YOUR_PROJECT_ID" |
| 96 | +# # location = "YOUR_LOCATION" # Values: "global" |
| 97 | +# # data_store_id = "YOUR_DATA_STORE_ID" |
| 98 | +# # target_site_id = "YOUR_TARGET_SITE_ID" |
| 99 | +# |
| 100 | +# # For more information, refer to: |
| 101 | +# # https://cloud.google.com/generative-ai-app-builder/docs/locations#specify_a_multi-region_for_your_data_store |
| 102 | +# client_options = ( |
| 103 | +# ClientOptions(api_endpoint=f"{location}-discoveryengine.googleapis.com") |
| 104 | +# if location != "global" |
| 105 | +# else None |
| 106 | +# ) |
| 107 | +# |
| 108 | +# # Create a client |
| 109 | +# client = discoveryengine.SiteSearchEngineServiceClient( |
| 110 | +# client_options=client_options |
| 111 | +# ) |
| 112 | +# |
| 113 | +# # The full resource name of the data store |
| 114 | +# # e.g. projects/{project}/locations/{location}/collections/{collection}/dataStores/{data_store_id}/siteSearchEngine/targetSites/{target_site} |
| 115 | +# name = client.target_site_path( |
| 116 | +# project=project_id, |
| 117 | +# location=location, |
| 118 | +# data_store=data_store_id, |
| 119 | +# target_site=target_site_id, |
| 120 | +# ) |
| 121 | +# |
| 122 | +# # Make the request |
| 123 | +# operation = client.delete_target_site(name=name) |
| 124 | +# |
| 125 | +# print(f"Operation: {operation.operation.name}") |
| 126 | +# # [END genappbuilder_delete_target_site] |
| 127 | +# |
| 128 | +# return operation.operation.name |
0 commit comments