Skip to content

Commit

Permalink
remove unused associated value from Mode type in the ‘message’ case
Browse files Browse the repository at this point in the history
  • Loading branch information
ataibarkai committed Apr 24, 2024
1 parent 43b60a5 commit 5d96ed9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
6 changes: 2 additions & 4 deletions CopilotKit/packages/backend/src/utils/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,14 @@ export function copilotkitStreamInterceptor(
console.log("data: " + JSON.stringify(value) + "\n\n");
}

type Mode =
| { type: "function"; toolCall: ToolCallPayload }
| { type: "message"; associatedValue: string };
type Mode = { type: "function"; toolCall: ToolCallPayload } | { type: "message" };

let mode: Mode;
const maybeToolCall = value.choices[0].delta.tool_calls?.[0];
if (maybeToolCall) {
mode = { type: "function", toolCall: maybeToolCall };
} else {
mode = { type: "message", associatedValue: value.choices[0].delta.content! };
mode = { type: "message" };
}

const nextChunkIndex = mode.type === "function" ? mode.toolCall.index : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ export function decodeChatCompletion(
): ReadableStream<ChatCompletionEvent> {
const reader = stream.getReader();

type Mode =
| { type: "function"; function: ToolCallFunctionCall }
| { type: "message"; associatedValue: string };
type Mode = { type: "function"; function: ToolCallFunctionCall } | { type: "message" };

let mode: Mode | null = null;
let functionCallName: string = "";
Expand Down Expand Up @@ -111,7 +109,7 @@ export function decodeChatCompletion(
if (maybeFunctionCall) {
mode = { type: "function", function: maybeFunctionCall };
} else {
mode = { type: "message", associatedValue: value.choices[0].delta.content! };
mode = { type: "message" };
}

// if we get a message, emit the content and continue;
Expand Down

0 comments on commit 5d96ed9

Please sign in to comment.