-
-
Notifications
You must be signed in to change notification settings - Fork 24.4k
feat: add session_history variable to Follow Up Prompts #6397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
859dc5f
35691ae
3320eff
156edee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -662,12 +662,25 @@ export const executeFlow = async ({ | |
|
|
||
| if (agentflow.followUpPrompts) { | ||
| const followUpPromptsConfig = JSON.parse(agentflow.followUpPrompts) | ||
| const generatedFollowUpPrompts = await generateFollowUpPrompts(followUpPromptsConfig, apiMessage.content, { | ||
| chatId, | ||
| chatflowid: agentflow.id, | ||
| appDataSource, | ||
| databaseEntities | ||
| }) | ||
| // Format session history for the prompt | ||
| const formattedSessionHistory = chatHistory | ||
| .map((msg) => { | ||
| const role = msg.type === 'apiMessage' ? 'Assistant' : 'User' | ||
| const content = msg.message || msg.content || '' | ||
| return `${role}: ${content}` | ||
| }) | ||
| .join('\n') | ||
|
Comment on lines
+666
to
+672
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| const generatedFollowUpPrompts = await generateFollowUpPrompts( | ||
| followUpPromptsConfig, | ||
| apiMessage.content, | ||
| { | ||
| chatId, | ||
| chatflowid: agentflow.id, | ||
| appDataSource, | ||
| databaseEntities | ||
| }, | ||
| formattedSessionHistory | ||
| ) | ||
| if (generatedFollowUpPrompts?.questions) { | ||
| apiMessage.followUpPrompts = JSON.stringify(generatedFollowUpPrompts.questions) | ||
| } | ||
|
|
@@ -875,12 +888,25 @@ export const executeFlow = async ({ | |
| if (result?.action) apiMessage.action = typeof result.action === 'string' ? result.action : JSON.stringify(result.action) | ||
| if (chatflow.followUpPrompts) { | ||
| const followUpPromptsConfig = JSON.parse(chatflow.followUpPrompts) | ||
| const followUpPrompts = await generateFollowUpPrompts(followUpPromptsConfig, apiMessage.content, { | ||
| chatId, | ||
| chatflowid, | ||
| appDataSource, | ||
| databaseEntities | ||
| }) | ||
| // Format session history for the prompt | ||
| const formattedSessionHistory = chatHistory | ||
| .map((msg) => { | ||
| const role = msg.type === 'apiMessage' ? 'Assistant' : 'User' | ||
| const content = msg.message || msg.content || '' | ||
| return `${role}: ${content}` | ||
| }) | ||
| .join('\n') | ||
| const followUpPrompts = await generateFollowUpPrompts( | ||
| followUpPromptsConfig, | ||
| apiMessage.content, | ||
| { | ||
| chatId, | ||
| chatflowid, | ||
| appDataSource, | ||
| databaseEntities | ||
| }, | ||
| formattedSessionHistory | ||
| ) | ||
| if (followUpPrompts?.questions) { | ||
| apiMessage.followUpPrompts = JSON.stringify(followUpPrompts.questions) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -115,7 +115,9 @@ export const utilGetChatMessage = async ({ | |||||||||
| }, | ||||||||||
| order: { | ||||||||||
| createdDate: sortOrder === 'DESC' ? 'DESC' : 'ASC' | ||||||||||
| } | ||||||||||
| }, | ||||||||||
| skip: page > -1 && pageSize > -1 ? page * pageSize : undefined, | ||||||||||
| take: page > -1 && pageSize > -1 ? pageSize : undefined | ||||||||||
|
Comment on lines
+119
to
+120
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The pagination logic here is inconsistent with
Suggested change
|
||||||||||
| }) | ||||||||||
|
|
||||||||||
| return messages | ||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of
.replace()only substitutes the first occurrence of the placeholder. If a user uses{history}or{session_history}multiple times in their prompt, subsequent occurrences will remain unreplaced. Additionally, using a string as the second argument to.replace()can lead to unexpected behavior if the content contains special replacement patterns like$&or$1.It is recommended to use
.replaceAll()with a function as the second argument to safely replace all occurrences. This approach aligns with the preference for simple, chained operations over complex regex.References