Skip to content

Commit 7adfc70

Browse files
committed
Change search sample to have tuned model as optional parameter
1 parent b11e852 commit 7adfc70

File tree

1 file changed

+4
-53
lines changed

1 file changed

+4
-53
lines changed

discoveryengine/search_sample.py

Lines changed: 4 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ def search_sample(
8484
spell_correction_spec=discoveryengine.SearchRequest.SpellCorrectionSpec(
8585
mode=discoveryengine.SearchRequest.SpellCorrectionSpec.Mode.AUTO
8686
),
87+
# Optional: Use fine-tuned model for this request
88+
# custom_fine_tuning_spec=discoveryengine.CustomFineTuningSpec(
89+
# enable_search_adaptor=True
90+
# ),
8791
)
8892

8993
response = client.search(request)
@@ -93,56 +97,3 @@ def search_sample(
9397

9498

9599
# [END genappbuilder_search]
96-
97-
# [START genappbuilder_search_tuned_model]
98-
99-
from google.api_core.client_options import ClientOptions
100-
from google.cloud import discoveryengine_v1alpha as discoveryengine
101-
102-
# TODO(developer): Uncomment these variables before running the sample.
103-
# project_id = "YOUR_PROJECT_ID"
104-
# location = "YOUR_LOCATION" # Values: "global", "us", "eu"
105-
# engine_id = "YOUR_APP_ID"
106-
# search_query = "YOUR_SEARCH_QUERY"
107-
108-
109-
def search_tuned_model_sample(
110-
project_id: str,
111-
location: str,
112-
engine_id: str,
113-
search_query: str,
114-
) -> discoveryengine.services.search_service.pagers.SearchPager:
115-
# For more information, refer to:
116-
# https://cloud.google.com/generative-ai-app-builder/docs/locations#specify_a_multi-region_for_your_data_store
117-
client_options = (
118-
ClientOptions(api_endpoint=f"{location}-discoveryengine.googleapis.com")
119-
if location != "global"
120-
else None
121-
)
122-
123-
# Create a client
124-
client = discoveryengine.SearchServiceClient(client_options=client_options)
125-
126-
# The full resource name of the search app serving config
127-
serving_config = f"projects/{project_id}/locations/{location}/collections/default_collection/engines/{engine_id}/servingConfigs/default_config"
128-
129-
# Refer to the `SearchRequest` reference for all supported fields:
130-
# https://cloud.google.com/python/docs/reference/discoveryengine/latest/google.cloud.discoveryengine_v1.types.SearchRequest
131-
request = discoveryengine.SearchRequest(
132-
serving_config=serving_config,
133-
query=search_query,
134-
custom_fine_tuning_spec=discoveryengine.CustomFineTuningSpec(
135-
enable_search_adaptor=True
136-
),
137-
)
138-
139-
page_result = client.search(request)
140-
141-
# Handle the response
142-
for response in page_result:
143-
print(response)
144-
145-
return page_result
146-
147-
148-
# [END genappbuilder_search_tuned_model]

0 commit comments

Comments
 (0)