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

Function DBChatMessageToGPT

lib/edge-runtime/utils.ts:31–56  ·  view source on GitHub ↗
(
  message: DBChatMessage,
)

Source from the content-addressed store, hash-verified

29}
30
31export function DBChatMessageToGPT(
32 message: DBChatMessage,
33): GPTMessageInclSummary {
34 if (message.role === "function") {
35 let content: string;
36 try {
37 // Below conversion to JSON and back to string remove all newlines, indentation etc
38 // which are empty tokens. This can cut tokens by ~half
39 content = JSON.stringify(JSON.parse(message.content));
40 } catch (e) {
41 // If invalid JSON
42 content = message.content;
43 }
44
45 return {
46 role: message.role,
47 content: content,
48 name: message.name!,
49 summary: message.summary ?? undefined,
50 };
51 }
52 return {
53 role: message.role as "user" | "assistant",
54 content: message.content,
55 };
56}
57
58export function MessageInclSummaryToGPT(
59 message: GPTMessageInclSummary,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected