mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 19:00:59 +03:00
Merge branch 'main' into feature/FlowiseMultiDatabaseSupport
This commit is contained in:
@@ -3,7 +3,7 @@ PORT=3000
|
||||
# FLOWISE_PASSWORD=1234
|
||||
# DEBUG=true
|
||||
# APIKEY_PATH=/your_api_key_path/.flowise
|
||||
# LOG_PATH=/your_log_path/logs
|
||||
# LOG_PATH=/your_log_path/.flowise/logs
|
||||
# LOG_LEVEL=debug (error | warn | info | verbose | debug)
|
||||
# EXECUTION_MODE=main (child | main)
|
||||
|
||||
@@ -18,4 +18,7 @@ DATABASE_TYPE="sqlite" # sqlite, mysql, postgres
|
||||
# DATABASE_HOST="127.0.0.1"
|
||||
# DATABASE_NAME="flowise"
|
||||
# DATABASE_USER="root"
|
||||
# DATABASE_PASSWORD="atish123"
|
||||
# DATABASE_PASSWORD="atish123"
|
||||
|
||||
# TOOL_FUNCTION_BUILTIN_DEP=crypto,fs
|
||||
# TOOL_FUNCTION_EXTERNAL_DEP=moment,lodash
|
||||
|
||||
+21
-19
@@ -31,26 +31,28 @@ FLOWISE_PASSWORD=1234
|
||||
|
||||
## 🌱 Env Variables
|
||||
|
||||
Flowise support different environment variables to configure your instance. You can specify the following variables in the `.env` file inside `packages/server` folder.
|
||||
Flowise support different environment variables to configure your instance. You can specify the following variables in the `.env` file inside `packages/server` folder. Read [more](https://docs.flowiseai.com/environment-variables)
|
||||
|
||||
| Variable | Description | Type | Default |
|
||||
| ---------------- | ---------------------------------------------------------------- | ------------------------------------------------ | ----------------------------------- |
|
||||
| PORT | The HTTP port Flowise runs on | Number | 3000 |
|
||||
| FLOWISE_USERNAME | Username to login | String |
|
||||
| FLOWISE_PASSWORD | Password to login | String |
|
||||
| DEBUG | Print logs from components | Boolean |
|
||||
| LOG_PATH | Location where log files are stored | String | `your-path/Flowise/logs` |
|
||||
| LOG_LEVEL | Different levels of logs | Enum String: `error`, `info`, `verbose`, `debug` | `info` |
|
||||
| APIKEY_PATH | Location where api keys are saved | String | `your-path/Flowise/packages/server` |
|
||||
| EXECUTION_MODE | Whether predictions run in their own process or the main process | Enum String: `child`, `main` | `main` |
|
||||
| OVERRIDE_DATABASE| Override current database with default | Enum String: `true`, `false` | `true` |
|
||||
| DATABASE_TYPE | Type of database to store the flowise data | Enum String: `sqlite`, `mysql`, `postgres` | `sqlite` |
|
||||
| DATABASE_PATH | Location where database is saved (When DATABASE_TYPE is sqlite) | String | `your-home-dir/.flowise` |
|
||||
| DATABASE_HOST | Host URL or IP address (When DATABASE_TYPE is not sqlite) | String | |
|
||||
| DATABASE_PORT | Database port (When DATABASE_TYPE is not sqlite) | String | |
|
||||
| DATABASE_USERNAME| Database username (When DATABASE_TYPE is not sqlite) | String | |
|
||||
| DATABASE_PASSWORD| Database password (When DATABASE_TYPE is not sqlite) | String | |
|
||||
| DATABASE_NAME | Database name (When DATABASE_TYPE is not sqlite) | String | |
|
||||
| Variable | Description | Type | Default |
|
||||
| ---------------- | ---------------------------------------------------------------- | ------------------------------------------------ | ----------------------------------- |
|
||||
| PORT | The HTTP port Flowise runs on | Number | 3000 |
|
||||
| FLOWISE_USERNAME | Username to login | String | |
|
||||
| FLOWISE_PASSWORD | Password to login | String | |
|
||||
| DEBUG | Print logs from components | Boolean | |
|
||||
| LOG_PATH | Location where log files are stored | String | `your-path/Flowise/logs` |
|
||||
| LOG_LEVEL | Different levels of logs | Enum String: `error`, `info`, `verbose`, `debug` | `info` |
|
||||
| APIKEY_PATH | Location where api keys are saved | String | `your-path/Flowise/packages/server` |
|
||||
| EXECUTION_MODE | Whether predictions run in their own process or the main process | Enum String: `child`, `main` | `main` |
|
||||
| TOOL_FUNCTION_BUILTIN_DEP | NodeJS built-in modules to be used for Tool Function | String | |
|
||||
| TOOL_FUNCTION_EXTERNAL_DEP | External modules to be used for Tool Function | String | |
|
||||
| OVERRIDE_DATABASE | Override current database with default | Enum String: `true`, `false` | `true` |
|
||||
| DATABASE_TYPE | Type of database to store the flowise data | Enum String: `sqlite`, `mysql`, `postgres` | `sqlite` |
|
||||
| DATABASE_PATH | Location where database is saved (When DATABASE_TYPE is sqlite) | String | `your-home-dir/.flowise` |
|
||||
| DATABASE_HOST | Host URL or IP address (When DATABASE_TYPE is not sqlite) | String | |
|
||||
| DATABASE_PORT | Database port (When DATABASE_TYPE is not sqlite) | String | |
|
||||
| DATABASE_USERNAME | Database username (When DATABASE_TYPE is not sqlite) | String | |
|
||||
| DATABASE_PASSWORD | Database password (When DATABASE_TYPE is not sqlite) | String | |
|
||||
| DATABASE_NAME | Database name (When DATABASE_TYPE is not sqlite) | String | |
|
||||
|
||||
You can also specify the env variables when using `npx`. For example:
|
||||
|
||||
|
||||
@@ -24,7 +24,9 @@ export default class Start extends Command {
|
||||
APIKEY_PATH: Flags.string(),
|
||||
LOG_PATH: Flags.string(),
|
||||
LOG_LEVEL: Flags.string(),
|
||||
EXECUTION_MODE: Flags.string()
|
||||
EXECUTION_MODE: Flags.string(),
|
||||
TOOL_FUNCTION_BUILTIN_DEP: Flags.string(),
|
||||
TOOL_FUNCTION_EXTERNAL_DEP: Flags.string()
|
||||
}
|
||||
|
||||
async stopProcess() {
|
||||
@@ -65,6 +67,8 @@ export default class Start extends Command {
|
||||
if (flags.LOG_LEVEL) process.env.LOG_LEVEL = flags.LOG_LEVEL
|
||||
if (flags.EXECUTION_MODE) process.env.EXECUTION_MODE = flags.EXECUTION_MODE
|
||||
if (flags.DEBUG) process.env.DEBUG = flags.DEBUG
|
||||
if (flags.TOOL_FUNCTION_BUILTIN_DEP) process.env.TOOL_FUNCTION_BUILTIN_DEP = flags.TOOL_FUNCTION_BUILTIN_DEP
|
||||
if (flags.TOOL_FUNCTION_EXTERNAL_DEP) process.env.TOOL_FUNCTION_EXTERNAL_DEP = flags.TOOL_FUNCTION_EXTERNAL_DEP
|
||||
|
||||
await (async () => {
|
||||
try {
|
||||
|
||||
@@ -39,7 +39,8 @@ import {
|
||||
isFlowValidForStream,
|
||||
isVectorStoreFaiss,
|
||||
databaseEntities,
|
||||
getApiKey
|
||||
getApiKey,
|
||||
clearSessionMemory
|
||||
} from './utils'
|
||||
import { cloneDeep } from 'lodash'
|
||||
import { getDataSource } from './DataSource'
|
||||
@@ -59,9 +60,6 @@ export class App {
|
||||
|
||||
constructor() {
|
||||
this.app = express()
|
||||
|
||||
// Add the expressRequestLogger middleware to log all requests
|
||||
this.app.use(expressRequestLogger)
|
||||
}
|
||||
|
||||
async initDatabase() {
|
||||
@@ -92,6 +90,9 @@ export class App {
|
||||
// Allow access from *
|
||||
this.app.use(cors())
|
||||
|
||||
// Add the expressRequestLogger middleware to log all requests
|
||||
this.app.use(expressRequestLogger)
|
||||
|
||||
if (process.env.FLOWISE_USERNAME && process.env.FLOWISE_PASSWORD) {
|
||||
const username = process.env.FLOWISE_USERNAME
|
||||
const password = process.env.FLOWISE_PASSWORD
|
||||
@@ -306,8 +307,13 @@ export class App {
|
||||
|
||||
// Get all chatmessages from chatflowid
|
||||
this.app.get('/api/v1/chatmessage/:id', async (req: Request, res: Response) => {
|
||||
const chatmessages = await this.AppDataSource.getRepository(ChatMessage).findBy({
|
||||
chatflowid: req.params.id
|
||||
const chatmessages = await this.AppDataSource.getRepository(ChatMessage).find({
|
||||
where: {
|
||||
chatflowid: req.params.id
|
||||
},
|
||||
order: {
|
||||
createdDate: 'ASC'
|
||||
}
|
||||
})
|
||||
return res.json(chatmessages)
|
||||
})
|
||||
@@ -326,6 +332,19 @@ export class App {
|
||||
|
||||
// Delete all chatmessages from chatflowid
|
||||
this.app.delete('/api/v1/chatmessage/:id', async (req: Request, res: Response) => {
|
||||
const chatflow = await this.AppDataSource.getRepository(ChatFlow).findOneBy({
|
||||
id: req.params.id
|
||||
})
|
||||
if (!chatflow) {
|
||||
res.status(404).send(`Chatflow ${req.params.id} not found`)
|
||||
return
|
||||
}
|
||||
const flowData = chatflow.flowData
|
||||
const parsedFlowData: IReactFlowObject = JSON.parse(flowData)
|
||||
const nodes = parsedFlowData.nodes
|
||||
let chatId = await getChatId(chatflow.id)
|
||||
if (!chatId) chatId = chatflow.id
|
||||
clearSessionMemory(nodes, this.nodesPool.componentNodes, chatId, req.query.sessionId as string)
|
||||
const results = await this.AppDataSource.getRepository(ChatMessage).delete({ chatflowid: req.params.id })
|
||||
return res.json(results)
|
||||
})
|
||||
@@ -668,7 +687,7 @@ export class App {
|
||||
if (!chatflow) return res.status(404).send(`Chatflow ${chatflowid} not found`)
|
||||
|
||||
let chatId = await getChatId(chatflow.id)
|
||||
if (!chatId) chatId = Date.now().toString()
|
||||
if (!chatId) chatId = chatflowid
|
||||
|
||||
if (!isInternal) {
|
||||
await this.validateKey(req, res, chatflow)
|
||||
|
||||
@@ -7,7 +7,7 @@ dotenv.config({ path: path.join(__dirname, '..', '..', '.env'), override: true }
|
||||
|
||||
// default config
|
||||
const loggingConfig = {
|
||||
dir: process.env.LOG_PATH ?? path.join(__dirname, '..', '..', '..', '..', 'logs'),
|
||||
dir: process.env.LOG_PATH ?? path.join(__dirname, '..', '..', 'logs'),
|
||||
server: {
|
||||
level: process.env.LOG_LEVEL ?? 'info',
|
||||
filename: 'server.log',
|
||||
|
||||
@@ -273,6 +273,29 @@ export const buildLangchain = async (
|
||||
return flowNodes
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear memory
|
||||
* @param {IReactFlowNode[]} reactFlowNodes
|
||||
* @param {IComponentNodes} componentNodes
|
||||
* @param {string} chatId
|
||||
* @param {string} sessionId
|
||||
*/
|
||||
export const clearSessionMemory = async (
|
||||
reactFlowNodes: IReactFlowNode[],
|
||||
componentNodes: IComponentNodes,
|
||||
chatId: string,
|
||||
sessionId?: string
|
||||
) => {
|
||||
for (const node of reactFlowNodes) {
|
||||
if (node.data.category !== 'Memory') continue
|
||||
const nodeInstanceFilePath = componentNodes[node.data.name].filePath as string
|
||||
const nodeModule = await import(nodeInstanceFilePath)
|
||||
const newNodeInstance = new nodeModule.nodeClass()
|
||||
if (sessionId && node.data.inputs) node.data.inputs.sessionId = sessionId
|
||||
if (newNodeInstance.clearSessionMemory) await newNodeInstance?.clearSessionMemory(node.data, { chatId })
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get variable value from outputResponses.output
|
||||
* @param {string} paramValue
|
||||
|
||||
@@ -57,43 +57,46 @@ const logger = createLogger({
|
||||
* this.app.use(expressRequestLogger)
|
||||
*/
|
||||
export function expressRequestLogger(req: Request, res: Response, next: NextFunction): void {
|
||||
const fileLogger = createLogger({
|
||||
format: combine(timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), format.json(), errors({ stack: true })),
|
||||
defaultMeta: {
|
||||
package: 'server',
|
||||
request: {
|
||||
method: req.method,
|
||||
url: req.url,
|
||||
body: req.body,
|
||||
query: req.query,
|
||||
params: req.params,
|
||||
headers: req.headers
|
||||
}
|
||||
},
|
||||
transports: [
|
||||
new transports.File({
|
||||
filename: path.join(logDir, config.logging.express.filename ?? 'server-requests.log.jsonl'),
|
||||
level: config.logging.express.level ?? 'debug'
|
||||
})
|
||||
]
|
||||
})
|
||||
const unwantedLogURLs = ['/api/v1/node-icon/']
|
||||
if (req.url.includes('/api/v1/') && !unwantedLogURLs.some((url) => req.url.includes(url))) {
|
||||
const fileLogger = createLogger({
|
||||
format: combine(timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), format.json(), errors({ stack: true })),
|
||||
defaultMeta: {
|
||||
package: 'server',
|
||||
request: {
|
||||
method: req.method,
|
||||
url: req.url,
|
||||
body: req.body,
|
||||
query: req.query,
|
||||
params: req.params,
|
||||
headers: req.headers
|
||||
}
|
||||
},
|
||||
transports: [
|
||||
new transports.File({
|
||||
filename: path.join(logDir, config.logging.express.filename ?? 'server-requests.log.jsonl'),
|
||||
level: config.logging.express.level ?? 'debug'
|
||||
})
|
||||
]
|
||||
})
|
||||
|
||||
const getRequestEmoji = (method: string) => {
|
||||
const requetsEmojis: Record<string, string> = {
|
||||
GET: '⬇️',
|
||||
POST: '⬆️',
|
||||
PUT: '🖊',
|
||||
DELETE: '❌'
|
||||
const getRequestEmoji = (method: string) => {
|
||||
const requetsEmojis: Record<string, string> = {
|
||||
GET: '⬇️',
|
||||
POST: '⬆️',
|
||||
PUT: '🖊',
|
||||
DELETE: '❌'
|
||||
}
|
||||
|
||||
return requetsEmojis[method] || '?'
|
||||
}
|
||||
|
||||
return requetsEmojis[method] || '?'
|
||||
}
|
||||
|
||||
if (req.method !== 'GET') {
|
||||
fileLogger.info(`${getRequestEmoji(req.method)} ${req.method} ${req.url}`)
|
||||
logger.info(`${getRequestEmoji(req.method)} ${req.method} ${req.url}`)
|
||||
} else {
|
||||
fileLogger.http(`${getRequestEmoji(req.method)} ${req.method} ${req.url}`)
|
||||
if (req.method !== 'GET') {
|
||||
fileLogger.info(`${getRequestEmoji(req.method)} ${req.method} ${req.url}`)
|
||||
logger.info(`${getRequestEmoji(req.method)} ${req.method} ${req.url}`)
|
||||
} else {
|
||||
fileLogger.http(`${getRequestEmoji(req.method)} ${req.method} ${req.url}`)
|
||||
}
|
||||
}
|
||||
|
||||
next()
|
||||
|
||||
Reference in New Issue
Block a user