Skip to content
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

Disable message saving to DB via an environment variable #3837

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
Expand Down
1 change: 1 addition & 0 deletions docker/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions packages/server/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion packages/server/src/NodesPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions packages/server/src/commands/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions packages/server/src/controllers/chat-messages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -41,13 +42,21 @@ 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)
}
}

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) {
Expand Down
7 changes: 6 additions & 1 deletion packages/server/src/utils/addChatMesage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ import { getRunningExpressApp } from '../utils/getRunningExpressApp'
* Method that add chat messages.
* @param {Partial<IChatMessage>} chatMessage
*/
export const utilAddChatMessage = async (chatMessage: Partial<IChatMessage>): Promise<ChatMessage> => {
export const utilAddChatMessage = async (chatMessage: Partial<IChatMessage>): Promise<ChatMessage | null> => {
const appServer = getRunningExpressApp()

if (process.env.DISABLE_MESSAGE_SAVING === 'true') {
return null
}

const newChatMessage = new ChatMessage()
Object.assign(newChatMessage, chatMessage)
if (!newChatMessage.createdDate) {
Expand Down
17 changes: 16 additions & 1 deletion packages/ui/src/ui-component/dialog/ViewMessagesDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -935,6 +937,19 @@ const ViewMessagesDialog = ({ show, dialogProps, onCancel }) => {
/>
</div>
<div style={{ display: 'flex', flexDirection: 'row' }}>
{chatlogs == null && (
<Stack sx={{ alignItems: 'center', justifyContent: 'center', width: '100%' }} flexDirection='column'>
<Box sx={{ p: 5, height: 'auto' }}>
<img
style={{ objectFit: 'cover', height: '20vh', width: 'auto' }}
src={msgEmptySVG}
alt='msgEmptySVG'
/>
</Box>
<div>Messages logs are disabled.</div>
<div>Please reconfigure your Flowise instance or enable an analytics integration</div>
</Stack>
)}
{chatlogs && chatlogs.length == 0 && (
<Stack sx={{ alignItems: 'center', justifyContent: 'center', width: '100%' }} flexDirection='column'>
<Box sx={{ p: 5, height: 'auto' }}>
Expand Down
Loading