Skip to content

Commit

Permalink
Always use latest app state in message history
Browse files Browse the repository at this point in the history
  • Loading branch information
ppsreejith committed Nov 8, 2024
1 parent e195e3a commit b37b62b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
6 changes: 3 additions & 3 deletions web/src/components/devtools/LLMContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ export const LLMContext: React.FC<null> = () => {
const actionDescriptions = simplePlannerConfig.actionDescriptions
// append the last user message to the message history
let extendedMessageHistory = [...messageHistory, lastMessage]
const app = getApp()
const userAppState = app.getCachedState(thread) as AppState
const messages = appState ? getLLMContextFromState(prompts, userAppState, appState as AppState, extendedMessageHistory) : []
// const app = getApp()
// const userAppState = app.getCachedState(thread) as AppState
const messages = appState ? getLLMContextFromState(prompts, appState as AppState, appState as AppState, extendedMessageHistory) : []
const systemMessage = messages.length ? messages[0] : {}
const nonSystemMessages = messages.length ? messages.slice(1, messages.length - 1) : []

Expand Down
4 changes: 2 additions & 2 deletions web/src/planner/simplePlan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ export async function simplePlan(signal: AbortSignal, plannerConfig: SimplePlann
user: plannerConfig.userPrompt,
}
const currentAppState = await app.getState() as AppState
const appState = (app.getCachedState(thread) as AppState) || currentAppState
// const appState = (app.getCachedState(thread) as AppState) || currentAppState
const actionDescriptions = plannerConfig.actionDescriptions
const messages = getLLMContextFromState(prompts, appState, currentAppState, messageHistory)
const messages = getLLMContextFromState(prompts, currentAppState, currentAppState, messageHistory)
const llmResponse = await planActions({
messages,
actions: actionDescriptions,
Expand Down
46 changes: 23 additions & 23 deletions web/src/planner/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,29 +40,29 @@ export function getLLMContextFromState(
}
}

if (furtherMessages.length != 0) {
const latestMessage = structuredClone(furtherMessages[furtherMessages.length - 1])
if (latestMessage.content.type == 'BLANK') {
let content = latestMessage.content.content
try {
if (content) {
content = JSON.parse(content)
}
} catch (e) {
// do nothing
}
latestMessage.content.content = JSON.stringify({
content: content || '',
currentAppState
})
} else if (latestMessage.content.type == 'DEFAULT') {
latestMessage.content.text = JSON.stringify({
content: latestMessage.content.text || '',
currentAppState
})
}
furtherMessages[furtherMessages.length - 1] = latestMessage
}
// if (furtherMessages.length != 0) {
// const latestMessage = structuredClone(furtherMessages[furtherMessages.length - 1])
// if (latestMessage.content.type == 'BLANK') {
// let content = latestMessage.content.content
// try {
// if (content) {
// content = JSON.parse(content)
// }
// } catch (e) {
// // do nothing
// }
// latestMessage.content.content = JSON.stringify({
// content: content || '',
// currentAppState
// })
// } else if (latestMessage.content.type == 'DEFAULT') {
// latestMessage.content.text = JSON.stringify({
// content: latestMessage.content.text || '',
// currentAppState
// })
// }
// furtherMessages[furtherMessages.length - 1] = latestMessage
// }
earlierMessages.push(finalUserMessage)
// add furtherMessages to earlierMessages
earlierMessages.push(...furtherMessages)
Expand Down

0 comments on commit b37b62b

Please sign in to comment.