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 1717import textgen_async_with_txt
1818import textgen_chat_stream_with_txt
1919import textgen_chat_with_txt
20- import textgen_code_with_pdf
2120import textgen_config_with_txt
2221import textgen_sys_instr_with_txt
2322import textgen_transcript_with_gcs_audio
2625import textgen_with_multi_img
2726import textgen_with_multi_local_img
2827import textgen_with_mute_video
28+ import textgen_with_pdf
2929import textgen_with_txt
3030import textgen_with_txt_img
3131import 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+
7277def 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:
120125def 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
Original file line number Diff line number Diff line change 1616
1717
1818def 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
You can’t perform that action at this time.
0 commit comments