diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 965541a2bf0..13e630d60c0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -149,6 +149,7 @@ Flowise support different environment variables to configure your instance. You | SECRETKEY_PATH | Location where encryption key (used to encrypt/decrypt credentials) is saved | String | `your-path/Flowise/packages/server` | | FLOWISE_SECRETKEY_OVERWRITE | Encryption key to be used instead of the key stored in SECRETKEY_PATH | String | | | DISABLE_FLOWISE_TELEMETRY | Turn off telemetry | Boolean | | +| DISABLE_MESSAGE_SAVING | Turn off message saving to the database. Analytics integrations will still work if enabled. | Boolean | | | MODEL_LIST_CONFIG_JSON | File path to load list of models from your local config file | String | `/your_model_list_config_file_path` | | STORAGE_TYPE | Type of storage for uploaded files. default is `local` | Enum String: `s3`, `local` | `local` | | BLOB_STORAGE_PATH | Local folder path where uploaded files are stored when `STORAGE_TYPE` is `local` | String | `your-home-dir/.flowise/storage` | diff --git a/docker/.env.example b/docker/.env.example index 708431f75de..4a8d0be3b0d 100644 --- a/docker/.env.example +++ b/docker/.env.example @@ -36,6 +36,7 @@ BLOB_STORAGE_PATH=/root/.flowise/storage # LANGCHAIN_PROJECT=your_project # DISABLE_FLOWISE_TELEMETRY=true +# DISABLE_MESSAGE_SAVING=false # Uncomment the following line to enable model list config, load the list of models from your local config file # see https://raw.githubusercontent.com/FlowiseAI/Flowise/main/packages/components/models.json for the format diff --git a/packages/server/.env.example b/packages/server/.env.example index bd7845846ff..4d87887fc6c 100644 --- a/packages/server/.env.example +++ b/packages/server/.env.example @@ -36,6 +36,7 @@ PORT=3000 # LANGCHAIN_PROJECT=your_project # DISABLE_FLOWISE_TELEMETRY=true +# DISABLE_MESSAGE_SAVING=false # Uncomment the following line to enable model list config, load the list of models from your local config file # see https://raw.githubusercontent.com/FlowiseAI/Flowise/main/packages/components/models.json for the format diff --git a/packages/server/src/NodesPool.ts b/packages/server/src/NodesPool.ts index 0ec14b86ffa..2a89862accf 100644 --- a/packages/server/src/NodesPool.ts +++ b/packages/server/src/NodesPool.ts @@ -24,7 +24,16 @@ export class NodesPool { * Initialize nodes */ private async initializeNodes() { - const disabled_nodes = process.env.DISABLED_NODES ? process.env.DISABLED_NODES.split(',') : [] + let disabled_nodes = process.env.DISABLED_NODES ? process.env.DISABLED_NODES.split(',') : [] + if (process.env.DISABLE_MESSAGE_SAVING === 'true') { + disabled_nodes = disabled_nodes.concat([ + 'bufferMemory', + 'bufferWindowMemory', + 'conversationSummaryBufferMemory', + 'conversationSummaryMemory' + ]) + } + const packagePath = getNodeModulesPackagePath('flowise-components') const nodesPath = path.join(packagePath, 'dist', 'nodes') const nodeFiles = await this.getFiles(nodesPath) diff --git a/packages/server/src/commands/start.ts b/packages/server/src/commands/start.ts index 14478adab79..0430a006db3 100644 --- a/packages/server/src/commands/start.ts +++ b/packages/server/src/commands/start.ts @@ -48,6 +48,7 @@ export default class Start extends Command { LANGCHAIN_API_KEY: Flags.string(), LANGCHAIN_PROJECT: Flags.string(), DISABLE_FLOWISE_TELEMETRY: Flags.string(), + DISABLE_MESSAGE_SAVING: Flags.string(), MODEL_LIST_CONFIG_JSON: Flags.string(), STORAGE_TYPE: Flags.string(), S3_STORAGE_BUCKET_NAME: Flags.string(), @@ -144,6 +145,9 @@ export default class Start extends Command { // Telemetry if (flags.DISABLE_FLOWISE_TELEMETRY) process.env.DISABLE_FLOWISE_TELEMETRY = flags.DISABLE_FLOWISE_TELEMETRY + // Message logs + if (flags.DISABLE_MESSAGE_SAVING) process.env.DISABLE_MESSAGE_SAVING = flags.DISABLE_MESSAGE_SAVING + // Model list config if (flags.MODEL_LIST_CONFIG_JSON) process.env.MODEL_LIST_CONFIG_JSON = flags.MODEL_LIST_CONFIG_JSON diff --git a/packages/server/src/controllers/chat-messages/index.ts b/packages/server/src/controllers/chat-messages/index.ts index 0e914a474c7..d42b3bd3a62 100644 --- a/packages/server/src/controllers/chat-messages/index.ts +++ b/packages/server/src/controllers/chat-messages/index.ts @@ -33,6 +33,7 @@ const getFeedbackTypeFilters = (_feedbackTypeFilters: ChatMessageRatingType[]): } const createChatMessage = async (req: Request, res: Response, next: NextFunction) => { + // createChatMessage handles DISABLE_MESSAGE_SAVING check for us and will return null try { if (!req.body) { throw new InternalFlowiseError( @@ -41,6 +42,10 @@ const createChatMessage = async (req: Request, res: Response, next: NextFunction ) } const apiResponse = await chatMessagesService.createChatMessage(req.body) + if (apiResponse === null) { + return res.status(500).send('Error: chatMessagesController.createChatMessage - chat message storage disabled!') + } + return res.json(parseAPIResponse(apiResponse)) } catch (error) { next(error) @@ -48,6 +53,10 @@ const createChatMessage = async (req: Request, res: Response, next: NextFunction } const getAllChatMessages = async (req: Request, res: Response, next: NextFunction) => { + if (process.env.DISABLE_MESSAGE_SAVING === 'true') { + return res.status(500).send('Error: chatMessagesController.createChatMessage - chat message storage disabled!') + } + try { let chatTypeFilter = req.query?.chatType as ChatType | undefined if (chatTypeFilter) { diff --git a/packages/server/src/utils/addChatMesage.ts b/packages/server/src/utils/addChatMesage.ts index 887031bfcda..74fce5a2174 100644 --- a/packages/server/src/utils/addChatMesage.ts +++ b/packages/server/src/utils/addChatMesage.ts @@ -6,8 +6,13 @@ import { getRunningExpressApp } from '../utils/getRunningExpressApp' * Method that add chat messages. * @param {Partial} chatMessage */ -export const utilAddChatMessage = async (chatMessage: Partial): Promise => { +export const utilAddChatMessage = async (chatMessage: Partial): Promise => { const appServer = getRunningExpressApp() + + if (process.env.DISABLE_MESSAGE_SAVING === 'true') { + return null + } + const newChatMessage = new ChatMessage() Object.assign(newChatMessage, chatMessage) if (!newChatMessage.createdDate) { diff --git a/packages/ui/src/ui-component/dialog/ViewMessagesDialog.jsx b/packages/ui/src/ui-component/dialog/ViewMessagesDialog.jsx index 7daab109849..ecba5238120 100644 --- a/packages/ui/src/ui-component/dialog/ViewMessagesDialog.jsx +++ b/packages/ui/src/ui-component/dialog/ViewMessagesDialog.jsx @@ -672,10 +672,12 @@ const ViewMessagesDialog = ({ show, dialogProps, onCancel }) => { getChatmessageFromPKApi.request(dialogProps.chatflow.id, transformChatPKToParams(chatPK)) } } + } else if (getChatmessageApi.error) { + setChatLogs(null) } // eslint-disable-next-line react-hooks/exhaustive-deps - }, [getChatmessageApi.data]) + }, [getChatmessageApi.data, getChatmessageApi.error]) useEffect(() => { if (getStatsApi.data) { @@ -935,6 +937,19 @@ const ViewMessagesDialog = ({ show, dialogProps, onCancel }) => { />
+ {chatlogs == null && ( + + + msgEmptySVG + +
Messages logs are disabled.
+
Please reconfigure your Flowise instance or enable an analytics integration
+
+ )} {chatlogs && chatlogs.length == 0 && (