Missing spaces in streamChat, streamGenerateContent, and promptStream output in gemini_implement.dart
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:
- Expected output:
"Hello World" - 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);
}
Same thing happening over here.
Same here, this issue unfortunately makes streaming unusable for me.
@nhao2003 I'm using the OpenAI client from openai_dart instead of this library now and it's working just fine, including with streaming, and without weirdly putting words together. Also see https://ai.google.dev/gemini-api/docs/openai. The only thing to note is that the default didn't work and I had set frequencyPenalty: null on the CreateChatCompletionRequest.
I'm experiencing the same problem