From fc97a30f00e77ff7ffb1e3f48df36410936e30ee Mon Sep 17 00:00:00 2001
From: Gregor Martynus <39992+gr2m@users.noreply.github.com>
Date: Tue, 10 Sep 2024 16:20:59 -0700
Subject: [PATCH] fix: set `index: 0` in choices as it is now required in
 copilot API (#76)

---
 lib/response.js                | 3 +++
 test/response.test.js.snapshot | 6 +++---
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/lib/response.js b/lib/response.js
index caf226d..43e98bb 100644
--- a/lib/response.js
+++ b/lib/response.js
@@ -5,6 +5,7 @@ export function createAckEvent() {
   const data = {
     choices: [
       {
+        index: 0,
         delta: { content: ``, role: "assistant" },
       },
     ],
@@ -17,6 +18,7 @@ export function createTextEvent(message) {
   const data = {
     choices: [
       {
+        index: 0,
         delta: { content: message, role: "assistant" },
       },
     ],
@@ -55,6 +57,7 @@ export function createDoneEvent() {
   const data = {
     choices: [
       {
+        index: 0,
         finish_reason: "stop",
         delta: { content: null },
       },
diff --git a/test/response.test.js.snapshot b/test/response.test.js.snapshot
index ef81396..d87b943 100644
--- a/test/response.test.js.snapshot
+++ b/test/response.test.js.snapshot
@@ -1,5 +1,5 @@
 exports[`response > createAckEvent() 1`] = `
-"data: {\\"choices\\":[{\\"delta\\":{\\"content\\":\\"\\",\\"role\\":\\"assistant\\"}}]}\\n\\n"
+"data: {\\"choices\\":[{\\"index\\":0,\\"delta\\":{\\"content\\":\\"\\",\\"role\\":\\"assistant\\"}}]}\\n\\n"
 `;
 
 exports[`response > createConfirmationEvent() 1`] = `
@@ -7,7 +7,7 @@ exports[`response > createConfirmationEvent() 1`] = `
 `;
 
 exports[`response > createDoneEvent() 1`] = `
-"data: {\\"choices\\":[{\\"finish_reason\\":\\"stop\\",\\"delta\\":{\\"content\\":null}}]}\\n\\ndata: [DONE]\\n\\n"
+"data: {\\"choices\\":[{\\"index\\":0,\\"finish_reason\\":\\"stop\\",\\"delta\\":{\\"content\\":null}}]}\\n\\ndata: [DONE]\\n\\n"
 `;
 
 exports[`response > createErrorsEvent() 1`] = `
@@ -19,5 +19,5 @@ exports[`response > createReferencesEvent() 1`] = `
 `;
 
 exports[`response > createTextEvent() 1`] = `
-"data: {\\"choices\\":[{\\"delta\\":{\\"content\\":\\"test\\",\\"role\\":\\"assistant\\"}}]}\\n\\n"
+"data: {\\"choices\\":[{\\"index\\":0,\\"delta\\":{\\"content\\":\\"test\\",\\"role\\":\\"assistant\\"}}]}\\n\\n"
 `;