Skip to content

Commit

Permalink
feat: story streaming (#62)
Browse files Browse the repository at this point in the history
## Motivation

* When creating a story, stream the content
  • Loading branch information
TimPietrusky authored Feb 23, 2024
1 parent aa0306e commit 5463eaf
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/electron/future/ipc/story.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,22 @@ Each image is separated from the next image by using a headline "## image 1", th
${imageDescriptions}
`;

const responseStory = await openai.chat.completions.create({
const streamStory = await openai.chat.completions.create({
model: "gpt-4-turbo-preview",
messages: [
{ role: "system", content: systemPrompt },
{ role: "user", content: userPromptStory },
],
stream: true,
});

console.log(responseStory.choices[0].message.content);
let story = "";

const story = responseStory.choices[0].message.content;
window_.webContents.send(buildKey([ID.STORY], { suffix: ":generated" }), story);
for await (const chunk of streamStory) {
story += chunk.choices[0]?.delta?.content || "";

window_.webContents.send(buildKey([ID.STORY], { suffix: ":generated" }), story);
}
} catch (error) {
window_.webContents.send(
buildKey([ID.STORY], { suffix: ":error" }),
Expand Down

0 comments on commit 5463eaf

Please sign in to comment.