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

Lines changed: 24 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy