googleapis / proto-plus-python

Beautiful, idiomatic protocol buffers in Python
Apache License 2.0
171 stars 36 forks source link

Can't handle repeated `Value` field (from `protobuf/struct.proto`) #488

Open MarkDaoust opened 2 months ago

MarkDaoust commented 2 months ago

We're launching an instance of this prediction service:

google/ai/generativelanguage/v1main/prediction_service.proto;l=77

The PredictRequest has in instances field that is a repeated protobufs.struct.Value.

Screenshot 2024-09-17 at 9 03 34 AM

No matter what you pass as instances here, the result is "Value must be iterable".

Debugging found that if you pass a list/sequence it gets converted to a struct_pb2.ListValue but the field is a repeated struct._pb2.Value so that fails.

Steps to reproduce

https://colab.sandbox.google.com/drive/1grGEJgXiZyvrJCZKvsFmuLyEeXc65vai?resourcekey=0-lTxTMUz7WTDYmV-CS9UHOQ#scrollTo=f4HxrpopJQ-C

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

Thanks!

MarkDaoust commented 1 month ago

Update:

I found a workaround, so I'm not blocked.

  1. I wrote my own to_value function:

https://github.com/google-gemini/generative-ai-python/blob/imagen/google/generativeai/vision_models/_vision_models.py#L55-L98

  1. And then when I need an instance containing a list of Values, I create an instance of the underlying raw proto (to bypass the failing logic):

https://github.com/google-gemini/generative-ai-python/blob/imagen/google/generativeai/vision_models/_vision_models.py#L351-L354

But it would be nice if this case was handled.

Thanks!