The count tokens function generates an `google.api_core.exceptions.PermissionDenied` error when using an uploaded file in the prompt using the files api
haruiz opened this issue · comments
Description of the bug:
After uploading a file using the file API and calling the count_tokens
functions, I get the following error.
google.api_core.exceptions.PermissionDenied: 403 You do not have permission to access the File 8lqhztqcd6g1 or it may not exist
Here is my code:
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
genai.configure(api_key=GOOGLE_API_KEY)
model_name = "models/gemini-1.5-pro-latest"
model = genai.GenerativeModel(model_name)
audio_file_path = "./../data/audio_example.mp3"
audio_sample = genai.upload_file(audio_file_path)
model.count_tokens(audio_sample)
Additional info: For some reason, if I comment the model.count_tokens
call line, and run the following code, it works:
response = model.generate_content([
"Describe the following audio:",
audio_sample
])
print(response)
Actual vs expected behavior:
Return the number of tokens as shown in the notebook: https://github.com/google-gemini/cookbook/blob/main/quickstarts/Counting_Tokens.ipynb
Any other information you'd like to share?
No response
@haruiz, I just tried running the counting tokens tutorial with generative-ai-python 0.5.4
and model.count_tokens
is able to count the numbers of tokens successfully for audio files. Please try out the tutorial and let us know if you face any issues and share a reproducible colab gist with us to reproduce the issue on our end. Thank you!
Hi @singhniraj08, thanks for your response. After updating the library 'generative-ai-python', it works perfectly! Thank you!