I am using `models/gemini-1.5-pro-latest`
I'm trying to do a multimodal prompt with string and PDF. This is a snippet of my code:
import google.generativeai as genai
model = genai.GenerativeModel(model_name='models/gemini-1.5-pro-latest',
generation_config=generation_config,
safety_settings=safety_settings)
with open("document.pdf", "rb") as pdf:
pdf = pdf.read()
prompt_parts = [ context_text , pdf ]
response = model.generate_content(prompt_parts)
Assume all my configs etc are correct, the example was working fine for only the `context_text`
The error I get is:
---> response = model.generate_content(prompt_parts)
...
/usr/local/lib/python3.10/dist-packages/google/generativeai/types/content_types.py in to_blob(blob)
...
TypeError: Could not create `Blob`, expected `Blob`, `dict` or an `Image` type(`PIL.Image.Image` or `IPython.display.Image`).
Got a: <class 'bytes'>
...
Solved! Go to Solution.
I believe you need to wrap your PDF into a `Part` object.
Something like the following:
import google.generativeai as genai
from vertexai.generative_models import Part
model = genai.GenerativeModel(model_name='models/gemini-1.5-pro-latest',
generation_config=generation_config,
safety_settings=safety_settings)
# NEW SECTION, LOAD INTO PART OBJECT
pdf_file_uri = "gs://path/to/your/document.pdf"
pdf = Part.from_uri(pdf_file_uri, mime_type="application/pdf")
###
prompt_parts = [ context_text , pdf ]
response = model.generate_content(prompt_parts)
User | Count |
---|---|
2 | |
2 | |
1 | |
1 | |
1 |