mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 19:00:59 +03:00
Conversation Starter: Changes to ensure that the chatbotConfig is not overwritten between the starter prompts and share chatbot dialogs
This commit is contained in:
@@ -106,6 +106,11 @@ export default function FlowListMenu({ chatflow, updateFlowsApi }) {
|
|||||||
setConversationStartersDialogOpen(true)
|
setConversationStartersDialogOpen(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const saveFlowStarterPrompts = async () => {
|
||||||
|
setConversationStartersDialogOpen(false)
|
||||||
|
await updateFlowsApi.request()
|
||||||
|
}
|
||||||
|
|
||||||
const saveFlowRename = async (chatflowName) => {
|
const saveFlowRename = async (chatflowName) => {
|
||||||
const updateBody = {
|
const updateBody = {
|
||||||
name: chatflowName,
|
name: chatflowName,
|
||||||
@@ -301,6 +306,7 @@ export default function FlowListMenu({ chatflow, updateFlowsApi }) {
|
|||||||
<StarterPromptsDialog
|
<StarterPromptsDialog
|
||||||
show={conversationStartersDialogOpen}
|
show={conversationStartersDialogOpen}
|
||||||
dialogProps={conversationStartersDialogProps}
|
dialogProps={conversationStartersDialogProps}
|
||||||
|
onConfirm={saveFlowStarterPrompts}
|
||||||
onCancel={() => setConversationStartersDialogOpen(false)}
|
onCancel={() => setConversationStartersDialogOpen(false)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import useNotifier from 'utils/useNotifier'
|
|||||||
// API
|
// API
|
||||||
import chatflowsApi from 'api/chatflows'
|
import chatflowsApi from 'api/chatflows'
|
||||||
|
|
||||||
const StarterPromptsDialog = ({ show, dialogProps, onCancel }) => {
|
const StarterPromptsDialog = ({ show, dialogProps, onCancel, onConfirm = undefined }) => {
|
||||||
const portalElement = document.getElementById('portal')
|
const portalElement = document.getElementById('portal')
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
|
|
||||||
@@ -44,6 +44,8 @@ const StarterPromptsDialog = ({ show, dialogProps, onCancel }) => {
|
|||||||
}
|
}
|
||||||
])
|
])
|
||||||
|
|
||||||
|
const [chatbotConfig, setChatbotConfig] = useState({})
|
||||||
|
|
||||||
const addInputField = () => {
|
const addInputField = () => {
|
||||||
setInputFields([
|
setInputFields([
|
||||||
...inputFields,
|
...inputFields,
|
||||||
@@ -72,8 +74,9 @@ const StarterPromptsDialog = ({ show, dialogProps, onCancel }) => {
|
|||||||
...inputFields
|
...inputFields
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
chatbotConfig.starterPrompts = value.starterPrompts
|
||||||
const saveResp = await chatflowsApi.updateChatflow(dialogProps.chatflow.id, {
|
const saveResp = await chatflowsApi.updateChatflow(dialogProps.chatflow.id, {
|
||||||
chatbotConfig: JSON.stringify(value)
|
chatbotConfig: JSON.stringify(chatbotConfig)
|
||||||
})
|
})
|
||||||
if (saveResp.data) {
|
if (saveResp.data) {
|
||||||
enqueueSnackbar({
|
enqueueSnackbar({
|
||||||
@@ -90,7 +93,9 @@ const StarterPromptsDialog = ({ show, dialogProps, onCancel }) => {
|
|||||||
})
|
})
|
||||||
dispatch({ type: SET_CHATFLOW, chatflow: saveResp.data })
|
dispatch({ type: SET_CHATFLOW, chatflow: saveResp.data })
|
||||||
}
|
}
|
||||||
onCancel()
|
if (onConfirm) {
|
||||||
|
onConfirm()
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const errorData = error.response.data || `${error.response.status}: ${error.response.statusText}`
|
const errorData = error.response.data || `${error.response.status}: ${error.response.statusText}`
|
||||||
enqueueSnackbar({
|
enqueueSnackbar({
|
||||||
@@ -113,6 +118,7 @@ const StarterPromptsDialog = ({ show, dialogProps, onCancel }) => {
|
|||||||
if (dialogProps.chatflow && dialogProps.chatflow.chatbotConfig) {
|
if (dialogProps.chatflow && dialogProps.chatflow.chatbotConfig) {
|
||||||
try {
|
try {
|
||||||
let chatbotConfig = JSON.parse(dialogProps.chatflow.chatbotConfig)
|
let chatbotConfig = JSON.parse(dialogProps.chatflow.chatbotConfig)
|
||||||
|
setChatbotConfig(chatbotConfig || {})
|
||||||
if (chatbotConfig.starterPrompts) {
|
if (chatbotConfig.starterPrompts) {
|
||||||
let inputFields = []
|
let inputFields = []
|
||||||
Object.getOwnPropertyNames(chatbotConfig.starterPrompts).forEach((key) => {
|
Object.getOwnPropertyNames(chatbotConfig.starterPrompts).forEach((key) => {
|
||||||
@@ -222,7 +228,8 @@ const StarterPromptsDialog = ({ show, dialogProps, onCancel }) => {
|
|||||||
StarterPromptsDialog.propTypes = {
|
StarterPromptsDialog.propTypes = {
|
||||||
show: PropTypes.bool,
|
show: PropTypes.bool,
|
||||||
dialogProps: PropTypes.object,
|
dialogProps: PropTypes.object,
|
||||||
onCancel: PropTypes.func
|
onCancel: PropTypes.func,
|
||||||
|
onConfirm: PropTypes.func
|
||||||
}
|
}
|
||||||
|
|
||||||
export default StarterPromptsDialog
|
export default StarterPromptsDialog
|
||||||
|
|||||||
@@ -135,6 +135,8 @@ const ShareChatbot = ({ isSessionMemory }) => {
|
|||||||
|
|
||||||
if (isSessionMemory) obj.overrideConfig.generateNewSession = generateNewSession
|
if (isSessionMemory) obj.overrideConfig.generateNewSession = generateNewSession
|
||||||
|
|
||||||
|
if (chatbotConfig?.starterPrompts) obj.starterPrompts = chatbotConfig.starterPrompts
|
||||||
|
|
||||||
return obj
|
return obj
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user