generative-ai-python icon indicating copy to clipboard operation
generative-ai-python copied to clipboard

how to convert resp to dict or json?

Open ikrammert opened this issue 2 years ago • 3 comments

Description of the feature request:

hi, i have a question i write this code but this 'resp' not JSON serializable

genai.configure(api_key=apiKey)
    model = genai.GenerativeModel("gemini-pro")   
    resp = model.generate_content("tell me a joke")
    b=resp.candidates
    

or resp._result

how to convert resp to dict or json? thanks for help ❤️

What problem are you trying to solve with this feature?

No response

Any other information you'd like to share?

No response

ikrammert avatar Dec 19 '23 12:12 ikrammert

Yes, we need to do this.

I'll include it in the next patch version, 0.3.3. Planned for ~12 Jan.

Proto objects can be converted with type(obj).to_dict(obj) but GenerateContentResponse is not a proto class, it's a python wrapper.

All our python classes should have a standard method for converting to a json.

MarkDaoust avatar Dec 21 '23 23:12 MarkDaoust

Thaks for answer 🙏, But I started to use your go lang sdk

ikrammert avatar Dec 22 '23 05:12 ikrammert

Yes, we need to do this.

I'll include it in the next patch version, 0.3.3. Planned for ~12 Jan.

Proto objects can be converted with type(obj).to_dict(obj) but GenerateContentResponse is not a proto class, it's a python wrapper.

All our python classes should have a standard method for converting to a json.

Do we have any workaround to achieve this until this is not available in a library?

hetvi01 avatar Feb 13 '24 05:02 hetvi01