googleapis / python-aiplatform

A Python SDK for Vertex AI, a fully managed, end-to-end platform for data science and machine learning.
Apache License 2.0
615 stars 330 forks source link

generate_content_async raising exeption google.api_core.exceptions.InvalidArgument: 400 Request contains an invalid argument. #4246

Open jutogashi opened 1 month ago

jutogashi commented 1 month ago

Thanks for stopping by to let us know something could be better!

PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.

Please run down the following list and make sure you've tried the usual "quick fixes":

If you are still having issues, please be sure to include as much information as possible:

Environment details

Steps to reproduce

  1. Sending different prompts using generate_content_async seems to have started to throw InvalidArgument exception from today, which didn't happen before.

Code example

import asyncio
from vertexai.preview.generative_models import GenerativeModel
prompt = ...
user_input = ...
parameters = {
    "generation_config": {
        "temperature": 0
        "max_output_tokens": 1024
    }
}
llm_gemini_pro_1_5 = GenerativeModel(
    model_name="gemini-1.5-pro-001", system_instruction=prompt
)
response = await asyncio.wait_for(
    llm_gemini_pro_1_5.generate_content_async(
        user_input,
        **parameters,
    ),
    timeout=60.0,
)

Stack trace

Traceback (most recent call last):
  File "/lib/python3.9/site-packages/google/api_core/grpc_helpers_async.py", line 85, in __await__
    response = yield from self._call.__await__()
  File "/lib/python3.9/site-packages/grpc/aio/_call.py", line 318, in __await__
    raise _create_rpc_error(
grpc.aio._call.AioRpcError: <AioRpcError of RPC that terminated with:
        status = StatusCode.INVALID_ARGUMENT
        details = "Request contains an invalid argument."
        debug_error_string = "UNKNOWN:Error received from peer ipv6:%5B2607:f8b0:400c:c01::5f%5D:443 {created_time:"2024-08-16T13:08:12.970802-03:00", grpc_status:3, grpc_message:"Request contains an invalid argument."}"
>
The above exception was the direct cause of the following exception:
  File "/lib/python3.9/site-packages/vertexai/generative_models/_generative_models.py", line 603, in generate_content_async
    return await self._generate_content_async(
  File "/lib/python3.9/site-packages/vertexai/generative_models/_generative_models.py", line 682, in _generate_content_async
    gapic_response = await self._prediction_async_client.generate_content(
  File "/lib/python3.9/site-packages/google/cloud/aiplatform_v1beta1/services/prediction_service/async_client.py", line 1826, in generate_content
    response = await rpc(
  File "/lib/python3.9/site-packages/google/api_core/grpc_helpers_async.py", line 88, in __await__
    raise exceptions.from_grpc_error(rpc_error) from rpc_error
google.api_core.exceptions.InvalidArgument: 400 Request contains an invalid argument.

Making sure to follow these steps will guarantee the quickest resolution possible.

Thanks!

Ark-kun commented 2 weeks ago

Have you tried the same code without async mode?

P.S. This is service error and usually this means that the SDK has nothing to do with it. Maybe your prompt or user_input are invalid and service rejects them.