GoogleCloudPlatform / python-docs-samples

Code samples used on cloud.google.com
Apache License 2.0
7.46k stars 6.45k forks source link

adding batch gemini predict sample #12606

Closed CadillacBurgess1 closed 1 month ago

CadillacBurgess1 commented 2 months ago

Description

Fixes #

Note: Before submitting a pull request, please open an issue for discussion if you are not associated with Google.

Checklist

snippet-bot[bot] commented 2 months ago

Here is the summary of changes.

You are about to add 1 region tag. - [generative_ai/batch_predict/batch_gemini_predict.py:33](https://github.com/CadillacBurgess1/python-docs-samples/blob/b996c0a1fe95329a06dbb2b437b80b52fc0822ee/generative_ai/batch_predict/batch_gemini_predict.py#L33), tag `generativeaionvertexai_batch_predict_gemini_createjob`

This comment is generated by snippet-bot. If you find problems with this result, please file an issue at: https://github.com/googleapis/repo-automation-bots/issues. To update this comment, add snippet-bot:force-run label or use the checkbox below:

CadillacBurgess1 commented 2 months ago

The issue was importing the preview resource. When I first created this sample it was working using the preview namespace (which as fine when I first started working on this sample), but the samples and testing in the batch predict folder uses the aiplatform namespace. Both aiplatform and vertexai.preview have a BatchPredictionJob class and they work a little different. I updated my sample to use the BatchPredictionJob class in the aiplatform namespace.

holtskinner commented 2 months ago

The issue was importing the preview resource. When I first created this sample it was working using the preview namespace (which as fine when I first started working on this sample), but the samples and testing in the batch predict folder uses the aiplatform namespace. Both aiplatform and vertexai.preview have a BatchPredictionJob class and they work a little different. I updated my sample to use the BatchPredictionJob class in the aiplatform namespace.

I think this sample should be using the vertexai.preview BatchPredictionJob class as it is intended for use with Gemini. (Different than other batch prediction samples for non-Gemini models)

I'll defer to the Vertex AI SDK product team @Ark-kun (or other)


This notebook from @gericdong also uses the vertexai.preview space

https://github.com/GoogleCloudPlatform/generative-ai/pull/1138/files

holtskinner commented 1 month ago

Looks like you're getting an error in the tests:

ValueError: Please either specify output_uri_prefix or set staging_bucket in vertexai.init().
msampathkumar commented 1 month ago

Errors for Py 3.11

  File "/workspace/generative_ai/.nox/py-3-11/lib/python3.11/site-packages/vertexai/batch_prediction/_batch_prediction.py", line 180, in submit
    if output_uri_prefix.startswith("gs://"):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/typing.py", line 1294, in __getattr__
    return getattr(self.__origin__, attr)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/typing.py", line 453, in __getattr__
    raise AttributeError(item)
AttributeError: startswith

Errors for Py 3.8

  File "/workspace/generative_ai/batch_predict/batch_gemini_predict.py", line 51, in batch_gemini_prediction
    batch_prediction_job = BatchPredictionJob.submit(
  File "/workspace/generative_ai/.nox/py-3-8/lib/python3.8/site-packages/vertexai/batch_prediction/_batch_prediction.py", line 180, in submit
    if output_uri_prefix.startswith("gs://"):
  File "/usr/local/lib/python3.8/typing.py", line 759, in __getattr__
    return getattr(self.__origin__, attr)
AttributeError: '_SpecialForm' object has no attribute 'startswith'

Checking on the samples.

CadillacBurgess1 commented 1 month ago

closing and opening new PR due to noise