Hi, all!
In my tests models.generateContent
returns a 500
error code 100% of the time. See the reproduction script below.
The script effectively creates a contentCache containing 9MB of text (e.g. SQLite3 C code) then asks the model a simple question about it. The script uses basic tools like jq
, tar
and curl
to make it easy to run it.
#!/usr/bin/env bash
pushd /tmp
curl https://sqlite.org/2024/sqlite-autoconf-3460000.tar.gz > sqlite-autoconf-3460000.tar.gz
tar xvfz sqlite-autoconf-3460000.tar.gz sqlite-autoconf-3460000/sqlite3.c
jq \
--null-input \
--rawfile sqlite3_source sqlite-autoconf-3460000/sqlite3.c \
'{
"contents": [
{
"parts": [
{
"text": $sqlite3_source
}
],
"role": "user",
}
],
"model": "models/gemini-1.5-flash-001"
}' > cached_contents_payload.json
cached_content_name=$(
curl \
--request POST \
--header "x-goog-api-key: $GEMINI_API_KEY" \
--json @cached_contents_payload.json \
https://generativelanguage.googleapis.com/v1beta/cachedContents \
| jq '.name' --raw-output
)
jq \
--null-input \
--arg cached_content_name $cached_content_name \
'{
"cachedContent": $cached_content_name,
"contents": [
{
"parts": [
{
"text": "Source code for what software is this?"
}
],
"role": "user"
}
]
}' > generate_content_payload.json
curl \
--request POST \
--header "x-goog-api-key: $GEMINI_API_KEY" \
--json @generate_content_payload.json \
https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-001:generateContent
# Clean-up
#
curl \
--verbose \
--request DELETE \
--header "x-goog-api-key: $GEMINI_API_KEY" \
https://generativelanguage.googleapis.com/v1beta/$cached_content_name
rm -r sqlite-autoconf-3460000*
popd
Run it like this:
GEMINI_API_KEY=abcd1234... ./problem.bash
The output is this:
{
"error": {
"code": 500,
"message": "An internal error has occurred. Please retry or report in https://developers.generativeai.google/guide/troubleshooting",
"status": "INTERNAL"
}
}
Any idea what am I doing wrong? I also tried using a different model, gemini-1.5-pro-001
, only to get the same error.