Skip to content

Commit 1164a38

Browse files
asperpharmaCopilot
andauthored
Apply suggestions from code review
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Asper Beauty Shop <252395498+asperpharma@users.noreply.github.com>
1 parent d229ccf commit 1164a38

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

  • supabase/functions/beauty-assistant

supabase/functions/beauty-assistant/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,9 +510,14 @@ serve(async (req) => {
510510
if (buffer) {
511511
const remainingLines = buffer.split("\n");
512512
for (const line of remainingLines) {
513-
if (line.startsWith("data: ") && line !== "data: [DONE]") {
513+
const trimmed = line.trimEnd();
514+
if (trimmed.startsWith("data:")) {
515+
const dataPayload = trimmed.slice("data:".length).trimStart();
516+
if (dataPayload === "[DONE]") {
517+
continue;
518+
}
514519
try {
515-
const json = JSON.parse(line.slice(6));
520+
const json = JSON.parse(dataPayload);
516521
const text = json?.candidates?.[0]?.content?.parts?.[0]?.text;
517522
if (text) {
518523
const chunk = `data: ${JSON.stringify({ choices: [{ delta: { content: text } }] })}\n\n`;

0 commit comments

Comments
 (0)