Skip to content

Commit 6fd262a

Browse files
authored
feat(genai): Update Text Generation with PDF Sample (#13160)
* feat(genai): Update Text Generation with PDF Sample - Changed to a basic Doc Summarization example instead of reading code from PDF. * Linting/Comments
1 parent bf826f5 commit 6fd262a

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

genai/text_generation/test_text_generation.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import textgen_async_with_txt
1818
import textgen_chat_stream_with_txt
1919
import textgen_chat_with_txt
20-
import textgen_code_with_pdf
2120
import textgen_config_with_txt
2221
import textgen_sys_instr_with_txt
2322
import textgen_transcript_with_gcs_audio
@@ -26,6 +25,7 @@
2625
import textgen_with_multi_img
2726
import textgen_with_multi_local_img
2827
import textgen_with_mute_video
28+
import textgen_with_pdf
2929
import textgen_with_txt
3030
import textgen_with_txt_img
3131
import textgen_with_txt_stream
@@ -69,6 +69,11 @@ def test_textgen_sys_instr_with_txt() -> None:
6969
assert response
7070

7171

72+
def test_textgen_with_pdf() -> None:
73+
response = textgen_with_pdf.generate_content()
74+
assert response
75+
76+
7277
def test_textgen_with_txt_img() -> None:
7378
response = textgen_with_txt_img.generate_content()
7479
assert response
@@ -120,8 +125,3 @@ def test_textgen_with_local_video() -> None:
120125
def test_textgen_with_youtube_video() -> None:
121126
response = textgen_with_youtube_video.generate_content()
122127
assert response
123-
124-
125-
def test_textgen_code_with_pdf() -> None:
126-
response = textgen_code_with_pdf.generate_content()
127-
assert response

genai/text_generation/textgen_code_with_pdf.py renamed to genai/text_generation/textgen_with_pdf.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,33 @@
1616

1717

1818
def generate_content() -> str:
19-
# [START googlegenaisdk_textgen_code_with_pdf]
19+
# [START googlegenaisdk_textgen_with_pdf]
2020
from google import genai
2121
from google.genai.types import HttpOptions, Part
2222

2323
client = genai.Client(http_options=HttpOptions(api_version="v1"))
2424
model_id = "gemini-2.0-flash-001"
2525

26-
python_code = Part.from_uri(
27-
file_uri="https://storage.googleapis.com/cloud-samples-data/generative-ai/text/inefficient_fibonacci_series_python_code.pdf",
26+
prompt = """
27+
You are a highly skilled document summarization specialist. Your task is to provide a concise executive summary of no more than 300 words. Please summarize the given document for a general audience.
28+
"""
29+
30+
pdf_file = Part.from_uri(
31+
file_uri="gs://cloud-samples-data/generative-ai/pdf/2403.05530.pdf",
2832
mime_type="application/pdf",
2933
)
3034

3135
response = client.models.generate_content(
3236
model=model_id,
33-
contents=[
34-
python_code,
35-
"Convert this python code to use Google Python Style Guide.",
36-
],
37+
contents=[pdf_file, prompt],
3738
)
3839

3940
print(response.text)
4041
# Example response:
41-
# ```python
42-
# def fibonacci(n: int) -> list[int] | str:
43-
# ...
44-
# [END googlegenaisdk_textgen_code_with_pdf]
42+
# Here's a summary of the Google DeepMind Gemini 1.5 report:
43+
#
44+
# This report introduces Gemini 1.5 Pro...
45+
# [END googlegenaisdk_textgen_with_pdf]
4546
return response.text
4647

4748

0 commit comments

Comments
 (0)