Welcome to Portkey Forum

Updated 3 days ago

Is There a Way to Pass Pdf Files to Vertex Ai Without Uploading to Google Storage?

is there a way to pass pdf files to vertexai without uploading to google storage? Their sdk supports it, was wondering how to do it with portkey
https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/inference
s
H
4 comments
the restriction is from vertex itself, can you confirm if you're actually able to use a public document with the sdk without uploading it to google storage?
Plain Text
from google import genai
from google.genai import types
import pathlib
import httpx

client = genai.Client()

doc_url = "https://discovery.ucl.ac.uk/id/eprint/10089234/1/343019_3_art_0_py4t4l_convrt.pdf"  # Replace with the actual URL of your PDF

# Retrieve and encode the PDF byte
filepath = pathlib.Path('file.pdf')
filepath.write_bytes(httpx.get(doc_url).content)

prompt = "Summarize this document"
response = client.models.generate_content(
  model="gemini-1.5-flash",
  contents=[
      types.Part.from_bytes(
        data=filepath.read_bytes(),
        mime_type='application/pdf',
      ),
      prompt])
print(response.text)

https://ai.google.dev/gemini-api/docs/document-processing?lang=python
@sega
This is an example with pdf as base64 right? that should work with portkey too,
but wasn't your query was about passing public url directly?
It works now thanks
Add a reply
Sign up and join the conversation on Discord