Skip to content

Commit

Permalink
fix: just add todos
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyLv committed Mar 13, 2023
1 parent 88ba363 commit dd05139
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/openai/fetchOpenAIResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export async function fetchOpenAIResult(
}

let counter = 0;

let tempData = "";
const stream = new ReadableStream({
async start(controller) {
// callback
Expand All @@ -65,12 +65,15 @@ export async function fetchOpenAIResult(
const data = event.data;
// https://beta.openai.com/docs/api-reference/completions/create#completions/create-stream
if (data === "[DONE]") {
// active
controller.close();
return;
}
try {
const json = JSON.parse(data);
const text = trimOpenAiResult(json);
// todo: add redis cache
tempData += text;
console.log("=====text====", text);
if (counter < 2 && (text.match(/\n/) || []).length) {
// this is a prefix character (i.e., "\n\n"), do nothing
Expand Down

1 comment on commit dd05139

@vercel
Copy link

@vercel vercel bot commented on dd05139 Mar 13, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.