Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streaming utf-8 #11

Merged
merged 10 commits into from
Dec 15, 2023
Merged

Streaming utf-8 #11

merged 10 commits into from
Dec 15, 2023

Conversation

alx13
Copy link
Contributor

@alx13 alx13 commented Dec 14, 2023

Fixes #9

Copy link

changeset-bot bot commented Dec 14, 2023

🦋 Changeset detected

Latest commit: 5372f24

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@google/generative-ai Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@alx13 alx13 requested a review from hsubox76 December 14, 2023 23:54
@alx13 alx13 changed the title [WIP] streaming utf-8 Streaming utf-8 Dec 14, 2023
): ReadableStream<GenerateContentResponse> {
let currentText = "";
const reader = new ReadableStream<Uint8Array>({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since response.body is a ReadableStream I think we can just pass body to this function and here we can do body.pipeThrough(newTextDecoderStream()).getReader(). But for the tests we'll have to rewrite mockResponse to really make body a ReadableStream instead of an empty object with a getReader() function

@alx13 alx13 force-pushed the issue/utf-parsing branch from b1d3a06 to cbc7670 Compare December 15, 2023 00:37
@@ -110,6 +132,37 @@ function readFromReader(
return stream;
}

function tryParse(currentText: string): {
leftText: string;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we call this "remainingText"?

@hsubox76 hsubox76 merged commit 73c2ff9 into main Dec 15, 2023
3 checks passed
@hsubox76 hsubox76 deleted the issue/utf-parsing branch December 15, 2023 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sendMessageStream with Chinese prompt returns malfunctioning chunks
2 participants