MCPcopy Create free account
hub / github.com/Superflows-AI/superflows / updatePastAssistantMessage

Function updatePastAssistantMessage

lib/edge-runtime/angelaUtils.ts:11–47  ·  view source on GitHub ↗
(
  command: FunctionCall,
  nonSystemMessages: GPTMessageInclSummary[],
)

Source from the content-addressed store, hash-verified

9import _ from "lodash";
10
11export function updatePastAssistantMessage(
12 command: FunctionCall,
13 nonSystemMessages: GPTMessageInclSummary[],
14) {
15 /** Updates the history of the assistant message to include the filled-in parameters in the command
16 *
17 * E.g. from
18 * test(a=b)
19 *
20 * where requiredParam was missing to
21 * test(a=b, requiredParam=value)
22 * **/
23 console.log("Updating past assistant message with command:", command);
24 const newCommandLine = `${command.name}(${Object.entries(command.args)
25 .map(([key, value]) => `${key}=${JSON.stringify(value)}`)
26 .join(", ")})`;
27
28 // Update the last assistant message in the nonSystemMessages array
29 const lastAssistantMessageIndex =
30 nonSystemMessages.length -
31 1 -
32 nonSystemMessages.reverse().findIndex((m) => m.role === "assistant");
33 nonSystemMessages.reverse(); // Reverse back to original order
34
35 nonSystemMessages[lastAssistantMessageIndex].content = nonSystemMessages[
36 lastAssistantMessageIndex
37 ].content
38 .split("\n") // Split into lines
39 .map((line) => {
40 // Below checks if it's the same function call as the one we're updating
41 if (line.startsWith(command.name + "(") && line.trim().endsWith(")")) {
42 return newCommandLine;
43 }
44 return line;
45 })
46 .join("\n"); // Re-join lines
47}
48
49export async function streamResponseToUser(
50 res: ReadableStream,

Callers 3

BertieFunction · 0.90
AngelaFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected