@@ -127,37 +127,40 @@ def rank_sample(
127127
128128def grounded_generation_inline_sample (
129129 project_id : str ,
130+ serving_config : str ,
130131) -> discoveryengine .GenerateGroundedContentResponse :
131132 # [START genappbuilder_grounded_generation_inline]
132133 from google .cloud import discoveryengine_v1 as discoveryengine
133134
134135 # TODO(developer): Uncomment these variables before running the sample.
135136 # project_id = "YOUR_PROJECT_ID"
137+ # The full resource name of the serving config for a Vertex AI Search App
138+ # serving_config = "projects/{project_id}/locations/global/collections/default_collection/engines/{engine_id}/servingConfigs/default_search"
136139
137140 client = discoveryengine .GroundedGenerationServiceClient ()
138141
139142 request = discoveryengine .GenerateGroundedContentRequest (
140143 # The full resource name of the location.
141144 # Format: projects/{project_id}/locations/{location}
142- location = client .common_location_path (project = project_id , location = "us " ),
145+ location = client .common_location_path (project = project_id , location = "global " ),
143146 generation_spec = discoveryengine .GenerateGroundedContentRequest .GenerationSpec (
144- model_id = "gemini-experimental " ,
147+ model_id = "gemini-1.5-flash " ,
145148 ),
146149 # Conversation between user and model
147150 contents = [
148151 discoveryengine .GroundedGenerationContent (
149152 role = "user" ,
150153 parts = [
151154 discoveryengine .GroundedGenerationContent .Part (
152- text = "Write a news article based on the sources. "
155+ text = "How did Google do in 2020? Where can I find BigQuery docs? "
153156 )
154157 ],
155158 )
156159 ],
157160 system_instruction = discoveryengine .GroundedGenerationContent (
158161 parts = [
159162 discoveryengine .GroundedGenerationContent .Part (
160- text = "Be comprehensive. Answer in HTML ."
163+ text = "Add a smiley emoji after the answer ."
161164 )
162165 ],
163166 ),
@@ -169,17 +172,19 @@ def grounded_generation_inline_sample(
169172 grounding_facts = [
170173 discoveryengine .GroundingFact (
171174 fact_text = (
172- "Titanic is a 1997 American epic romantic disaster movie. It was directed, written,"
173- " and co-produced by James Cameron. The movie is about the 1912 sinking of the"
174- " RMS Titanic. It stars Kate Winslet and Leonardo DiCaprio. The movie was released"
175- " on December 19, 1997. It received positive critical reviews. The movie won 11 Academy"
176- " Awards, and was nominated for fourteen total Academy Awards."
175+ "The BigQuery documentation can be found at https://cloud.google.com/bigquery/docs/introduction"
177176 ),
178- attributes = {"author" : "Simple Wikipedia" },
177+ attributes = {
178+ "title" : "BigQuery Overview" ,
179+ "uri" : "https://cloud.google.com/bigquery/docs/introduction" ,
180+ },
179181 ),
180182 ]
181183 ),
182184 ),
185+ discoveryengine .GenerateGroundedContentRequest .GroundingSource .SearchSource (
186+ serving_config = serving_config ,
187+ ),
183188 ]
184189 ),
185190 )
0 commit comments