Skip to content
This repository was archived by the owner on Dec 16, 2025. It is now read-only.
This repository was archived by the owner on Dec 16, 2025. It is now read-only.

Gemini 1.5 Pro Error: "Something went wrong while trying to deserialize a response from the server." #160

Closed

Description

@karloti

Description of the bug:

I get this error very, very often. I wait about 15 seconds and repeat the prompt until I get a normal response. The prompt is not in English. This wastes a lot of time and I don't know how to fix it. Is there a way to handle errors? The model returns them to normal text that I have to parse. So far I have received over x3 types of different errors from Gemini 1.5 Pro.

image

Actual vs expected behavior:

No response

Any other information you'd like to share?

No response

Activity

  1. karloti commented on May 30, 2024

    @karloti
    Author

    BILLING from google.ai.generativelanguage.v1beta.GenerativeService.GenerateContent

    Gemini requests are currently being billed to me. The problem is that I get an error from the library and no result.
    Please tell me what to do? This library has a serialization error. I repeatedly repeat the request until I get an answer that does not have an error and in this way insanely large amounts are charged. Is there a way to not charge these errors? If not, in this case this library is not appropriate to use because it generates billing that is without any content.
    For example, here is the following error:

    image

    dump.txt

  2. rlazo commented on May 30, 2024

    @rlazo
    Collaborator

    Hey @karloti could you share the prompt you are using that's triggering the deserialization issue for debugging?

  3. karloti commented on May 30, 2024

    @karloti
    Author

    Hello,
    thanks for your quick reply.
    I think this is where the problem comes from. I'm thinking of replacing it with a String scheme

    image

  4. davidmotson commented on May 30, 2024

    @davidmotson
    Contributor

    I think the issue may be because you are subclassing FunctionDeclaration. This is not the intended use. Does this error also occur if you use the defineFunction methods?

  5. rlazo commented on May 30, 2024

    @rlazo
    Collaborator

    Sounds like a possibility, since the trace points to that line

    	at com.google.ai.client.generativeai.common.shared.FunctionCall$$serializer.deserialize(Types.kt:62)
    

    that being said, it should absolutely not fail deserializing. The model is not returning a value that we were expecting.

  6. davidmotson commented on May 30, 2024

    @davidmotson
    Contributor

    relatedly, if you happen to be able to pull the text of one of these responses that fails to parse that would help debugging immensely. If you're in android studio you can use the network inspector in App Inspection to accomplish this.

  7. karloti commented on May 30, 2024

    @karloti
    Author

    I made a change to the code but it didn't help. It keeps giving the same error. After a few tries it manages to return a correct result, but this is not a good idea because it is charged.

    image
    image

  8. karloti commented on May 30, 2024

    @karloti
    Author

    relatedly, if you happen to be able to pull the text of one of these responses that fails to parse that would help debugging immensely. If you're in android studio you can use the network inspector in App Inspection to accomplish this.

    I can give you the prompt, but I don't want it here publicly. Maybe an email. Note that the prompt is in Bulgarian and this may be a problem. However, the fact is that the same prompt has no problem in AI Studio

  9. davidmotson commented on May 30, 2024

    @davidmotson
    Contributor

    Actually, the response is more important, Feel free to remove any strings you like from it, the structure is whats important.

    If you'd prefer to email it to me, you can email it to davidmotson@google.com

  10. rlazo commented on May 30, 2024

    @rlazo
    Collaborator

    Alternatively, you could record request/responses send to the server using https://developer.android.com/studio/debug/network-profiler

    That would allow us to see what gets send and what you get back. As @davidmotson said, structure matters rather than content, so you can edit out the values.

  11. added
    type:bug
    status:awaiting user response
    component:android sdk
    on May 31, 2024
  12. karloti commented on May 31, 2024

    @karloti
    Author

    I forked generative-ai-android.git
    I suspect that the error is caused by the serialization of the returned list of candidates.

    image
    image

  13. karloti commented on May 31, 2024

    @karloti
    Author

    Alternatively, you could record request/responses send to the server using https://developer.android.com/studio/debug/network-profiler

    That would allow us to see what gets send and what you get back. As @davidmotson said, structure matters rather than content, so you can edit out the values.

    Temporarily stopped the Gemini API

    I've also temporarily stopped the Gemini API for obvious reasons and can't give you a result from Network Inspector, but I've emailed everything I need and described the problem pretty well.

    I hope you fix the error as soon as possible!

    I have used type safe text for TextPart(val text: String)

    I have no null strings passed
    I also emailed the prompt to @davidmotson which shows that everything is normal.
    here is the code snippet which appears to be null safe (prompt):

    image

  14. karloti commented on Jun 5, 2024

    @karloti
    Author

    This bug will be fixed in v0.8.0
    I have already tested the latest update and the bug is caught.
    Thanks to David for fixing this.

  15. reopened this on Jun 8, 2024
  16. assigned and unassigned on Jun 10, 2024
  17. rlazo commented on Jun 12, 2024

    @rlazo
    Collaborator

    image image image image

    @davidmotson https://drive.google.com/drive/folders/10S8eA3nXlkxUjqlK9EuIptzDMF7WQJf1?usp=sharing

    Seems like this is not the same issue as the original one. Please create a new issue to track it separately. Thanks!

    New version 0.8.0 has been published, including the fix to the original issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

component:android sdkstatus:awaiting user responsetype:bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions