generative-ai-python icon indicating copy to clipboard operation
generative-ai-python copied to clipboard

google.api_core.exceptions.InternalServerError: 500 An internal error has occurred.

Open JoshuaEworo opened this issue 1 year ago • 4 comments

Description of the bug:

The error occurs when "res = geminiClient.generate_content(conversation).text" is reached again in a recursive function call. I expected it to work the same way it did over the function's first pass. How do i fix this?

Error/Bug Found:

Traceback (most recent call last):
  File "C:\Users\eworo\DELTA\env\Lib\site-packages\google\api_core\grpc_helpers.py", line 79, in error_remapped_callable
    return callable_(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\eworo\DELTA\env\Lib\site-packages\grpc\_channel.py", line 1160, in __call__
    return _end_unary_response_blocking(state, call, False, None)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\eworo\DELTA\env\Lib\site-packages\grpc\_channel.py", line 1003, in _end_unary_response_blocking
    raise _InactiveRpcError(state)  # pytype: disable=not-instantiable
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
        status = StatusCode.INTERNAL
        details = "An internal error has occurred. Please retry or report in https://developers.generativeai.google/guide/troubleshooting"
        debug_error_string = "UNKNOWN:Error received from peer ipv4:142.250.115.95:443 {created_time:"2023-12-15T04:18:34.1915935+00:00", grpc_status:13, grpc_message:"An internal error has occurred. Please retry or report in https://developers.generativeai.google/guide/troubleshooting"}"
>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "c:\Users\eworo\DELTA\src\test.py", line 48, in <module>
    infer(input("Q: "))
  File "c:\Users\eworo\DELTA\src\test.py", line 45, in infer
    infer("")
  File "c:\Users\eworo\DELTA\src\test.py", line 40, in infer
    res = geminiClient.generate_content(conversation).text
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\eworo\DELTA\env\Lib\site-packages\google\generativeai\generative_models.py", line 243, in generate_content
    response = self._client.generate_content(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\eworo\DELTA\env\Lib\site-packages\google\ai\generativelanguage_v1beta\services\generative_service\client.py", line 566, in generate_content
    response = rpc(
               ^^^^
  File "C:\Users\eworo\DELTA\env\Lib\site-packages\google\api_core\gapic_v1\method.py", line 131, in __call__
    return wrapped_func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\eworo\DELTA\env\Lib\site-packages\google\api_core\retry.py", line 372, in retry_wrapped_func
    return retry_target(
           ^^^^^^^^^^^^^
  File "C:\Users\eworo\DELTA\env\Lib\site-packages\google\api_core\retry.py", line 207, in retry_target
    result = target()
             ^^^^^^^^
  File "C:\Users\eworo\DELTA\env\Lib\site-packages\google\api_core\timeout.py", line 120, in func_with_timeout
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\eworo\DELTA\env\Lib\site-packages\google\api_core\grpc_helpers.py", line 81, in error_remapped_callable
    raise exceptions.from_grpc_error(exc) from exc
google.api_core.exceptions.InternalServerError: 500 An internal error has occurred. Please retry or report in https://developers.generativeai.google/guide/troubleshooting

Any other information you'd like to share?

I was using the Gemini API.

Here is code to recreate the error:

import google.generativeai as genai

genai.configure(api_key="API_KEY")

geminiClient = genai.GenerativeModel(model_name="gemini-pro")

conversation = [{'role':'user','parts': [f"Hello!"]}, {'role':'model','parts': ["Hey there Anon!"]}]


def infer(query):
    conversation.append({'role':'user','parts': [query]})
    res = geminiClient.generate_content(conversation).text
    print("A: " + res)
    conversation.append({'role':'model','parts': [res]})

    if res == "Y":
        infer("")

while True:
    infer(input("Q: "))

To attain the error, tell the model "only respond to me with "Y" until i say stop".

JoshuaEworo avatar Dec 15 '23 04:12 JoshuaEworo

UPDATE (Problem resolved): Turns out this happens if an empty string is passed as a part.

JoshuaEworo avatar Dec 15 '23 09:12 JoshuaEworo

the issue is still valid I believe. We should fix the status code of 500.

saikatmitra91 avatar Jan 10 '24 09:01 saikatmitra91

Still 500 everyday. I would suggest team to check the backend 500 logs, and fix one by one. 😄

suqi avatar Mar 12 '24 15:03 suqi

This is a known issue with the model and not related to the library see #236 236

LindaLawton avatar Mar 15 '24 08:03 LindaLawton

We've had a few patches of intermittent 500 errors in the past. I think this is fixed. But please reopen if yiou find that it's still reproducible.

MarkDaoust avatar May 17 '24 22:05 MarkDaoust