Skip to content

to_dict incorrectly returns base64 encoded results for bytes type #478

@Ark-kun

Description

@Ark-kun

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

  • Programming language: Python
  • OS: Linux
  • Language runtime version: 3.10
  • Package version: 1.24

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'}

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions