Skip to content

Commit 4bf9816

Browse files
vertex-sdk-botcopybara-github
authored andcommitted
docs: GenAI - Grounding - Added sample for grounding with Google Search to the Vertex GenAI SDK README.
PiperOrigin-RevId: 697048102
1 parent ca61c5a commit 4bf9816

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

vertexai/generative_models/README.md

+24
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,30 @@ chat = model.start_chat(responder=afc_responder)
183183
print(chat.send_message("What is the weather like in Boston?"))
184184
```
185185

186+
### Grounding with Google Search
187+
188+
```
189+
from vertexai import generative_models
190+
from vertexai.generative_models import GenerativeModel, Tool
191+
192+
model=GenerativeModel(
193+
"gemini-pro",
194+
tools=[Tool.from_google_search_retrieval(
195+
google_search_retrieval=generative_models.grounding.GoogleSearchRetrieval(
196+
dynamic_retrieval_config=generative_models.grounding.DynamicRetrievalConfig(
197+
mode=generative_models.grounding.DynamicRetrievalConfig.Mode.MODE_DYNAMIC)))
198+
],
199+
)
200+
201+
response = gnd_model.generate_content("Who win Euro 2024")
202+
203+
print(response.text)
204+
205+
# Checking grounding metadata. It contains grounding supports and the follow-up search entry widget.
206+
if response.candidates:
207+
print(response.candidates[0].grounding_metadata)
208+
```
209+
186210
## Documentation
187211

188212
You can find complete documentation for the Vertex AI SDKs and the Gemini model in the Google Cloud [documentation](https://cloud.google.com/vertex-ai/docs/generative-ai/learn/overview)

0 commit comments

Comments
 (0)