fix message reversing

This commit is contained in:
bracesproul
2025-02-28 14:15:37 -08:00
parent 3f4aad48e6
commit a15a9104b4
6 changed files with 57 additions and 129 deletions

View File

@@ -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],