Skip to content

Commit

Permalink
fix: set index: 0 in choices as it is now required in copilot API (#76
Browse files Browse the repository at this point in the history
)
  • Loading branch information
gr2m authored Sep 10, 2024
1 parent c593ba6 commit fc97a30
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions lib/response.js
Original file line number Diff line number Diff line change
@@ -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 },
},
6 changes: 3 additions & 3 deletions test/response.test.js.snapshot
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
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`] = `
"event: copilot_confirmation\\ndata: {\\"type\\":\\"action\\",\\"title\\":\\"title\\",\\"message\\":\\"message\\",\\"confirmation\\":{\\"id\\":\\"123\\",\\"foo\\":\\"bar\\"}}\\n\\n"
`;

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"
`;

0 comments on commit fc97a30

Please sign in to comment.