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
631 stars 345 forks source link

Calling GetModelGarden when using REST fails because of empty query strings #4550

Open idofl opened 1 week ago

idofl commented 1 week ago

After initiating the SDK with api_transport="rest", calling the GetPublisherModel function fails with the error:

google.api_core.exceptions.BadRequest: 400 GET https://us-central1-aiplatform.googleapis.com/v1/publishers/google/models/medlm-large?name=&languageCode=&view=0&huggingFaceToken=&%24alt=json%3Benum-encoding%3Dint: List of found errors: 1.Field: name; Message: Required field is not set. 2.Field: name; Message: GetPublisherModelRequest has invalid publisher model name. Current publisher model name: ''.

I tracked down the error to the _BaseGetPublisherModel class in https://github.com/googleapis/python-aiplatform/blob/main/google/cloud/aiplatform_v1/services/model_garden_service/transports/rest_base.py

The generated URL places the name parameter in the path as it should ({name=publishers//models/}), but keeps a query string parameter "name" with an empty value - you can see the resulted URL in the above error.

If I use curl with the above URL I get the same error. If I manually remove the empty params ("name=" and "languageCode="), curl returns a valid response.

Please fix the code to remove empty query string params from the generated URL.

parthea commented 6 days ago

@idofl, Regrettably I'm not able to re-create the issue with the SDK using a minimal example. Please could you share the code used when you saw the error?

DEBUG:urllib3.connectionpool:https://oauth2.googleapis.com:443 "POST /token HTTP/11" 200 None
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): us-central1-aiplatform.googleapis.com:443
send: b'GET /v1/publishers/REDACTED/models/REDACTED?%24alt=json%3Benum-encoding%3Dint HTTP/1.1\r\nHost: us-central1-aiplatform.googleapis.com\r\nUser-Agent: python-requests/2.32.3\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nx-goog-request-params: name=publishers/REDACTED/models/REDACTED\r\nx-goog-api-client: gl-python/3.9.16 grpc/1.66.1 gax/2.21.0 gapic/1.70.0 cred-type/u\r\nContent-Type: application/json\r\nauthorization: Bearer.....
idofl commented 1 day ago

We are getting the error regardless of the model name we use.

vertexai.init(

        project=os.getenv("VERTEXAI_PROJECT_ID"),

        location=os.getenv("VERTEXAI_LOCATION"),

        credentials=credentials,

        api_transport="rest"

    )

    parameters = {

        "max_output_tokens": 400,

        "temperature": 1,

        "top_p": 0.95,

    }

    model_instance = TextGenerationModel.from_pretrained("medlm-large")

    response = model_instance.predict(

        "Question: What causes you to get ringworm?",

        **parameters

    )