Skip to content

Commit

Permalink
Fix queue closing.
Browse files Browse the repository at this point in the history
  • Loading branch information
lgrammel committed Jul 11, 2023
1 parent a5d4a84 commit 75aa96c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion examples/ai-chat-next-js/src/pages/api/send-message.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
CohereTextGenerationModel,
LlamaCppTextGenerationModel,
OpenAIChatMessage,
OpenAIChatModel,
Expand Down Expand Up @@ -66,8 +67,12 @@ async function createTextStream(
controller: AbortController
) {
return streamText(
// You can user other models such as CohereTextGenerationModel here:
new LlamaCppTextGenerationModel({}),
// You can also use other models such as CohereTextGenerationModel instead:
// new CohereTextGenerationModel({
// model: "command-nightly",
// maxTokens: 1000,
// }),
[
"You are an AI chat bot. " +
"Follow the user's instructions carefully. Respond using markdown.",
Expand Down
5 changes: 5 additions & 0 deletions src/model/text-streaming/TextDeltaEventSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,13 @@ export function convertTextDeltaEventSourceToIterable(
);

queue.push(data.textDelta);

if (data.isFinished) {
queue.close();
}
} catch (error) {
options?.errorHandler(error);
queue.close();
}
},
});
Expand Down

1 comment on commit 75aa96c

@vercel
Copy link

@vercel vercel bot commented on 75aa96c Jul 11, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

ai-utils-js – ./

ai-utils-js-git-main-lgrammel.vercel.app
ai-utils.vercel.app
ai-utils-js-lgrammel.vercel.app
ai-utils.dev

Please sign in to comment.