Skip to content

Commit 1589fcd

Browse files
seanzhougooglecopybara-github
authored andcommitted
chore: Replace github HTTP URIs with GCS HTTP URIs in static non-text content sample agent
mainly because http://github.com/robots.txt disallows `/*/raw/` path. using GCS HTTP URIs is more reliable with Gemini model. PiperOrigin-RevId: 811409688
1 parent e7528ae commit 1589fcd

File tree

3 files changed

+45
-28
lines changed

3 files changed

+45
-28
lines changed

contributing/samples/static_non_text_content/README.md

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ This sample demonstrates ADK's static instruction feature with non-text content
99
- **Gemini Files API integration**: Demonstrates uploading documents and using file_data
1010
- **Mixed content types**: inline_data for images, file_data for documents
1111
- **API variant detection**: Different behavior for Gemini API vs Vertex AI
12-
- **GCS file references**: Additional GCS file support when using Vertex AI
12+
- **GCS file references**: Support for both GCS URI and HTTPS URL access methods in Vertex AI
1313

1414
## Static Instruction Content
1515

@@ -23,7 +23,7 @@ The agent includes:
2323

2424
**Vertex AI:**
2525
3. **Research paper**: Gemma research paper from Google Cloud Storage via GCS file reference
26-
4. **Contributing guide**: Gemini Cookbook contributing guide from GitHub via HTTPS file reference
26+
4. **AI research paper**: Same research paper accessed via HTTPS URL for comparison
2727

2828
## Content Used
2929

@@ -37,14 +37,14 @@ The agent includes:
3737
- Files are automatically cleaned up after 48 hours by the Gemini API
3838

3939
**Vertex AI:**
40-
- **Research Paper**: Gemma research paper (GCS file reference as `file_data`)
41-
- Public GCS URI: `gs://cloud-samples-data/generative-ai/pdf/2403.05530.pdf`
42-
- Demonstrates GCS file access in Vertex AI
43-
- PDF format with technical AI research content
44-
- **Contributing Guide**: Gemini Cookbook contributing guide (HTTPS file reference as `file_data`)
45-
- Public GitHub URL: `https://raw.githubusercontent.com/google-gemini/cookbook/main/CONTRIBUTING.md`
40+
- **Gemma Research Paper**: Research paper accessed via GCS URI (as `file_data`)
41+
- GCS URI: `gs://cloud-samples-data/generative-ai/pdf/2403.05530.pdf`
42+
- Demonstrates native GCS file access in Vertex AI
43+
- PDF format with technical AI research content about Gemini 1.5
44+
- **AI Research Paper**: Same research paper accessed via HTTPS URL (as `file_data`)
45+
- HTTPS URL: `https://storage.googleapis.com/cloud-samples-data/generative-ai/pdf/2403.05530.pdf`
4646
- Demonstrates HTTPS file access in Vertex AI
47-
- Markdown format with development guidelines
47+
- Agent can discover these are the same document and compare access methods
4848

4949
## Setup
5050

@@ -73,7 +73,9 @@ The agent will automatically load environment variables on startup.
7373
cd contributing/samples
7474
python -m static_non_text_content.main
7575
```
76-
This runs 4 test prompts that specifically demonstrate the static content features.
76+
This runs test prompts that demonstrate the static content features:
77+
- **Gemini Developer API**: 4 prompts testing inline_data + Files API upload
78+
- **Vertex AI**: 5 prompts testing inline_data + GCS/HTTPS file access comparison
7779

7880
### Interactive Mode
7981
```bash
@@ -101,13 +103,17 @@ The sample automatically runs test prompts when no `--prompt` is specified:
101103
**All API variants:**
102104
1. "What reference materials do you have access to?"
103105
2. "Can you describe the sample chart that was provided to you?"
104-
3. "What does the contributing guide document say about best practices?"
105-
4. "How do the inline image and file references in your instructions help you answer questions?"
106+
3. "How do the inline image and file references in your instructions help you answer questions?"
106107

107-
**Vertex AI only (additional prompt):**
108+
**Gemini Developer API only:**
109+
4. "What does the contributing guide document say about best practices?"
110+
111+
**Vertex AI only (additional prompts):**
108112
5. "What is the Gemma research paper about and what are its key contributions?"
113+
6. "Can you compare the research papers you have access to? Are they related or different?"
109114

