fix message reversing
This commit is contained in:
@@ -32,7 +32,8 @@ async function router(
|
||||
const prompt = `You're a highly helpful AI assistant, tasked with routing the user's query to the appropriate tool.
|
||||
You should analyze the user's input, and choose the appropriate tool to use.`;
|
||||
|
||||
const recentHumanMessage = state.messages
|
||||
const messagesCopy = state.messages;
|
||||
const recentHumanMessage = messagesCopy
|
||||
.reverse()
|
||||
.find((m) => m.getType() === "human");
|
||||
|
||||
@@ -65,7 +66,11 @@ function handleRoute(
|
||||
|
||||
async function handleGeneralInput(state: GenerativeUIState) {
|
||||
const llm = new ChatOpenAI({ model: "gpt-4o-mini", temperature: 0 });
|
||||
const response = await llm.invoke(state.messages);
|
||||
const messagesCopy = state.messages;
|
||||
messagesCopy.reverse();
|
||||
console.log("messagesCopy", messagesCopy);
|
||||
|
||||
const response = await llm.invoke(messagesCopy);
|
||||
|
||||
return {
|
||||
messages: [response],
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { StockbrokerState } from "../types";
|
||||
import { ToolMessage } from "@langchain/core/messages";
|
||||
import { ChatOpenAI } from "@langchain/openai";
|
||||
import { typedUi } from "@langchain/langgraph-sdk/react-ui/server";
|
||||
import type ComponentMap from "../../uis/index";
|
||||
@@ -64,19 +63,8 @@ export async function callTools(
|
||||
ui.write("portfolio", {});
|
||||
}
|
||||
|
||||
const toolMessages =
|
||||
message.tool_calls?.map((tc) => {
|
||||
return new ToolMessage({
|
||||
name: tc.name,
|
||||
tool_call_id: tc.id ?? "",
|
||||
content: "Successfully handled tool call",
|
||||
});
|
||||
}) || [];
|
||||
|
||||
console.log("Returning", [message, ...toolMessages]);
|
||||
|
||||
return {
|
||||
messages: [message, ...toolMessages],
|
||||
messages: [message],
|
||||
// TODO: Fix the ui return type.
|
||||
ui: ui.collect as any[],
|
||||
timestamp: Date.now(),
|
||||
|
||||
@@ -15,7 +15,9 @@ export default function StockPrice(props: {
|
||||
apiUrl: "http://localhost:3123",
|
||||
});
|
||||
|
||||
const aiTool = thread.messages
|
||||
const messagesCopy = thread.messages;
|
||||
|
||||
const aiTool = messagesCopy
|
||||
.slice()
|
||||
.reverse()
|
||||
.find(
|
||||
|
||||
Reference in New Issue
Block a user