File tree Expand file tree Collapse file tree 2 files changed +18
-17
lines changed Expand file tree Collapse file tree 2 files changed +18
-17
lines changed Original file line number Diff line number Diff line change 17
17
import textgen_async_with_txt
18
18
import textgen_chat_stream_with_txt
19
19
import textgen_chat_with_txt
20
- import textgen_code_with_pdf
21
20
import textgen_config_with_txt
22
21
import textgen_sys_instr_with_txt
23
22
import textgen_transcript_with_gcs_audio
26
25
import textgen_with_multi_img
27
26
import textgen_with_multi_local_img
28
27
import textgen_with_mute_video
28
+ import textgen_with_pdf
29
29
import textgen_with_txt
30
30
import textgen_with_txt_img
31
31
import textgen_with_txt_stream
@@ -69,6 +69,11 @@ def test_textgen_sys_instr_with_txt() -> None:
69
69
assert response
70
70
71
71
72
+ def test_textgen_with_pdf () -> None :
73
+ response = textgen_with_pdf .generate_content ()
74
+ assert response
75
+
76
+
72
77
def test_textgen_with_txt_img () -> None :
73
78
response = textgen_with_txt_img .generate_content ()
74
79
assert response
@@ -120,8 +125,3 @@ def test_textgen_with_local_video() -> None:
120
125
def test_textgen_with_youtube_video () -> None :
121
126
response = textgen_with_youtube_video .generate_content ()
122
127
assert response
123
-
124
-
125
- def test_textgen_code_with_pdf () -> None :
126
- response = textgen_code_with_pdf .generate_content ()
127
- assert response
Original file line number Diff line number Diff line change 16
16
17
17
18
18
def generate_content () -> str :
19
- # [START googlegenaisdk_textgen_code_with_pdf ]
19
+ # [START googlegenaisdk_textgen_with_pdf ]
20
20
from google import genai
21
21
from google .genai .types import HttpOptions , Part
22
22
23
23
client = genai .Client (http_options = HttpOptions (api_version = "v1" ))
24
24
model_id = "gemini-2.0-flash-001"
25
25
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" ,
28
32
mime_type = "application/pdf" ,
29
33
)
30
34
31
35
response = client .models .generate_content (
32
36
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 ],
37
38
)
38
39
39
40
print (response .text )
40
41
# 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 ]
45
46
return response .text
46
47
47
48
You can’t perform that action at this time.
0 commit comments