110-
These prompts test `inline_data`, Files API `file_data` (Gemini API), and GCS/HTTPS `file_data` (Vertex AI).
115+
**Gemini Developer API** tests: `inline_data` (image) + Files API `file_data` (uploaded document)
116+
**Vertex AI** tests: `inline_data` (image) + GCS URI `file_data` + HTTPS URL `file_data` (same document via different access methods)
111117

112118
## How It Works
113119

contributing/samples/static_non_text_content/agent.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def create_static_instruction_with_file_upload():
7575
file_data_parts = []
7676

7777
if api_variant == GoogleLLMVariant.VERTEX_AI:
78-
print("Using Vertex AI - adding GCS and GitHub file references")
78+
print("Using Vertex AI - adding GCS URI and HTTPS URL references")
7979

8080
# Add GCS file reference
8181
file_data_parts.append(
@@ -90,20 +90,20 @@ def create_static_instruction_with_file_upload():
9090
)
9191
)
9292

93-
# Add GitHub public file reference
93+
# Add the same document via HTTPS URL to demonstrate both access methods
9494
file_data_parts.append(
9595
types.Part(
9696
file_data=types.FileData(
97-
file_uri="https://raw.githubusercontent.com/google-gemini/cookbook/main/CONTRIBUTING.md",
98-
mime_type="text/markdown",
99-
display_name="Gemini Cookbook Contributing Guide",
97+
file_uri="https://storage.googleapis.com/cloud-samples-data/generative-ai/pdf/2403.05530.pdf",
98+
mime_type="application/pdf",
99+
display_name="AI Research Paper (HTTPS)",
100100
)
101101
)
102102
)
103103

104104
additional_text = (
105-
" You also have access to the Gemma research paper from Google Cloud"
106-
" Storage and the Gemini Cookbook contributing guide from GitHub."
105+
" You also have access to a Gemma research paper from GCS"
106+
" and an AI research paper from HTTPS URL."
107107
)
108108

109109
else:
@@ -187,8 +187,8 @@ def create_static_instruction_with_file_upload():
187187
instruction_text = """
188188
When users ask questions, you should:
189189
1. Use the reference chart above to provide context when discussing visual data or charts
190-
2. Reference the Gemma research paper when discussing AI research, model architectures, or technical details
191-
3. Reference the Gemini Cookbook contributing guide when explaining best practices and guidelines
190+
2. Reference the Gemma research paper (from GCS) when discussing AI research, model architectures, or technical details
191+
3. Reference the AI research paper (from HTTPS) when discussing research topics
192192
4. Be helpful and informative in your responses
193193
5. Explain how the provided reference materials relate to their questions"""
194194
else:

contributing/samples/static_non_text_content/main.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,22 +115,33 @@ async def run_default_test_prompts(runner):
115115
app_name=APP_NAME, user_id=USER_ID
116116
)
117117

118-
# Test prompts that specifically exercise the static content features
118+
# Common test prompts for all API variants
119119
test_prompts = [
120120
"What reference materials do you have access to?",
121121
"Can you describe the sample chart that was provided to you?",
122-
"What does the contributing guide document say about best practices?",
123122
(
124123
"How do the inline image and file references in your instructions "
125124
"help you answer questions?"
126125
),
127126
]
128127

129-
# Add Vertex AI specific prompt to test GCS file reference
128+
# Add API-specific prompts
130129
if api_variant == GoogleLLMVariant.VERTEX_AI:
130+
# Vertex AI has research papers instead of contributing guide
131+
test_prompts.extend([
132+
(
133+
"What is the Gemma research paper about and what are its key "
134+
"contributions?"
135+
),
136+
(
137+
"Can you compare the research papers you have access to? Are they "
138+
"related or different?"
139+
),
140+
])
141+
else:
142+
# Gemini Developer API has contributing guide document
131143
test_prompts.append(
132-
"What is the Gemma research paper about and what are its key "
133-
"contributions?"
144+
"What does the contributing guide document say about best practices?"
134145
)
135146

136147
for i, prompt in enumerate(test_prompts, 1):

0 commit comments

Comments
 (0)