create final nodes
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
import { GraphNode } from "@langchain/langgraph";
|
||||
import { MessagesState } from "../state";
|
||||
import { AIMessage } from "@langchain/core/messages";
|
||||
|
||||
export function createDummyModelNode(addition): GraphNode<typeof MessagesState> {
|
||||
return async (state) => {
|
||||
//TODO: call AI model with collected data
|
||||
|
||||
return {
|
||||
messages: [new AIMessage(addition + " : " + state.messages.at(-1)?.content)]
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
import { GraphNode } from "@langchain/langgraph";
|
||||
import { MessagesState } from "../state";
|
||||
import { AIMessage, HumanMessage } from "@langchain/core/messages";
|
||||
|
||||
export const dummyNormalisationModel: GraphNode<typeof MessagesState> = async (state) => {
|
||||
//TODO: call AI model with collected data
|
||||
|
||||
return {
|
||||
messages: [ new AIMessage(state.messages.at(-1)?.content + " Processed")]
|
||||
};
|
||||
};
|
||||
@@ -1,11 +0,0 @@
|
||||
import { GraphNode } from "@langchain/langgraph";
|
||||
import { MessagesState } from "../state";
|
||||
import { AIMessage, HumanMessage } from "@langchain/core/messages";
|
||||
|
||||
export const dummyTriggerEventModel: GraphNode<typeof MessagesState> = async (state) => {
|
||||
//TODO: call AI model with collected data
|
||||
|
||||
return {
|
||||
messages: [ new AIMessage("Trigger events of: " + state.messages.at(-1)?.content)]
|
||||
};
|
||||
};
|
||||
@@ -1,11 +0,0 @@
|
||||
import { GraphNode } from "@langchain/langgraph";
|
||||
import { MessagesState } from "../state";
|
||||
import { AIMessage, HumanMessage } from "@langchain/core/messages";
|
||||
|
||||
export const dummyVerificationModel: GraphNode<typeof MessagesState> = async (state) => {
|
||||
//TODO: call AI model with collected data
|
||||
|
||||
return {
|
||||
messages: [ new AIMessage("Verified : " + state.messages.at(-1)?.content)]
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,9 @@
|
||||
import { GraphNode } from "@langchain/langgraph";
|
||||
import { MessagesState } from "../state";
|
||||
import { AIMessage, HumanMessage } from "@langchain/core/messages";
|
||||
|
||||
export const produceRanking: GraphNode<typeof MessagesState> = async (state) => {
|
||||
//TODO: produce ranking here
|
||||
|
||||
return { messages: [ new AIMessage(state.messages?.length.toString() ?? "0")] };
|
||||
};
|
||||
+19
-18
@@ -1,25 +1,26 @@
|
||||
import { AIMessage, ToolMessage } from "@langchain/core/messages";
|
||||
import { GraphNode } from "@langchain/langgraph";
|
||||
import { MessagesState } from "../state";
|
||||
import { arithmeticToolsByName } from "../tools/arithmetic";
|
||||
|
||||
export const toolNode: GraphNode<typeof MessagesState> = async (state) => {
|
||||
const lastMessage = state.messages.at(-1);
|
||||
export function createToolNode(tools): GraphNode<typeof MessagesState> {
|
||||
return async (state) => {
|
||||
const lastMessage = state.messages.at(-1);
|
||||
|
||||
//STARTTEMP
|
||||
return {messages: [new AIMessage("yeman")]}
|
||||
//ENDTEMP
|
||||
|
||||
if (lastMessage == null || !AIMessage.isInstance(lastMessage)) {
|
||||
return { messages: [] };
|
||||
}
|
||||
//STARTTEMP
|
||||
return {messages: [new AIMessage("yeman")]}
|
||||
//ENDTEMP
|
||||
|
||||
const result: ToolMessage[] = [];
|
||||
for (const toolCall of lastMessage.tool_calls ?? []) {
|
||||
const tool = arithmeticToolsByName[toolCall.name];
|
||||
const observation = await tool.invoke(toolCall);
|
||||
result.push(observation);
|
||||
}
|
||||
if (lastMessage == null || !AIMessage.isInstance(lastMessage)) {
|
||||
return { messages: [] };
|
||||
}
|
||||
|
||||
return { messages: result };
|
||||
};
|
||||
const result: ToolMessage[] = [];
|
||||
for (const toolCall of (lastMessage as AIMessage).tool_calls ?? []) {
|
||||
const tool = tools[toolCall.name];
|
||||
const observation = await tool.invoke(toolCall);
|
||||
result.push(observation);
|
||||
}
|
||||
|
||||
return { messages: result };
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user