From c28b328ba39ee9a0f581bd52891497ab9313335b Mon Sep 17 00:00:00 2001 From: Farhim Keser Date: Sun, 10 Sep 2023 19:50:41 -0400 Subject: [PATCH] Update chat.ts --- pages/api/chat.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pages/api/chat.ts b/pages/api/chat.ts index 7234a6f..7475cf4 100644 --- a/pages/api/chat.ts +++ b/pages/api/chat.ts @@ -38,7 +38,7 @@ const handler = async (req: Request): Promise => { let tokenCount = prompt_tokens.length; let messagesToSend: Message[] = []; - for (let i = messages.length - 1; i >= 0; i--) { + for (let i = messages.length - 1; i >= 0; --i) { const message = messages[i]; const tokens = encoding.encode(message.content); @@ -54,6 +54,7 @@ const handler = async (req: Request): Promise => { const stream = await OpenAIStream(model, promptToSend, temperatureToUse, key, messagesToSend); return new Response(stream); + } catch (error) { console.error(error); if (error instanceof OpenAIError) {