Closed reosablo closed 4 months ago
I tried TextDecoderStream
and it seems to work fine.
I'll create PR.
// core/llm/stream.ts
export async function* streamResponse(
response: Response,
): AsyncGenerator<string> {
if (response.status !== 200) {
throw new Error(await response.text());
}
if (!response.body) {
throw new Error("No response body returned.");
}
// `response` doesn't seem to be an instance of globalThis.Response and
// TypeScript doesn't seem to know ReadableStream has `from` method.
const stream = (ReadableStream as any).from(response.body);
// The type of stream is any, not ReadableStream.
// So we don't need "DOM.AsyncIterable" lib for this line.
yield* stream.pipeThrough(new TextDecoderStream());
}
Thanks for the PR @reosablo !
Before submitting your bug report
Relevant environment info
Description
A description of the bug
I'm encountering an issue where responses from Gemini with non-ASCII characters are garbled. This doesn't seem to happen with responses from Groq.
What you expected to happen
Non-ASCII character responses should be displayed correctly, without any garbled characters or replacement characters (like "�").
What actually happened
Currently, non-ASCII characters are being replaced with the replacement character "�". This happens consistently.
For example, the following response is affected:
Screenshots or videos
Possible solutions
I suspect this is because the buffer is being treated as a string, rather than an ArrayBuffer. Since Gemini responses may contain incomplete Unicode bytes, using a string buffer could be causing the corruption.
solution 1: change
buffer
from string to ArrayBuffer instreamChatGemini
functionhttps://github.com/continuedev/continue/blob/aa18568c6096f8f2df7075ff0f1f711f6f75ed01/core/llm/llms/Gemini.ts#L105
solution 2: use
TextDecoderStream
instead ofTextDecoder
instreamResponse
function.https://github.com/continuedev/continue/blob/aa18568c6096f8f2df7075ff0f1f711f6f75ed01/core/llm/stream.ts#L12-L18
To reproduce
Ask some questions in the chat panel in Japanese.
Log output