Welcome to Portkey Forum

Updated 3 days ago

Handling PDF Data with Gemini

s
a
9 comments
you can send it the same way in image_url
Plain Text
                {
                    "type": "image_url",
                    "image_url": {
                        "url": "gs://cloud-samples-data/generative-ai/image/myDocument.pdf"
                    }
                }
What kind of documents are supported? I tried various kinds of docs but faced the below error:

Plain Text
openai.BadRequestError: Error code: 400 - {'error': {'message': 'google error: Invalid or unsupported file uri: gs://cloud-samples-data/generative-ai/image/myDocument.pdf', 'type': 'INVALID_ARGUMENT', 'param': None, 'code': 400}, 'provider': 'google'}


I also tried the same image url in the doc and got the same error.

Trace ID:
Plain Text
b95e8595-5de2-4f4a-b796-c687ce83616e
Attachment
image.png
My code:

Plain Text
from portkey_ai import Portkey
from dotenv import load_dotenv
import os

load_dotenv("/Users/abineshsivakumar/MightyBot/mightybot/python/agentcontroller/.env")

portkey = Portkey(
    api_key=os.getenv("PORTKEY_API_KEY"),
    base_url="https://api.portkey.ai/v1",
    config=os.getenv("PORTKEY_GOOGLE_CONFIG_ID"),
)

completion = portkey.chat.completions.create(
    messages=[
        {
            "role": "system",
            "content": "You are a helpful assistant"
        },
        {
            "role": "user",
            "content": [
                {
                    "type": "image_url",
                    "image_url": {
                        "url": "gs://cloud-samples-data/generative-ai/image/scones.jpg"
                    }
                },
                {
                    "type": "text",
                    "text": "What is the main idea of the document?"
                }
            ]
        }
    ],
    model='gemini-1.5-pro',
    max_tokens=8000
)
print(completion)
Plain Text
gs://cloud-samples-data/generative-ai/image/myDocument.pdf

is not a valid pdf, please replace it with a valid pdf link and try
example https://discovery.ucl.ac.uk/id/eprint/10089234/1/343019_3_art_0_py4t4l_convrt.pdf
I tried various pdfs, including this one that you sent. Still ended up with the same Invalid or unsupported file uri error.
Attachment
image.png
I hope the code is right.
try uploading one to your google cloud and use it with the gs:// format if public urls are not working for you
Add a reply
Sign up and join the conversation on Discord