Refactor calculating score. Add sort node for vanity

This commit is contained in:
William Jeynes
2026-02-12 23:46:00 +00:00
parent b06c08daab
commit 7fe63d6a98
6 changed files with 56 additions and 30 deletions
+20
View File
@@ -0,0 +1,20 @@
import { GraphNode } from "@langchain/langgraph";
import { MessagesState } from "../state";
import { AIMessage } from "@langchain/core/messages";
export const sort: GraphNode<typeof MessagesState> = async (state) => {
//not sure which will be better from API, just do both
let current = state.proposedTriggerEvent;
current.sort((a, b) => ((b.score as number) ?? 0) - ((a.score as number) ?? 0));
const displayVersion = current.map((item) => ({
event: item.Event,
reasoningWhyRelevant: item.ReasoningWhyRelevant,
score: item.score ?? 0,
}));
let message = new AIMessage(JSON.stringify(displayVersion))
return { proposedTriggerEvent: current, messages: [message] };
};