googleapis / proto-plus-python

Beautiful, idiomatic protocol buffers in Python
Apache License 2.0
169 stars 35 forks source link

to_dict incorrectly returns base64 encoded results for bytes type #478

Open Ark-kun opened 3 months ago

Ark-kun commented 3 months ago

Message.to_dict returns bytes fields as Base-64 encoded strings instead of proper bytes strings. It also returns integers as strings instead of int.

Environment details

Steps to reproduce

model = GenerativeModel("gemini-pro")
compute_tokens_response = model.compute_tokens(["Hello world!", "How are you?"])
token_info = compute_tokens_response.tokens_info[1]
>>> token_info

tokens: "How"
tokens: " are"
tokens: " you"
tokens: "?"
token_ids: 2299
token_ids: 708
token_ids: 692
token_ids: 235336
role: "user"
>>> type(token_info).to_dict(token_info)

{'tokens': ['SG93', 'IGFyZQ==', 'IHlvdQ==', 'Pw=='],
 'token_ids': ['2299', '708', '692', '235336'],
 'role': 'user'}