Repository navigation
Expand file tree
/
Copy pathtest_grounding.py
More file actions
47 lines (41 loc) · 1.47 KB
/
Copy pathtest_grounding.py
File metadata and controls
47 lines (41 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import os
from google import genai
from google.genai import types
def run_test():
client = genai.Client()
model = "gemini-3-flash-preview"
contents = [
types.Content(
role="user",
parts=[
types.Part.from_text(text="What is the weather in VIT Vellore today?"),
],
),
]
tools = [
types.Tool(googleSearch=types.GoogleSearch()),
]
config = types.GenerateContentConfig(
thinking_config=types.ThinkingConfig(thinking_level="HIGH"),
tools=tools,
)
response = client.models.generate_content(
model=model,
contents=contents,
config=config,
)
print("Response text:", response.text)
print("\nCandidates type:", type(response.candidates))
if hasattr(response, 'candidates') and response.candidates:
candidate = response.candidates[0]
if hasattr(candidate, 'grounding_metadata') and candidate.grounding_metadata:
meta = candidate.grounding_metadata
print("\nGrounding metadata type:", type(meta))
if hasattr(meta, 'grounding_chunks') and meta.grounding_chunks:
for chunk in meta.grounding_chunks:
print("Chunk:", chunk)
if hasattr(chunk, 'web') and chunk.web:
print(f" Web Title: {chunk.web.title}")
print(f" Web URI: {chunk.web.uri}")
if __name__ == "__main__":
run_test()