Skip to content

Missing spaces in streamChat, streamGenerateContent, and promptStream output in gemini_implement.dart #47

Description

@nhao2003

Description of the Issue:

When using the methods streamChat, streamGenerateContent, and promptStream, the output is missing spaces between words, causing words to be concatenated incorrectly.

Example:

  1. Expected output: "Hello World"
  2. Actual output: "HelloWorld"

Location of the Issue:
File: gemini_implement.dart

Current code:

res = res.trim();

if (index == 0 && res.startsWith("[")) {
  res = res.replaceFirst('[', '');
}
if (res.startsWith(',')) {
  res = res.replaceFirst(',', '');
}
if (res.endsWith(']')) {
  res = res.substring(0, res.length - 1);
}

res = res.trim();

Proposed Fix:
Use a separate variable (trimmedRes) to check conditions before modifying res, preventing unintended modifications that could cause words to be concatenated incorrectly:

String trimmedRes = res.trim();

if (index == 0 && trimmedRes.startsWith("[")) {
  res = res.replaceFirst('[', '');
}
if (trimmedRes.startsWith(',')) {
  res = res.replaceFirst(',', '');
}
if (trimmedRes.endsWith(']')) {
  res = res.substring(0, res.length - 1);
}

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions