From 31fc8f37dbe6e75eddcd0e404ef1d3570b416735 Mon Sep 17 00:00:00 2001 From: chungyau97 Date: Mon, 28 Aug 2023 18:41:17 +0800 Subject: [PATCH 01/53] rate limit poc --- packages/server/package.json | 1 + packages/server/src/index.ts | 18 ++++++++- packages/server/src/utils/rateLimit.ts | 56 ++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 packages/server/src/utils/rateLimit.ts diff --git a/packages/server/package.json b/packages/server/package.json index 4d50ddc4..9b9b7dbd 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -52,6 +52,7 @@ "dotenv": "^16.0.0", "express": "^4.17.3", "express-basic-auth": "^1.2.1", + "express-rate-limit": "^6.9.0", "flowise-components": "*", "flowise-ui": "*", "moment-timezone": "^0.5.34", diff --git a/packages/server/src/index.ts b/packages/server/src/index.ts index 66c7b000..15709ad9 100644 --- a/packages/server/src/index.ts +++ b/packages/server/src/index.ts @@ -1,4 +1,4 @@ -import express, { Request, Response } from 'express' +import express, { NextFunction, Request, Response } from 'express' import multer from 'multer' import path from 'path' import cors from 'cors' @@ -54,6 +54,7 @@ import { Credential } from './entity/Credential' import { Tool } from './entity/Tool' import { ChatflowPool } from './ChatflowPool' import { ICommonObject, INodeOptionsValue } from 'flowise-components' +import { createRateLimiter, getRateLimiter } from './utils/rateLimit' export class App { app: express.Application @@ -654,6 +655,21 @@ export class App { // Prediction // ---------------------------------------- + this.app.get( + '/api/v1/rate-limit/:id', + upload.array('files'), + (req: Request, res: Response, next: NextFunction) => getRateLimiter(req, res, next), + // specificRouteLimiter, + async (req: Request, res: Response) => { + res.send("you're fine") + } + ) + + this.app.post('/api/v1/rate-limit/', async (req: Request, res: Response) => { + createRateLimiter(req) + res.send('Created/Updated rate limit') + }) + // Send input message and get prediction result (External) this.app.post('/api/v1/prediction/:id', upload.array('files'), async (req: Request, res: Response) => { await this.processPrediction(req, res, socketIO) diff --git a/packages/server/src/utils/rateLimit.ts b/packages/server/src/utils/rateLimit.ts new file mode 100644 index 00000000..0bd5be98 --- /dev/null +++ b/packages/server/src/utils/rateLimit.ts @@ -0,0 +1,56 @@ +import { NextFunction, Request, Response } from 'express' +import { rateLimit, RateLimitRequestHandler } from 'express-rate-limit' + +interface RateLimit { + id: string + rateLimitObj: RateLimitRequestHandler +} + +export const specificRouteLimiter: RateLimitRequestHandler = rateLimit({ + windowMs: 1 * 60 * 1000, // 15 minutes + max: 1, // Limit each IP to 100 requests per windowMs + message: 'Too many requests, please try again later.' +}) + +let rateLimiters: RateLimit[] = [] + +export function createRateLimiter(req: Request) { + const id = req.body.id + const duration = req.body.duration + const limit = req.body.limit + const message = req.body.message + + const rateLimitObj: RateLimitRequestHandler = rateLimit({ + windowMs: Number(duration), + max: limit, + handler: (req, res) => { + res.status(429).json({ error: message }) + } + }) + + const existingIndex: number = rateLimiters.findIndex((rateLimit) => rateLimit.id === id) + + if (existingIndex === -1) { + rateLimiters.push({ + id, + rateLimitObj + }) + } else { + rateLimiters[existingIndex] = { + id, + rateLimitObj + } + } +} + +export function getRateLimiter(req: Request, res: Response, next: NextFunction) { + const id = req.params.id + + const ratelimiter = rateLimiters.find((rateLimit) => rateLimit.id === id) + + if (!ratelimiter) return next() + + const idRateLimiter = ratelimiter.rateLimitObj + + return idRateLimiter(req, res, next) +} From 1b75121d5e1939aba7b22fddcb9f4550ad93ec41 Mon Sep 17 00:00:00 2001 From: chungyau97 Date: Wed, 30 Aug 2023 21:35:16 +0800 Subject: [PATCH 02/53] init rateLimiter --- packages/server/package.json | 1 + packages/server/src/Interface.ts | 3 ++ packages/server/src/entity/ChatFlow.ts | 9 ++++ packages/server/src/index.ts | 60 +++++++++++++++++------- packages/server/src/utils/rateLimit.ts | 65 ++++++++++---------------- 5 files changed, 80 insertions(+), 58 deletions(-) diff --git a/packages/server/package.json b/packages/server/package.json index 9b9b7dbd..4d4293b0 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -46,6 +46,7 @@ "license": "SEE LICENSE IN LICENSE.md", "dependencies": { "@oclif/core": "^1.13.10", + "async-mutex": "^0.4.0", "axios": "^0.27.2", "cors": "^2.8.5", "crypto-js": "^4.1.1", diff --git a/packages/server/src/Interface.ts b/packages/server/src/Interface.ts index 92e3054d..a83e556e 100644 --- a/packages/server/src/Interface.ts +++ b/packages/server/src/Interface.ts @@ -15,6 +15,9 @@ export interface IChatFlow { isPublic?: boolean apikeyid?: string chatbotConfig?: string + rateLimit?: number + rateLimitDuration?: number + rateLimitMsg?: string } export interface IChatMessage { diff --git a/packages/server/src/entity/ChatFlow.ts b/packages/server/src/entity/ChatFlow.ts index 4c37e083..e8ed861b 100644 --- a/packages/server/src/entity/ChatFlow.ts +++ b/packages/server/src/entity/ChatFlow.ts @@ -25,6 +25,15 @@ export class ChatFlow implements IChatFlow { @Column({ nullable: true }) chatbotConfig?: string + @Column({ nullable: true }) + rateLimit?: number + + @Column({ nullable: true }) + rateLimitDuration?: number + + @Column({ nullable: true }) + rateLimitMsg?: string + @CreateDateColumn() createdDate: Date diff --git a/packages/server/src/index.ts b/packages/server/src/index.ts index 15709ad9..f6df0c30 100644 --- a/packages/server/src/index.ts +++ b/packages/server/src/index.ts @@ -54,7 +54,7 @@ import { Credential } from './entity/Credential' import { Tool } from './entity/Tool' import { ChatflowPool } from './ChatflowPool' import { ICommonObject, INodeOptionsValue } from 'flowise-components' -import { createRateLimiter, getRateLimiter } from './utils/rateLimit' +import { createRateLimiter, getRateLimiter, initializeRateLimiter } from './utils/rateLimit' export class App { app: express.Application @@ -84,6 +84,10 @@ export class App { // Initialize encryption key await getEncryptionKey() + + // Initialize Rate Limit + const AllChatFlow: IChatFlow[] = await getAllChatFlow() + await initializeRateLimiter(AllChatFlow) }) .catch((err) => { logger.error('❌ [server]: Error during Data Source initialization:', err) @@ -246,7 +250,7 @@ export class App { // Get all chatflows this.app.get('/api/v1/chatflows', async (req: Request, res: Response) => { - const chatflows: IChatFlow[] = await this.AppDataSource.getRepository(ChatFlow).find() + const chatflows: IChatFlow[] = await getAllChatFlow() return res.json(chatflows) }) @@ -655,21 +659,6 @@ export class App { // Prediction // ---------------------------------------- - this.app.get( - '/api/v1/rate-limit/:id', - upload.array('files'), - (req: Request, res: Response, next: NextFunction) => getRateLimiter(req, res, next), - // specificRouteLimiter, - async (req: Request, res: Response) => { - res.send("you're fine") - } - ) - - this.app.post('/api/v1/rate-limit/', async (req: Request, res: Response) => { - createRateLimiter(req) - res.send('Created/Updated rate limit') - }) - // Send input message and get prediction result (External) this.app.post('/api/v1/prediction/:id', upload.array('files'), async (req: Request, res: Response) => { await this.processPrediction(req, res, socketIO) @@ -768,6 +757,39 @@ export class App { } }) + // ---------------------------------------- + // Rate Limit + // ---------------------------------------- + + this.app.get( + '/api/v1/rate-limit/:id', + upload.array('files'), + (req: Request, res: Response, next: NextFunction) => getRateLimiter(req, res, next), + // specificRouteLimiter, + async (req: Request, res: Response) => { + res.send("you're fine") + } + ) + + this.app.post('/api/v1/rate-limit/', async (req: Request, res: Response) => { + const id = req.body.id + const duration = req.body.duration + const limit = req.body.limit + const message = req.body.message + + const result = await getDataSource() + .getRepository(ChatFlow) + .createQueryBuilder() + .update(ChatFlow) + .set({ rateLimit: limit, rateLimitDuration: duration, rateLimitMsg: message }) + .where('id = :id', { id: id }) + .execute() + + await createRateLimiter(id, Number(duration), Number(limit), message) + + res.send({ result }) + }) + // ---------------------------------------- // Serve UI static // ---------------------------------------- @@ -1012,6 +1034,10 @@ export async function getChatId(chatflowid: string) { let serverApp: App | undefined +export async function getAllChatFlow(): Promise { + return await getDataSource().getRepository(ChatFlow).find() +} + export async function start(): Promise { serverApp = new App() diff --git a/packages/server/src/utils/rateLimit.ts b/packages/server/src/utils/rateLimit.ts index 0bd5be98..882964c4 100644 --- a/packages/server/src/utils/rateLimit.ts +++ b/packages/server/src/utils/rateLimit.ts @@ -1,56 +1,39 @@ import { NextFunction, Request, Response } from 'express' import { rateLimit, RateLimitRequestHandler } from 'express-rate-limit' +import { IChatFlow } from '../Interface' +import { Mutex } from 'async-mutex' -interface RateLimit { - id: string - rateLimitObj: RateLimitRequestHandler -} +let rateLimiters: Record = {} +const rateLimiterMutex = new Mutex() -export const specificRouteLimiter: RateLimitRequestHandler = rateLimit({ - windowMs: 1 * 60 * 1000, // 15 minutes - max: 1, // Limit each IP to 100 requests per windowMs - message: 'Too many requests, please try again later.' -}) - -let rateLimiters: RateLimit[] = [] - -export function createRateLimiter(req: Request) { - const id = req.body.id - const duration = req.body.duration - const limit = req.body.limit - const message = req.body.message - - const rateLimitObj: RateLimitRequestHandler = rateLimit({ - windowMs: Number(duration), - max: limit, - handler: (req, res) => { - res.status(429).json({ error: message }) - } - }) - - const existingIndex: number = rateLimiters.findIndex((rateLimit) => rateLimit.id === id) - - if (existingIndex === -1) { - rateLimiters.push({ - id, - rateLimitObj +export async function createRateLimiter(id: string, duration: number, limit: number, message: string) { + const release = await rateLimiterMutex.acquire() + try { + rateLimiters[id] = rateLimit({ + windowMs: duration, + max: limit, + handler: (req, res) => { + res.status(429).json({ error: message }) + } }) - } else { - rateLimiters[existingIndex] = { - id, - rateLimitObj - } + } finally { + release() } } export function getRateLimiter(req: Request, res: Response, next: NextFunction) { const id = req.params.id - const ratelimiter = rateLimiters.find((rateLimit) => rateLimit.id === id) + if (!rateLimiters[id]) return next() - if (!ratelimiter) return next() - - const idRateLimiter = ratelimiter.rateLimitObj + const idRateLimiter = rateLimiters[id] return idRateLimiter(req, res, next) } + +export async function initializeRateLimiter(ChatFlowPool: IChatFlow[]) { + await ChatFlowPool.map(async (ChatFlow) => { + if (ChatFlow.rateLimitDuration && ChatFlow.rateLimit && ChatFlow.rateLimitMsg) + await createRateLimiter(ChatFlow.id, ChatFlow.rateLimitDuration, ChatFlow.rateLimit, ChatFlow.rateLimitMsg) + }) +} From a58adcadf1087cb6d858b90647611fba57fcfa76 Mon Sep 17 00:00:00 2001 From: chungyau97 Date: Wed, 30 Aug 2023 21:43:42 +0800 Subject: [PATCH 03/53] add rateLimiter to prediction --- packages/server/src/index.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/server/src/index.ts b/packages/server/src/index.ts index f6df0c30..b72cbaa1 100644 --- a/packages/server/src/index.ts +++ b/packages/server/src/index.ts @@ -660,9 +660,14 @@ export class App { // ---------------------------------------- // Send input message and get prediction result (External) - this.app.post('/api/v1/prediction/:id', upload.array('files'), async (req: Request, res: Response) => { - await this.processPrediction(req, res, socketIO) - }) + this.app.post( + '/api/v1/prediction/:id', + upload.array('files'), + (req: Request, res: Response, next: NextFunction) => getRateLimiter(req, res, next), + async (req: Request, res: Response) => { + await this.processPrediction(req, res, socketIO) + } + ) // Send input message and get prediction result (Internal) this.app.post('/api/v1/internal-prediction/:id', async (req: Request, res: Response) => { @@ -765,7 +770,6 @@ export class App { '/api/v1/rate-limit/:id', upload.array('files'), (req: Request, res: Response, next: NextFunction) => getRateLimiter(req, res, next), - // specificRouteLimiter, async (req: Request, res: Response) => { res.send("you're fine") } From cbf17b3624566a87dbb5c8196fa5a590c375e7eb Mon Sep 17 00:00:00 2001 From: chungyau97 Date: Thu, 31 Aug 2023 00:45:15 +0800 Subject: [PATCH 04/53] standardize rate limit return error message --- packages/server/src/utils/rateLimit.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server/src/utils/rateLimit.ts b/packages/server/src/utils/rateLimit.ts index 882964c4..25222afd 100644 --- a/packages/server/src/utils/rateLimit.ts +++ b/packages/server/src/utils/rateLimit.ts @@ -13,7 +13,7 @@ export async function createRateLimiter(id: string, duration: number, limit: num windowMs: duration, max: limit, handler: (req, res) => { - res.status(429).json({ error: message }) + res.status(429).send(message) } }) } finally { From d03108d0ac1b53179bf46794edf1499973f2ff2d Mon Sep 17 00:00:00 2001 From: Yavisht Katgara Date: Fri, 1 Sep 2023 11:46:37 +1000 Subject: [PATCH 05/53] feat: dateTime marketplace tool --- .../server/marketplaces/tools/Get Current DateTime.json | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 packages/server/marketplaces/tools/Get Current DateTime.json diff --git a/packages/server/marketplaces/tools/Get Current DateTime.json b/packages/server/marketplaces/tools/Get Current DateTime.json new file mode 100644 index 00000000..b6860b30 --- /dev/null +++ b/packages/server/marketplaces/tools/Get Current DateTime.json @@ -0,0 +1,8 @@ +{ + "name": "todays_date_time", + "description": "Useful to get todays day, date and time.", + "color": "linear-gradient(rgb(117,118,129), rgb(230,10,250))", + "iconSrc": "https://raw.githubusercontent.com/gilbarbara/logos/main/logos/javascript.svg", + "schema": "[]", + "func": "const timeZone = 'Australia/Sydney';\nconst options = {\n timeZone: timeZone,\n year: 'numeric',\n month: 'long',\n day: 'numeric',\n weekday: 'long',\n hour: '2-digit',\n minute: '2-digit',\n second: '2-digit',\n hour12: true\n};\nconst today = new Date();\nconst formattedDate = today.toLocaleString('en-GB', options);\nconst result = {\n \"formattedDate\": formattedDate,\n \"timezone\": timeZone\n};\nreturn JSON.stringify(result);\n" +} From 8f83bb670093ebe4befda15905f8426969da0d3a Mon Sep 17 00:00:00 2001 From: Henry Date: Fri, 1 Sep 2023 10:59:38 +0100 Subject: [PATCH 06/53] removed CLA from contributing md --- CONTRIBUTING.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 90ba5498..05925b1e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -156,10 +156,6 @@ npx flowise start --PORT=3000 --DEBUG=true A member of the FlowiseAI team will automatically be notified/assigned when you open a pull request. You can also reach out to us on [Discord](https://discord.gg/jbaHfsRVBW). -## 📃 Contributor License Agreement - -Before we can merge your contribution you have to sign our [Contributor License Agreement (CLA)](https://cla-assistant.io/FlowiseAI/Flowise). The CLA contains the terms and conditions under which the contribution is submitted. You need to do this only once for your first pull request. Keep in mind that without a signed CLA we cannot merge your contribution. - ## 📜 Code of Conduct This project and everyone participating in it are governed by the Code of Conduct which can be found in the [file](CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code. Please report unacceptable behavior to hello@flowiseai.com. From 607415c663868b82d4cb87fa5ae26ad110f81879 Mon Sep 17 00:00:00 2001 From: chungyau97 Date: Sat, 2 Sep 2023 13:28:47 +0800 Subject: [PATCH 07/53] add API Configuration UI --- packages/ui/src/assets/images/settings.svg | 5 + .../ui/src/views/chatflows/APICodeDialog.js | 9 +- .../ui/src/views/chatflows/Configuration.js | 145 ++++++++++++++++++ 3 files changed, 157 insertions(+), 2 deletions(-) create mode 100644 packages/ui/src/assets/images/settings.svg create mode 100644 packages/ui/src/views/chatflows/Configuration.js diff --git a/packages/ui/src/assets/images/settings.svg b/packages/ui/src/assets/images/settings.svg new file mode 100644 index 00000000..4f4dfc09 --- /dev/null +++ b/packages/ui/src/assets/images/settings.svg @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/packages/ui/src/views/chatflows/APICodeDialog.js b/packages/ui/src/views/chatflows/APICodeDialog.js index 0ae8a8f4..49c718cc 100644 --- a/packages/ui/src/views/chatflows/APICodeDialog.js +++ b/packages/ui/src/views/chatflows/APICodeDialog.js @@ -34,6 +34,7 @@ import javascriptSVG from 'assets/images/javascript.svg' import cURLSVG from 'assets/images/cURL.svg' import EmbedSVG from 'assets/images/embed.svg' import ShareChatbotSVG from 'assets/images/sharing.png' +import settingsSVG from 'assets/images/settings.svg' // API import apiKeyApi from 'api/apikey' @@ -46,6 +47,7 @@ import { CheckboxInput } from 'ui-component/checkbox/Checkbox' import { TableViewOnly } from 'ui-component/table/Table' import { IconBulb } from '@tabler/icons' +import Configuration from './Configuration' function TabPanel(props) { const { children, value, index, ...other } = props @@ -141,7 +143,7 @@ const APICodeDialog = ({ show, dialogProps, onCancel }) => { const navigate = useNavigate() const dispatch = useDispatch() - const codes = ['Embed', 'Python', 'JavaScript', 'cURL', 'Share Chatbot'] + const codes = ['Embed', 'Python', 'JavaScript', 'cURL', 'Share Chatbot', 'Configuration'] const [value, setValue] = useState(0) const [keyOptions, setKeyOptions] = useState([]) const [apiKeys, setAPIKeys] = useState([]) @@ -321,6 +323,8 @@ query({"question": "Hey, how are you?"}).then((response) => { return cURLSVG } else if (codeLang === 'Share Chatbot') { return ShareChatbotSVG + } else if (codeLang === 'Configuration') { + return settingsSVG } return pythonSVG } @@ -647,7 +651,7 @@ formData.append("openAIApiKey[openAIEmbeddings_0]", "sk-my-openai-2nd-key")` )} {codeLang === 'Embed' && !chatflowApiKeyId && } - {codeLang !== 'Embed' && codeLang !== 'Share Chatbot' && ( + {codeLang !== 'Embed' && codeLang !== 'Share Chatbot' && codeLang !== 'Configuration' && ( <> )} + {codeLang === 'Configuration' && } ))} diff --git a/packages/ui/src/views/chatflows/Configuration.js b/packages/ui/src/views/chatflows/Configuration.js new file mode 100644 index 00000000..d5f4bbf9 --- /dev/null +++ b/packages/ui/src/views/chatflows/Configuration.js @@ -0,0 +1,145 @@ +import { useState } from 'react' +import { useDispatch, useSelector } from 'react-redux' +import { enqueueSnackbar as enqueueSnackbarAction, closeSnackbar as closeSnackbarAction, SET_CHATFLOW } from 'store/actions' +import PropTypes from 'prop-types' + +import { Box, Typography, Button, OutlinedInput } from '@mui/material' + +// Project import +import { StyledButton } from 'ui-component/button/StyledButton' + +// Icons +import { IconX } from '@tabler/icons' + +// API +import chatflowsApi from 'api/chatflows' + +// utils +import useNotifier from 'utils/useNotifier' + +const Configuration = () => { + const dispatch = useDispatch() + const chatflow = useSelector((state) => state.canvas.chatflow) + const chatflowid = chatflow.id + const apiConfig = chatflow.apiConfig ? JSON.parse(chatflow.apiConfig) : {} + + useNotifier() + + const enqueueSnackbar = (...args) => dispatch(enqueueSnackbarAction(...args)) + const closeSnackbar = (...args) => dispatch(closeSnackbarAction(...args)) + + const [limitMax, setLimitMax] = useState(apiConfig?.rateLimit?.limitMax ?? 20) + const [limitDuration, setLimitDuration] = useState(apiConfig?.rateLimit?.limitDuration ?? 120) + const [limitMsg, setLimitMsg] = useState(apiConfig?.rateLimit?.limitMsg ?? "Please don't spam me") + + const formatObj = () => { + const obj = { + rateLimit: {} + } + + if (limitMax && limitDuration && limitMsg) + obj.rateLimit = { + limitMax, + limitDuration, + limitMsg + } + + return obj + } + + const onSave = async () => { + try { + const saveResp = await chatflowsApi.updateChatflow(chatflowid, { + apiConfig: JSON.stringify(formatObj()) + }) + if (saveResp.data) { + enqueueSnackbar({ + message: 'API Configuration Saved', + options: { + key: new Date().getTime() + Math.random(), + variant: 'success', + action: (key) => ( + + ) + } + }) + dispatch({ type: SET_CHATFLOW, chatflow: saveResp.data }) + } + } catch (error) { + console.error(error) + const errorData = error.response.data || `${error.response.status}: ${error.response.statusText}` + enqueueSnackbar({ + message: `Failed to save API Configuration: ${errorData}`, + options: { + key: new Date().getTime() + Math.random(), + variant: 'error', + persist: true, + action: (key) => ( + + ) + } + }) + } + } + + const onTextChanged = (value, fieldName) => { + switch (fieldName) { + case 'limitMax': + setLimitMax(value) + break + case 'limitDuration': + setLimitDuration(value) + break + case 'limitMsg': + setLimitMsg(value) + break + } + } + + const textField = (message, fieldName, fieldLabel, fieldType = 'string', placeholder = '') => { + return ( + +
+ {fieldLabel} + { + onTextChanged(e.target.value, fieldName) + }} + /> +
+
+ ) + } + + return ( + <> + {/*Rate Limit*/} + + Rate Limit + + {textField(limitMax, 'Limit Max', 'Max Limit', 'number')} + {textField(limitDuration, 'Limit Duration', 'Font Size', 'number')} + {textField(limitMsg, 'limitMsg', 'Limit Message', 'string')} + + onSave()}> + Save Changes + + + ) +} + +Configuration.propTypes = { + isSessionMemory: PropTypes.bool +} + +export default Configuration From 34dd7a3a3d00915b7411e644d54059fe1becc32b Mon Sep 17 00:00:00 2001 From: chungyau97 Date: Sat, 2 Sep 2023 14:59:33 +0800 Subject: [PATCH 08/53] modify rateLimit data storage --- packages/server/src/Interface.ts | 4 +-- packages/server/src/entity/ChatFlow.ts | 8 +---- packages/server/src/index.ts | 35 ++----------------- packages/server/src/utils/rateLimit.ts | 20 +++++++---- .../ui/src/views/chatflows/Configuration.js | 4 +-- 5 files changed, 21 insertions(+), 50 deletions(-) diff --git a/packages/server/src/Interface.ts b/packages/server/src/Interface.ts index a83e556e..42c1231a 100644 --- a/packages/server/src/Interface.ts +++ b/packages/server/src/Interface.ts @@ -15,9 +15,7 @@ export interface IChatFlow { isPublic?: boolean apikeyid?: string chatbotConfig?: string - rateLimit?: number - rateLimitDuration?: number - rateLimitMsg?: string + apiConfig?: any } export interface IChatMessage { diff --git a/packages/server/src/entity/ChatFlow.ts b/packages/server/src/entity/ChatFlow.ts index e8ed861b..2be09155 100644 --- a/packages/server/src/entity/ChatFlow.ts +++ b/packages/server/src/entity/ChatFlow.ts @@ -26,13 +26,7 @@ export class ChatFlow implements IChatFlow { chatbotConfig?: string @Column({ nullable: true }) - rateLimit?: number - - @Column({ nullable: true }) - rateLimitDuration?: number - - @Column({ nullable: true }) - rateLimitMsg?: string + apiConfig?: string @CreateDateColumn() createdDate: Date diff --git a/packages/server/src/index.ts b/packages/server/src/index.ts index b72cbaa1..82e32bdb 100644 --- a/packages/server/src/index.ts +++ b/packages/server/src/index.ts @@ -319,6 +319,9 @@ export class App { const updateChatFlow = new ChatFlow() Object.assign(updateChatFlow, body) + updateChatFlow.id = chatflow.id + createRateLimiter(updateChatFlow) + this.AppDataSource.getRepository(ChatFlow).merge(chatflow, updateChatFlow) const result = await this.AppDataSource.getRepository(ChatFlow).save(chatflow) @@ -762,38 +765,6 @@ export class App { } }) - // ---------------------------------------- - // Rate Limit - // ---------------------------------------- - - this.app.get( - '/api/v1/rate-limit/:id', - upload.array('files'), - (req: Request, res: Response, next: NextFunction) => getRateLimiter(req, res, next), - async (req: Request, res: Response) => { - res.send("you're fine") - } - ) - - this.app.post('/api/v1/rate-limit/', async (req: Request, res: Response) => { - const id = req.body.id - const duration = req.body.duration - const limit = req.body.limit - const message = req.body.message - - const result = await getDataSource() - .getRepository(ChatFlow) - .createQueryBuilder() - .update(ChatFlow) - .set({ rateLimit: limit, rateLimitDuration: duration, rateLimitMsg: message }) - .where('id = :id', { id: id }) - .execute() - - await createRateLimiter(id, Number(duration), Number(limit), message) - - res.send({ result }) - }) - // ---------------------------------------- // Serve UI static // ---------------------------------------- diff --git a/packages/server/src/utils/rateLimit.ts b/packages/server/src/utils/rateLimit.ts index 25222afd..b1cd1819 100644 --- a/packages/server/src/utils/rateLimit.ts +++ b/packages/server/src/utils/rateLimit.ts @@ -6,11 +6,11 @@ import { Mutex } from 'async-mutex' let rateLimiters: Record = {} const rateLimiterMutex = new Mutex() -export async function createRateLimiter(id: string, duration: number, limit: number, message: string) { +async function addRateLimiter(id: string, duration: number, limit: number, message: string) { const release = await rateLimiterMutex.acquire() try { rateLimiters[id] = rateLimit({ - windowMs: duration, + windowMs: duration * 1000, max: limit, handler: (req, res) => { res.status(429).send(message) @@ -31,9 +31,17 @@ export function getRateLimiter(req: Request, res: Response, next: NextFunction) return idRateLimiter(req, res, next) } -export async function initializeRateLimiter(ChatFlowPool: IChatFlow[]) { - await ChatFlowPool.map(async (ChatFlow) => { - if (ChatFlow.rateLimitDuration && ChatFlow.rateLimit && ChatFlow.rateLimitMsg) - await createRateLimiter(ChatFlow.id, ChatFlow.rateLimitDuration, ChatFlow.rateLimit, ChatFlow.rateLimitMsg) +export async function createRateLimiter(chatFlow: IChatFlow) { + if (!chatFlow.apiConfig) return + const apiConfig: any = JSON.parse(chatFlow.apiConfig) + const rateLimit: { limitDuration: number; limitMax: number; limitMsg: string } = apiConfig.rateLimit + if (!rateLimit) return + const { limitDuration, limitMax, limitMsg } = rateLimit + if (limitMax && limitDuration && limitMsg) await addRateLimiter(chatFlow.id, limitDuration, limitMax, limitMsg) +} + +export async function initializeRateLimiter(chatFlowPool: IChatFlow[]) { + await chatFlowPool.map(async (chatFlow) => { + await createRateLimiter(chatFlow) }) } diff --git a/packages/ui/src/views/chatflows/Configuration.js b/packages/ui/src/views/chatflows/Configuration.js index d5f4bbf9..b49b87e7 100644 --- a/packages/ui/src/views/chatflows/Configuration.js +++ b/packages/ui/src/views/chatflows/Configuration.js @@ -127,8 +127,8 @@ const Configuration = () => { Rate Limit - {textField(limitMax, 'Limit Max', 'Max Limit', 'number')} - {textField(limitDuration, 'Limit Duration', 'Font Size', 'number')} + {textField(limitMax, 'limitMax', 'Message Limit per Duration', 'number')} + {textField(limitDuration, 'limitDuration', 'Duration in Second', 'number')} {textField(limitMsg, 'limitMsg', 'Limit Message', 'string')} onSave()}> From 49f8e796f43e72c4901c42abff46dca9bb97fa08 Mon Sep 17 00:00:00 2001 From: chungyau97 Date: Sat, 2 Sep 2023 15:48:04 +0800 Subject: [PATCH 09/53] fix UI no data show default value --- packages/ui/src/views/chatflows/Configuration.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/ui/src/views/chatflows/Configuration.js b/packages/ui/src/views/chatflows/Configuration.js index b49b87e7..4268fd08 100644 --- a/packages/ui/src/views/chatflows/Configuration.js +++ b/packages/ui/src/views/chatflows/Configuration.js @@ -36,13 +36,17 @@ const Configuration = () => { const obj = { rateLimit: {} } - - if (limitMax && limitDuration && limitMsg) + const rateLimitValuesBoolean = [!limitMax, !limitDuration, !limitMsg] + const rateLimitFilledValues = rateLimitValuesBoolean.filter((value) => value === false) + if (rateLimitFilledValues.length >= 1 && rateLimitFilledValues.length <= 2) { + throw new Error('Need to fill all rate limit input fields') + } else if (rateLimitFilledValues.length === 3) { obj.rateLimit = { limitMax, limitDuration, limitMsg } + } return obj } @@ -69,7 +73,9 @@ const Configuration = () => { } } catch (error) { console.error(error) - const errorData = error.response.data || `${error.response.status}: ${error.response.statusText}` + const errorData = error.response + ? error.response.data || `${error.response.status}: ${error.response.statusText}` + : error.message enqueueSnackbar({ message: `Failed to save API Configuration: ${errorData}`, options: { From 3f0c6339e13497cd578c1f2306b6fbd98f63c574 Mon Sep 17 00:00:00 2001 From: chungyau97 Date: Sat, 2 Sep 2023 21:52:20 +0800 Subject: [PATCH 10/53] swap URL to get Confluence access token directly --- packages/components/credentials/ConfluenceApi.credential.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/components/credentials/ConfluenceApi.credential.ts b/packages/components/credentials/ConfluenceApi.credential.ts index a1d32e9c..371201a0 100644 --- a/packages/components/credentials/ConfluenceApi.credential.ts +++ b/packages/components/credentials/ConfluenceApi.credential.ts @@ -12,7 +12,7 @@ class ConfluenceApi implements INodeCredential { this.name = 'confluenceApi' this.version = 1.0 this.description = - 'Refer to official guide on how to get accessToken on Confluence' + 'Refer here to get accessToken on Confluence' this.inputs = [ { label: 'Access Token', From a05d73d83b245e29cc51d723c8d998aa445923eb Mon Sep 17 00:00:00 2001 From: Yongtae Date: Sun, 3 Sep 2023 19:12:42 +0900 Subject: [PATCH 11/53] Add input option for Model Name in GoogleVertexAIEmbedding --- .../GoogleVertexAIEmbedding.ts | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts index fdf7ea97..ad86ff5f 100644 --- a/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts +++ b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts @@ -33,11 +33,35 @@ class GoogleVertexAIEmbedding_Embeddings implements INode { description: 'Google Vertex AI credential. If you are using a GCP service like Cloud Run, or if you have installed default credentials on your local machine, you do not need to set this credential.' } - this.inputs = [] + this.inputs = [ + { + label: 'Model Name', + name: 'modelName', + type: 'options', + options: [ + { + label: 'textembedding-gecko@001', + name: 'textembedding-gecko@001' + }, + { + label: 'textembedding-gecko@latest', + name: 'textembedding-gecko@latest' + }, + { + label: 'textembedding-gecko-multilingual@latest', + name: 'textembedding-gecko-multilingual@latest' + } + ], + default: 'textembedding-gecko@001', + optional: true, + additionalParams: true + } + ] } async init(nodeData: INodeData, _: string, options: ICommonObject): Promise { const credentialData = await getCredentialData(nodeData.credential ?? '', options) + const modelName = nodeData.inputs?.modelName ?? 'textembedding-gecko@001' const googleApplicationCredentialFilePath = getCredentialParam('googleApplicationCredentialFilePath', credentialData, nodeData) const googleApplicationCredential = getCredentialParam('googleApplicationCredential', credentialData, nodeData) const projectID = getCredentialParam('projectID', credentialData, nodeData) @@ -58,7 +82,9 @@ class GoogleVertexAIEmbedding_Embeddings implements INode { if (projectID) authOptions.projectId = projectID } - const obj: GoogleVertexAIEmbeddingsParams = {} + const obj: GoogleVertexAIEmbeddingsParams = { + model: modelName + } if (Object.keys(authOptions).length !== 0) obj.authOptions = authOptions const model = new GoogleVertexAIEmbeddings(obj) From 0b67afe54667744d8f3895eaeccc02bf04facb4a Mon Sep 17 00:00:00 2001 From: Yongtae Date: Sun, 3 Sep 2023 19:16:45 +0900 Subject: [PATCH 12/53] Refactor modelName assignment in GoogleVertexAIEmbedding.ts --- .../GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts index ad86ff5f..61518ceb 100644 --- a/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts +++ b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts @@ -61,7 +61,7 @@ class GoogleVertexAIEmbedding_Embeddings implements INode { async init(nodeData: INodeData, _: string, options: ICommonObject): Promise { const credentialData = await getCredentialData(nodeData.credential ?? '', options) - const modelName = nodeData.inputs?.modelName ?? 'textembedding-gecko@001' + const modelName = nodeData.inputs?.modelName as string const googleApplicationCredentialFilePath = getCredentialParam('googleApplicationCredentialFilePath', credentialData, nodeData) const googleApplicationCredential = getCredentialParam('googleApplicationCredential', credentialData, nodeData) const projectID = getCredentialParam('projectID', credentialData, nodeData) From 4d8b24180c048cbaf1dd2746c72fd416d747245b Mon Sep 17 00:00:00 2001 From: Yongtae Date: Sun, 3 Sep 2023 19:27:00 +0900 Subject: [PATCH 13/53] add 32k model --- .../ChatGoogleVertexAI/ChatGoogleVertexAI.ts | 8 ++++++++ .../nodes/llms/GoogleVertexAI/GoogleVertexAI.ts | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/packages/components/nodes/chatmodels/ChatGoogleVertexAI/ChatGoogleVertexAI.ts b/packages/components/nodes/chatmodels/ChatGoogleVertexAI/ChatGoogleVertexAI.ts index a7ac4259..1bc06f4b 100644 --- a/packages/components/nodes/chatmodels/ChatGoogleVertexAI/ChatGoogleVertexAI.ts +++ b/packages/components/nodes/chatmodels/ChatGoogleVertexAI/ChatGoogleVertexAI.ts @@ -46,6 +46,14 @@ class GoogleVertexAI_ChatModels implements INode { { label: 'codechat-bison', name: 'codechat-bison' + }, + { + label: 'chat-bison-32k', + name: 'chat-bison-32k' + }, + { + label: 'codechat-bison-32k', + name: 'codechat-bison-32k' } ], default: 'chat-bison', diff --git a/packages/components/nodes/llms/GoogleVertexAI/GoogleVertexAI.ts b/packages/components/nodes/llms/GoogleVertexAI/GoogleVertexAI.ts index b379ad47..4d19d04f 100644 --- a/packages/components/nodes/llms/GoogleVertexAI/GoogleVertexAI.ts +++ b/packages/components/nodes/llms/GoogleVertexAI/GoogleVertexAI.ts @@ -50,6 +50,18 @@ class GoogleVertexAI_LLMs implements INode { { label: 'code-gecko', name: 'code-gecko' + }, + { + label: 'text-bison-32k', + name: 'text-bison-32k' + }, + { + label: 'code-bison-32k', + name: 'code-bison-32k' + }, + { + label: 'code-gecko-32k', + name: 'code-gecko-32k' } ], default: 'text-bison' From 1505e72dd1908dd0eae85b32163727a6892737c9 Mon Sep 17 00:00:00 2001 From: chungyau97 Date: Mon, 4 Sep 2023 08:57:48 +0800 Subject: [PATCH 14/53] add API Key URL instead of swap URL --- packages/components/credentials/ConfluenceApi.credential.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/components/credentials/ConfluenceApi.credential.ts b/packages/components/credentials/ConfluenceApi.credential.ts index 371201a0..656ecf6b 100644 --- a/packages/components/credentials/ConfluenceApi.credential.ts +++ b/packages/components/credentials/ConfluenceApi.credential.ts @@ -12,7 +12,7 @@ class ConfluenceApi implements INodeCredential { this.name = 'confluenceApi' this.version = 1.0 this.description = - 'Refer here to get accessToken on Confluence' + 'Refer to official guide on how to get Access Token or API Token on Confluence' this.inputs = [ { label: 'Access Token', From 95740a84647d597b96ef8d9b78e21d7761874164 Mon Sep 17 00:00:00 2001 From: Yongtae Date: Mon, 4 Sep 2023 11:01:56 +0900 Subject: [PATCH 15/53] Refactor GoogleVertexAIEmbedding.ts to remove unnecessary additionalParams field --- .../GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts index 61518ceb..3cbd600a 100644 --- a/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts +++ b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts @@ -53,8 +53,7 @@ class GoogleVertexAIEmbedding_Embeddings implements INode { } ], default: 'textembedding-gecko@001', - optional: true, - additionalParams: true + optional: true } ] } From a373422abf93fdb2ca92d52f5c9e4dc42f008fde Mon Sep 17 00:00:00 2001 From: Yongtae Date: Mon, 4 Sep 2023 11:02:35 +0900 Subject: [PATCH 16/53] Refactor GoogleVertexAIEmbedding.ts for handling modelName in GoogleVertexAIEmbeddingsParams --- .../GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts index 3cbd600a..7d086e0c 100644 --- a/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts +++ b/packages/components/nodes/embeddings/GoogleVertexAIEmbedding/GoogleVertexAIEmbedding.ts @@ -81,9 +81,8 @@ class GoogleVertexAIEmbedding_Embeddings implements INode { if (projectID) authOptions.projectId = projectID } - const obj: GoogleVertexAIEmbeddingsParams = { - model: modelName - } + const obj: GoogleVertexAIEmbeddingsParams = {} + if (modelName) obj.model = modelName if (Object.keys(authOptions).length !== 0) obj.authOptions = authOptions const model = new GoogleVertexAIEmbeddings(obj) From 008f1a95f15a09b2892a1071526919f9605bde1d Mon Sep 17 00:00:00 2001 From: chungyau97 Date: Mon, 4 Sep 2023 17:14:49 +0800 Subject: [PATCH 17/53] init migration poc --- packages/server/src/DataSource.ts | 31 ++++++++++--------- .../{entity => database/entities}/ChatFlow.ts | 2 +- .../entities}/ChatMessage.ts | 2 +- .../entities}/Credential.ts | 2 +- .../src/{entity => database/entities}/Tool.ts | 2 +- .../server/src/database/entities/index.ts | 11 +++++++ .../migrations/1693809869231-initSqlite.ts | 29 +++++++++++++++++ packages/server/src/index.ts | 13 +++++--- packages/server/src/utils/index.ts | 8 ++--- 9 files changed, 73 insertions(+), 27 deletions(-) rename packages/server/src/{entity => database/entities}/ChatFlow.ts (93%) rename packages/server/src/{entity => database/entities}/ChatMessage.ts (88%) rename packages/server/src/{entity => database/entities}/Credential.ts (90%) rename packages/server/src/{entity => database/entities}/Tool.ts (93%) create mode 100644 packages/server/src/database/entities/index.ts create mode 100644 packages/server/src/database/migrations/1693809869231-initSqlite.ts diff --git a/packages/server/src/DataSource.ts b/packages/server/src/DataSource.ts index b0d56477..a1d37996 100644 --- a/packages/server/src/DataSource.ts +++ b/packages/server/src/DataSource.ts @@ -1,26 +1,24 @@ import 'reflect-metadata' import path from 'path' import { DataSource } from 'typeorm' -import { ChatFlow } from './entity/ChatFlow' -import { ChatMessage } from './entity/ChatMessage' -import { Credential } from './entity/Credential' -import { Tool } from './entity/Tool' import { getUserHome } from './utils' +import { entities } from './database/entities' +import { InitSqlite1693809869231 } from './database/migrations/1693809869231-initSqlite' let appDataSource: DataSource export const init = async (): Promise => { let homePath - const synchronize = process.env.OVERRIDE_DATABASE === 'false' ? false : true switch (process.env.DATABASE_TYPE) { case 'sqlite': homePath = process.env.DATABASE_PATH ?? path.join(getUserHome(), '.flowise') appDataSource = new DataSource({ type: 'sqlite', database: path.resolve(homePath, 'database.sqlite'), - synchronize, - entities: [ChatFlow, ChatMessage, Tool, Credential], - migrations: [] + synchronize: false, + migrationsRun: false, + entities: Object.values(entities), + migrations: [InitSqlite1693809869231] }) break case 'mysql': @@ -32,8 +30,9 @@ export const init = async (): Promise => { password: process.env.DATABASE_PASSWORD, database: process.env.DATABASE_NAME, charset: 'utf8mb4', - synchronize, - entities: [ChatFlow, ChatMessage, Tool, Credential], + synchronize: false, + migrationsRun: false, + entities: Object.values(entities), migrations: [] }) break @@ -45,8 +44,9 @@ export const init = async (): Promise => { username: process.env.DATABASE_USER, password: process.env.DATABASE_PASSWORD, database: process.env.DATABASE_NAME, - synchronize, - entities: [ChatFlow, ChatMessage, Tool, Credential], + synchronize: false, + migrationsRun: false, + entities: Object.values(entities), migrations: [] }) break @@ -55,9 +55,10 @@ export const init = async (): Promise => { appDataSource = new DataSource({ type: 'sqlite', database: path.resolve(homePath, 'database.sqlite'), - synchronize, - entities: [ChatFlow, ChatMessage, Tool, Credential], - migrations: [] + synchronize: false, + migrationsRun: false, + entities: Object.values(entities), + migrations: [InitSqlite1693809869231] }) break } diff --git a/packages/server/src/entity/ChatFlow.ts b/packages/server/src/database/entities/ChatFlow.ts similarity index 93% rename from packages/server/src/entity/ChatFlow.ts rename to packages/server/src/database/entities/ChatFlow.ts index 4c37e083..a1a32a88 100644 --- a/packages/server/src/entity/ChatFlow.ts +++ b/packages/server/src/database/entities/ChatFlow.ts @@ -1,6 +1,6 @@ /* eslint-disable */ import { Entity, Column, CreateDateColumn, UpdateDateColumn, PrimaryGeneratedColumn } from 'typeorm' -import { IChatFlow } from '../Interface' +import { IChatFlow } from '../../Interface' @Entity() export class ChatFlow implements IChatFlow { diff --git a/packages/server/src/entity/ChatMessage.ts b/packages/server/src/database/entities/ChatMessage.ts similarity index 88% rename from packages/server/src/entity/ChatMessage.ts rename to packages/server/src/database/entities/ChatMessage.ts index 8123020c..23804846 100644 --- a/packages/server/src/entity/ChatMessage.ts +++ b/packages/server/src/database/entities/ChatMessage.ts @@ -1,6 +1,6 @@ /* eslint-disable */ import { Entity, Column, CreateDateColumn, PrimaryGeneratedColumn, Index } from 'typeorm' -import { IChatMessage, MessageType } from '../Interface' +import { IChatMessage, MessageType } from '../../Interface' @Entity() export class ChatMessage implements IChatMessage { diff --git a/packages/server/src/entity/Credential.ts b/packages/server/src/database/entities/Credential.ts similarity index 90% rename from packages/server/src/entity/Credential.ts rename to packages/server/src/database/entities/Credential.ts index b724eed6..e77711dc 100644 --- a/packages/server/src/entity/Credential.ts +++ b/packages/server/src/database/entities/Credential.ts @@ -1,6 +1,6 @@ /* eslint-disable */ import { Entity, Column, PrimaryGeneratedColumn, Index, CreateDateColumn, UpdateDateColumn } from 'typeorm' -import { ICredential } from '../Interface' +import { ICredential } from '../../Interface' @Entity() export class Credential implements ICredential { diff --git a/packages/server/src/entity/Tool.ts b/packages/server/src/database/entities/Tool.ts similarity index 93% rename from packages/server/src/entity/Tool.ts rename to packages/server/src/database/entities/Tool.ts index 011bf957..d459eee3 100644 --- a/packages/server/src/entity/Tool.ts +++ b/packages/server/src/database/entities/Tool.ts @@ -1,6 +1,6 @@ /* eslint-disable */ import { Entity, Column, CreateDateColumn, UpdateDateColumn, PrimaryGeneratedColumn } from 'typeorm' -import { ITool } from '../Interface' +import { ITool } from '../../Interface' @Entity() export class Tool implements ITool { diff --git a/packages/server/src/database/entities/index.ts b/packages/server/src/database/entities/index.ts new file mode 100644 index 00000000..ff109863 --- /dev/null +++ b/packages/server/src/database/entities/index.ts @@ -0,0 +1,11 @@ +import { ChatFlow } from './ChatFlow' +import { ChatMessage } from './ChatMessage' +import { Credential } from './Credential' +import { Tool } from './Tool' + +export const entities = { + ChatFlow, + ChatMessage, + Credential, + Tool +} diff --git a/packages/server/src/database/migrations/1693809869231-initSqlite.ts b/packages/server/src/database/migrations/1693809869231-initSqlite.ts new file mode 100644 index 00000000..78af741d --- /dev/null +++ b/packages/server/src/database/migrations/1693809869231-initSqlite.ts @@ -0,0 +1,29 @@ +import { MigrationInterface, QueryRunner } from 'typeorm' + +export class InitSqlite1693809869231 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + console.info('started migration query') + await queryRunner.query( + `CREATE TABLE "chat_flow" ("id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, "flowData" text NOT NULL, "deployed" boolean, "isPublic" boolean, "apikeyid" varchar, "chatbotConfig" varchar, "createdDate" datetime NOT NULL DEFAULT (datetime('now')), "updatedDate" datetime NOT NULL DEFAULT (datetime('now')));` + ) + await queryRunner.query( + `CREATE TABLE "chat_message" ("id" varchar PRIMARY KEY NOT NULL, "role" varchar NOT NULL, "chatflowid" varchar NOT NULL, "content" text NOT NULL, "sourceDocuments" varchar, "createdDate" datetime NOT NULL DEFAULT (datetime('now')));` + ) + await queryRunner.query(`CREATE INDEX "IDX_e574527322272fd838f4f0f3d3" ON "chat_message" ("chatflowid") ;`) + await queryRunner.query( + `CREATE TABLE "credential" ("id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, "credentialName" varchar NOT NULL, "encryptedData" varchar NOT NULL, "createdDate" datetime NOT NULL DEFAULT (datetime('now')), "updatedDate" datetime NOT NULL DEFAULT (datetime('now')));` + ) + await queryRunner.query( + `CREATE TABLE "tool" ("id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, "description" text NOT NULL, "color" varchar NOT NULL, "iconSrc" varchar, "schema" varchar, "func" varchar, "createdDate" datetime NOT NULL DEFAULT (datetime('now')), "updatedDate" datetime NOT NULL DEFAULT (datetime('now')));` + ) + console.info('Finish migration query') + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DROP TABLE "chat_flow"`) + await queryRunner.query(`DROP INDEX "IDX_chat_messagee574527322272fd838f4f0f3d3"`) + await queryRunner.query(`DROP TABLE "chat_message"`) + await queryRunner.query(`DROP TABLE "credential"`) + await queryRunner.query(`DROP TABLE "tool"`) + } +} diff --git a/packages/server/src/index.ts b/packages/server/src/index.ts index 66c7b000..1e8dc83c 100644 --- a/packages/server/src/index.ts +++ b/packages/server/src/index.ts @@ -48,10 +48,10 @@ import { import { cloneDeep, omit } from 'lodash' import { getDataSource } from './DataSource' import { NodesPool } from './NodesPool' -import { ChatFlow } from './entity/ChatFlow' -import { ChatMessage } from './entity/ChatMessage' -import { Credential } from './entity/Credential' -import { Tool } from './entity/Tool' +import { ChatFlow } from './database/entities/ChatFlow' +import { ChatMessage } from './database/entities/ChatMessage' +import { Credential } from './database/entities/Credential' +import { Tool } from './database/entities/Tool' import { ChatflowPool } from './ChatflowPool' import { ICommonObject, INodeOptionsValue } from 'flowise-components' @@ -71,6 +71,11 @@ export class App { .then(async () => { logger.info('📦 [server]: Data Source has been initialized!') + //Migrations + console.info(`start migration`) + await this.AppDataSource.runMigrations({ transaction: 'each' }) + console.info(`finish migration`) + // Initialize nodes pool this.nodesPool = new NodesPool() await this.nodesPool.initialize() diff --git a/packages/server/src/utils/index.ts b/packages/server/src/utils/index.ts index b95dd301..73c748a3 100644 --- a/packages/server/src/utils/index.ts +++ b/packages/server/src/utils/index.ts @@ -30,10 +30,10 @@ import { import { scryptSync, randomBytes, timingSafeEqual } from 'crypto' import { lib, PBKDF2, AES, enc } from 'crypto-js' -import { ChatFlow } from '../entity/ChatFlow' -import { ChatMessage } from '../entity/ChatMessage' -import { Credential } from '../entity/Credential' -import { Tool } from '../entity/Tool' +import { ChatFlow } from '../database/entities/ChatFlow' +import { ChatMessage } from '../database/entities/ChatMessage' +import { Credential } from '../database/entities/Credential' +import { Tool } from '../database/entities/Tool' import { DataSource } from 'typeorm' const QUESTION_VAR_PREFIX = 'question' From 3849169a7670b6c648d8ded545a98f343c2c3514 Mon Sep 17 00:00:00 2001 From: chungyau97 Date: Mon, 4 Sep 2023 22:36:38 +0800 Subject: [PATCH 18/53] cleanup sqlite migration scripts --- package.json | 3 ++- packages/server/src/DataSource.ts | 6 +++--- .../1693835579790-Init.ts} | 8 +++----- packages/server/src/database/migrations/sqlite/index.ts | 3 +++ packages/server/src/index.ts | 4 +--- 5 files changed, 12 insertions(+), 12 deletions(-) rename packages/server/src/database/migrations/{1693809869231-initSqlite.ts => sqlite/1693835579790-Init.ts} (85%) create mode 100644 packages/server/src/database/migrations/sqlite/index.ts diff --git a/package.json b/package.json index 5ef0ecdb..dae9d098 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,8 @@ "lint": "eslint \"**/*.{js,jsx,ts,tsx,json,md}\"", "lint-fix": "yarn lint --fix", "quick": "pretty-quick --staged", - "postinstall": "husky install" + "postinstall": "husky install", + "migration:create": "yarn typeorm migration:create" }, "lint-staged": { "*.{js,jsx,ts,tsx,json,md}": "eslint --fix" diff --git a/packages/server/src/DataSource.ts b/packages/server/src/DataSource.ts index a1d37996..11ddc8ee 100644 --- a/packages/server/src/DataSource.ts +++ b/packages/server/src/DataSource.ts @@ -3,7 +3,7 @@ import path from 'path' import { DataSource } from 'typeorm' import { getUserHome } from './utils' import { entities } from './database/entities' -import { InitSqlite1693809869231 } from './database/migrations/1693809869231-initSqlite' +import { sqliteMigrations } from './database/migrations/sqlite' let appDataSource: DataSource @@ -18,7 +18,7 @@ export const init = async (): Promise => { synchronize: false, migrationsRun: false, entities: Object.values(entities), - migrations: [InitSqlite1693809869231] + migrations: sqliteMigrations }) break case 'mysql': @@ -58,7 +58,7 @@ export const init = async (): Promise => { synchronize: false, migrationsRun: false, entities: Object.values(entities), - migrations: [InitSqlite1693809869231] + migrations: sqliteMigrations }) break } diff --git a/packages/server/src/database/migrations/1693809869231-initSqlite.ts b/packages/server/src/database/migrations/sqlite/1693835579790-Init.ts similarity index 85% rename from packages/server/src/database/migrations/1693809869231-initSqlite.ts rename to packages/server/src/database/migrations/sqlite/1693835579790-Init.ts index 78af741d..2ae72b63 100644 --- a/packages/server/src/database/migrations/1693809869231-initSqlite.ts +++ b/packages/server/src/database/migrations/sqlite/1693835579790-Init.ts @@ -1,27 +1,25 @@ import { MigrationInterface, QueryRunner } from 'typeorm' -export class InitSqlite1693809869231 implements MigrationInterface { +export class Init1693835579790 implements MigrationInterface { public async up(queryRunner: QueryRunner): Promise { - console.info('started migration query') await queryRunner.query( `CREATE TABLE "chat_flow" ("id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, "flowData" text NOT NULL, "deployed" boolean, "isPublic" boolean, "apikeyid" varchar, "chatbotConfig" varchar, "createdDate" datetime NOT NULL DEFAULT (datetime('now')), "updatedDate" datetime NOT NULL DEFAULT (datetime('now')));` ) await queryRunner.query( `CREATE TABLE "chat_message" ("id" varchar PRIMARY KEY NOT NULL, "role" varchar NOT NULL, "chatflowid" varchar NOT NULL, "content" text NOT NULL, "sourceDocuments" varchar, "createdDate" datetime NOT NULL DEFAULT (datetime('now')));` ) - await queryRunner.query(`CREATE INDEX "IDX_e574527322272fd838f4f0f3d3" ON "chat_message" ("chatflowid") ;`) + await queryRunner.query(`CREATE INDEX "IDX_e574527322272fd838f4f0f3d3" ON "chat_message" ("chatflowid");`) await queryRunner.query( `CREATE TABLE "credential" ("id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, "credentialName" varchar NOT NULL, "encryptedData" varchar NOT NULL, "createdDate" datetime NOT NULL DEFAULT (datetime('now')), "updatedDate" datetime NOT NULL DEFAULT (datetime('now')));` ) await queryRunner.query( `CREATE TABLE "tool" ("id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, "description" text NOT NULL, "color" varchar NOT NULL, "iconSrc" varchar, "schema" varchar, "func" varchar, "createdDate" datetime NOT NULL DEFAULT (datetime('now')), "updatedDate" datetime NOT NULL DEFAULT (datetime('now')));` ) - console.info('Finish migration query') } public async down(queryRunner: QueryRunner): Promise { await queryRunner.query(`DROP TABLE "chat_flow"`) - await queryRunner.query(`DROP INDEX "IDX_chat_messagee574527322272fd838f4f0f3d3"`) + await queryRunner.query(`DROP INDEX "IDX_e574527322272fd838f4f0f3d3"`) await queryRunner.query(`DROP TABLE "chat_message"`) await queryRunner.query(`DROP TABLE "credential"`) await queryRunner.query(`DROP TABLE "tool"`) diff --git a/packages/server/src/database/migrations/sqlite/index.ts b/packages/server/src/database/migrations/sqlite/index.ts new file mode 100644 index 00000000..31fef34a --- /dev/null +++ b/packages/server/src/database/migrations/sqlite/index.ts @@ -0,0 +1,3 @@ +import { Init1693835579790 } from './1693835579790-Init' + +export const sqliteMigrations = [Init1693835579790] diff --git a/packages/server/src/index.ts b/packages/server/src/index.ts index 1e8dc83c..81dbbcb4 100644 --- a/packages/server/src/index.ts +++ b/packages/server/src/index.ts @@ -71,10 +71,8 @@ export class App { .then(async () => { logger.info('📦 [server]: Data Source has been initialized!') - //Migrations - console.info(`start migration`) + // Run Migrations Scripts await this.AppDataSource.runMigrations({ transaction: 'each' }) - console.info(`finish migration`) // Initialize nodes pool this.nodesPool = new NodesPool() From 02924f96c8205a50990949b273954358f17be01f Mon Sep 17 00:00:00 2001 From: chungyau97 Date: Tue, 5 Sep 2023 00:26:47 +0800 Subject: [PATCH 19/53] add text into potential large column --- packages/server/src/database/entities/ChatFlow.ts | 2 +- packages/server/src/database/entities/ChatMessage.ts | 2 +- packages/server/src/database/entities/Credential.ts | 2 +- packages/server/src/database/entities/Tool.ts | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/server/src/database/entities/ChatFlow.ts b/packages/server/src/database/entities/ChatFlow.ts index a1a32a88..a4fdd130 100644 --- a/packages/server/src/database/entities/ChatFlow.ts +++ b/packages/server/src/database/entities/ChatFlow.ts @@ -22,7 +22,7 @@ export class ChatFlow implements IChatFlow { @Column({ nullable: true }) apikeyid?: string - @Column({ nullable: true }) + @Column({ nullable: true, type: 'text' }) chatbotConfig?: string @CreateDateColumn() diff --git a/packages/server/src/database/entities/ChatMessage.ts b/packages/server/src/database/entities/ChatMessage.ts index 23804846..4b5306ee 100644 --- a/packages/server/src/database/entities/ChatMessage.ts +++ b/packages/server/src/database/entities/ChatMessage.ts @@ -17,7 +17,7 @@ export class ChatMessage implements IChatMessage { @Column({ type: 'text' }) content: string - @Column({ nullable: true }) + @Column({ nullable: true, type: 'text' }) sourceDocuments?: string @CreateDateColumn() diff --git a/packages/server/src/database/entities/Credential.ts b/packages/server/src/database/entities/Credential.ts index e77711dc..822f2584 100644 --- a/packages/server/src/database/entities/Credential.ts +++ b/packages/server/src/database/entities/Credential.ts @@ -13,7 +13,7 @@ export class Credential implements ICredential { @Column() credentialName: string - @Column() + @Column({ type: 'text' }) encryptedData: string @CreateDateColumn() diff --git a/packages/server/src/database/entities/Tool.ts b/packages/server/src/database/entities/Tool.ts index d459eee3..8e675eb0 100644 --- a/packages/server/src/database/entities/Tool.ts +++ b/packages/server/src/database/entities/Tool.ts @@ -19,10 +19,10 @@ export class Tool implements ITool { @Column({ nullable: true }) iconSrc?: string - @Column({ nullable: true }) + @Column({ nullable: true, type: 'text' }) schema?: string - @Column({ nullable: true }) + @Column({ nullable: true, type: 'text' }) func?: string @CreateDateColumn() From 17c2309454963482a5f333c8f1859ce238c1ba1e Mon Sep 17 00:00:00 2001 From: chungyau97 Date: Tue, 5 Sep 2023 00:36:37 +0800 Subject: [PATCH 20/53] add mysqlMigrations --- packages/server/src/DataSource.ts | 3 +- .../migrations/mysql/1693840429259-Init.ts | 64 +++++++++++++++++++ .../src/database/migrations/mysql/index.ts | 3 + 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 packages/server/src/database/migrations/mysql/1693840429259-Init.ts create mode 100644 packages/server/src/database/migrations/mysql/index.ts diff --git a/packages/server/src/DataSource.ts b/packages/server/src/DataSource.ts index 11ddc8ee..6f8e56fd 100644 --- a/packages/server/src/DataSource.ts +++ b/packages/server/src/DataSource.ts @@ -4,6 +4,7 @@ import { DataSource } from 'typeorm' import { getUserHome } from './utils' import { entities } from './database/entities' import { sqliteMigrations } from './database/migrations/sqlite' +import { mysqlMigrations } from './database/migrations/mysql' let appDataSource: DataSource @@ -33,7 +34,7 @@ export const init = async (): Promise => { synchronize: false, migrationsRun: false, entities: Object.values(entities), - migrations: [] + migrations: mysqlMigrations }) break case 'postgres': diff --git a/packages/server/src/database/migrations/mysql/1693840429259-Init.ts b/packages/server/src/database/migrations/mysql/1693840429259-Init.ts new file mode 100644 index 00000000..8d034680 --- /dev/null +++ b/packages/server/src/database/migrations/mysql/1693840429259-Init.ts @@ -0,0 +1,64 @@ +import { MigrationInterface, QueryRunner } from 'typeorm' + +export class Init1693840429259 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `CREATE TABLE \`chat_flow\` ( + \`id\` varchar(36) NOT NULL, + \`name\` varchar(255) NOT NULL, + \`flowData\` text NOT NULL, + \`deployed\` tinyint DEFAULT NULL, + \`isPublic\` tinyint DEFAULT NULL, + \`apikeyid\` varchar(255) DEFAULT NULL, + \`chatbotConfig\` text, + \`createdDate\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), + \`updatedDate\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), + PRIMARY KEY (\`id\`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;` + ) + await queryRunner.query( + `CREATE TABLE \`chat_message\` ( + \`id\` varchar(36) NOT NULL, + \`role\` varchar(255) NOT NULL, + \`chatflowid\` varchar(255) NOT NULL, + \`content\` text NOT NULL, + \`sourceDocuments\` text, + \`createdDate\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), + PRIMARY KEY (\`id\`), + KEY \`IDX_e574527322272fd838f4f0f3d3\` (\`chatflowid\`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;` + ) + await queryRunner.query( + `CREATE TABLE \`credential\` ( + \`id\` varchar(36) NOT NULL, + \`name\` varchar(255) NOT NULL, + \`credentialName\` varchar(255) NOT NULL, + \`encryptedData\` text NOT NULL, + \`createdDate\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), + \`updatedDate\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), + PRIMARY KEY (\`id\`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;` + ) + await queryRunner.query( + `CREATE TABLE \`tool\` ( + \`id\` varchar(36) NOT NULL, + \`name\` varchar(255) NOT NULL, + \`description\` text NOT NULL, + \`color\` varchar(255) NOT NULL, + \`iconSrc\` varchar(255) DEFAULT NULL, + \`schema\` text, + \`func\` text, + \`createdDate\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), + \`updatedDate\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), + PRIMARY KEY (\`id\`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;` + ) + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DROP TABLE "chat_flow"`) + await queryRunner.query(`DROP TABLE "chat_message"`) + await queryRunner.query(`DROP TABLE "credential"`) + await queryRunner.query(`DROP TABLE "tool"`) + } +} diff --git a/packages/server/src/database/migrations/mysql/index.ts b/packages/server/src/database/migrations/mysql/index.ts new file mode 100644 index 00000000..79fa17ad --- /dev/null +++ b/packages/server/src/database/migrations/mysql/index.ts @@ -0,0 +1,3 @@ +import { Init1693840429259 } from './1693840429259-Init' + +export const mysqlMigrations = [Init1693840429259] From b688f962363e2f8aefcbff51055ee79b49532c20 Mon Sep 17 00:00:00 2001 From: chungyau97 Date: Tue, 5 Sep 2023 00:55:39 +0800 Subject: [PATCH 21/53] update sqlite init query --- .../migrations/mysql/1693840429259-Init.ts | 8 ++++---- .../migrations/sqlite/1693835579790-Init.ts | 19 +++++++++---------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/packages/server/src/database/migrations/mysql/1693840429259-Init.ts b/packages/server/src/database/migrations/mysql/1693840429259-Init.ts index 8d034680..6ae611dc 100644 --- a/packages/server/src/database/migrations/mysql/1693840429259-Init.ts +++ b/packages/server/src/database/migrations/mysql/1693840429259-Init.ts @@ -56,9 +56,9 @@ export class Init1693840429259 implements MigrationInterface { } public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`DROP TABLE "chat_flow"`) - await queryRunner.query(`DROP TABLE "chat_message"`) - await queryRunner.query(`DROP TABLE "credential"`) - await queryRunner.query(`DROP TABLE "tool"`) + await queryRunner.query(`DROP TABLE chat_flow`) + await queryRunner.query(`DROP TABLE chat_message`) + await queryRunner.query(`DROP TABLE credential`) + await queryRunner.query(`DROP TABLE tool`) } } diff --git a/packages/server/src/database/migrations/sqlite/1693835579790-Init.ts b/packages/server/src/database/migrations/sqlite/1693835579790-Init.ts index 2ae72b63..2c199881 100644 --- a/packages/server/src/database/migrations/sqlite/1693835579790-Init.ts +++ b/packages/server/src/database/migrations/sqlite/1693835579790-Init.ts @@ -3,25 +3,24 @@ import { MigrationInterface, QueryRunner } from 'typeorm' export class Init1693835579790 implements MigrationInterface { public async up(queryRunner: QueryRunner): Promise { await queryRunner.query( - `CREATE TABLE "chat_flow" ("id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, "flowData" text NOT NULL, "deployed" boolean, "isPublic" boolean, "apikeyid" varchar, "chatbotConfig" varchar, "createdDate" datetime NOT NULL DEFAULT (datetime('now')), "updatedDate" datetime NOT NULL DEFAULT (datetime('now')));` + `CREATE TABLE "chat_flow" ("id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, "flowData" text NOT NULL, "deployed" boolean, "isPublic" boolean, "apikeyid" varchar, "chatbotConfig" text, "createdDate" datetime NOT NULL DEFAULT (datetime('now')), "updatedDate" datetime NOT NULL DEFAULT (datetime('now')));` ) await queryRunner.query( - `CREATE TABLE "chat_message" ("id" varchar PRIMARY KEY NOT NULL, "role" varchar NOT NULL, "chatflowid" varchar NOT NULL, "content" text NOT NULL, "sourceDocuments" varchar, "createdDate" datetime NOT NULL DEFAULT (datetime('now')));` + `CREATE TABLE "chat_message" ("id" varchar PRIMARY KEY NOT NULL, "role" varchar NOT NULL, "chatflowid" varchar NOT NULL, "content" text NOT NULL, "sourceDocuments" text, "createdDate" datetime NOT NULL DEFAULT (datetime('now')));` ) - await queryRunner.query(`CREATE INDEX "IDX_e574527322272fd838f4f0f3d3" ON "chat_message" ("chatflowid");`) + await queryRunner.query(`CREATE INDEX "IDX_e574527322272fd838f4f0f3d3" ON "chat_message" ("chatflowid") ;`) await queryRunner.query( - `CREATE TABLE "credential" ("id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, "credentialName" varchar NOT NULL, "encryptedData" varchar NOT NULL, "createdDate" datetime NOT NULL DEFAULT (datetime('now')), "updatedDate" datetime NOT NULL DEFAULT (datetime('now')));` + `CREATE TABLE "credential" ("id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, "credentialName" varchar NOT NULL, "encryptedData" text NOT NULL, "createdDate" datetime NOT NULL DEFAULT (datetime('now')), "updatedDate" datetime NOT NULL DEFAULT (datetime('now')));` ) await queryRunner.query( - `CREATE TABLE "tool" ("id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, "description" text NOT NULL, "color" varchar NOT NULL, "iconSrc" varchar, "schema" varchar, "func" varchar, "createdDate" datetime NOT NULL DEFAULT (datetime('now')), "updatedDate" datetime NOT NULL DEFAULT (datetime('now')));` + `CREATE TABLE "tool" ("id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, "description" text NOT NULL, "color" varchar NOT NULL, "iconSrc" varchar, "schema" text, "func" text, "createdDate" datetime NOT NULL DEFAULT (datetime('now')), "updatedDate" datetime NOT NULL DEFAULT (datetime('now')));` ) } public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`DROP TABLE "chat_flow"`) - await queryRunner.query(`DROP INDEX "IDX_e574527322272fd838f4f0f3d3"`) - await queryRunner.query(`DROP TABLE "chat_message"`) - await queryRunner.query(`DROP TABLE "credential"`) - await queryRunner.query(`DROP TABLE "tool"`) + await queryRunner.query(`DROP TABLE chat_flow`) + await queryRunner.query(`DROP TABLE chat_message`) + await queryRunner.query(`DROP TABLE credential`) + await queryRunner.query(`DROP TABLE tool`) } } From ae66f163de47c69209e517bef3bc0309c8918441 Mon Sep 17 00:00:00 2001 From: chungyau97 Date: Tue, 5 Sep 2023 13:49:50 +0800 Subject: [PATCH 22/53] add postgresMigrations --- packages/server/src/DataSource.ts | 3 +- .../migrations/postgres/1693891895163-Init.ts | 64 +++++++++++++++++++ .../src/database/migrations/postgres/index.ts | 3 + 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 packages/server/src/database/migrations/postgres/1693891895163-Init.ts create mode 100644 packages/server/src/database/migrations/postgres/index.ts diff --git a/packages/server/src/DataSource.ts b/packages/server/src/DataSource.ts index 6f8e56fd..9265e55f 100644 --- a/packages/server/src/DataSource.ts +++ b/packages/server/src/DataSource.ts @@ -5,6 +5,7 @@ import { getUserHome } from './utils' import { entities } from './database/entities' import { sqliteMigrations } from './database/migrations/sqlite' import { mysqlMigrations } from './database/migrations/mysql' +import { postgresMigrations } from './database/migrations/postgres' let appDataSource: DataSource @@ -48,7 +49,7 @@ export const init = async (): Promise => { synchronize: false, migrationsRun: false, entities: Object.values(entities), - migrations: [] + migrations: postgresMigrations }) break default: diff --git a/packages/server/src/database/migrations/postgres/1693891895163-Init.ts b/packages/server/src/database/migrations/postgres/1693891895163-Init.ts new file mode 100644 index 00000000..defb5f87 --- /dev/null +++ b/packages/server/src/database/migrations/postgres/1693891895163-Init.ts @@ -0,0 +1,64 @@ +import { MigrationInterface, QueryRunner } from 'typeorm' + +export class Init1693891895163 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `CREATE TABLE chat_flow ( + id uuid NOT NULL DEFAULT uuid_generate_v4(), + "name" varchar NOT NULL, + "flowData" text NOT NULL, + deployed bool NULL, + "isPublic" bool NULL, + apikeyid varchar NULL, + "chatbotConfig" text NULL, + "createdDate" timestamp NOT NULL DEFAULT now(), + "updatedDate" timestamp NOT NULL DEFAULT now(), + CONSTRAINT "PK_3c7cea7d047ac4b91764574cdbf" PRIMARY KEY (id) + );` + ) + await queryRunner.query( + `CREATE TABLE chat_message ( + id uuid NOT NULL DEFAULT uuid_generate_v4(), + "role" varchar NOT NULL, + chatflowid varchar NOT NULL, + "content" text NOT NULL, + "sourceDocuments" text NULL, + "createdDate" timestamp NOT NULL DEFAULT now(), + CONSTRAINT "PK_3cc0d85193aade457d3077dd06b" PRIMARY KEY (id) + );` + ) + await queryRunner.query(`CREATE INDEX "IDX_e574527322272fd838f4f0f3d3" ON chat_message USING btree (chatflowid);`) + await queryRunner.query( + `CREATE TABLE credential ( + id uuid NOT NULL DEFAULT uuid_generate_v4(), + "name" varchar NOT NULL, + "credentialName" varchar NOT NULL, + "encryptedData" text NOT NULL, + "createdDate" timestamp NOT NULL DEFAULT now(), + "updatedDate" timestamp NOT NULL DEFAULT now(), + CONSTRAINT "PK_3a5169bcd3d5463cefeec78be82" PRIMARY KEY (id) + );` + ) + await queryRunner.query( + `CREATE TABLE tool ( + id uuid NOT NULL DEFAULT uuid_generate_v4(), + "name" varchar NOT NULL, + description text NOT NULL, + color varchar NOT NULL, + "iconSrc" varchar NULL, + "schema" text NULL, + func text NULL, + "createdDate" timestamp NOT NULL DEFAULT now(), + "updatedDate" timestamp NOT NULL DEFAULT now(), + CONSTRAINT "PK_3bf5b1016a384916073184f99b7" PRIMARY KEY (id) + );` + ) + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DROP TABLE chat_flow`) + await queryRunner.query(`DROP TABLE chat_message`) + await queryRunner.query(`DROP TABLE credential`) + await queryRunner.query(`DROP TABLE tool`) + } +} diff --git a/packages/server/src/database/migrations/postgres/index.ts b/packages/server/src/database/migrations/postgres/index.ts new file mode 100644 index 00000000..c8805785 --- /dev/null +++ b/packages/server/src/database/migrations/postgres/index.ts @@ -0,0 +1,3 @@ +import { Init1693891895163 } from './1693891895163-Init' + +export const postgresMigrations = [Init1693891895163] From 0e891bfb3aa1cbad492c9947ff4569aaec6ae0ec Mon Sep 17 00:00:00 2001 From: chungyau97 Date: Tue, 5 Sep 2023 16:13:04 +0800 Subject: [PATCH 23/53] preserve previous user data --- .../server/src/database/entities/ChatFlow.ts | 2 +- .../src/database/entities/ChatMessage.ts | 2 +- .../src/database/entities/Credential.ts | 2 +- packages/server/src/database/entities/Tool.ts | 4 ++-- .../migrations/mysql/1693840429259-Init.ts | 18 ++++++++--------- .../migrations/postgres/1693891895163-Init.ts | 20 +++++++++---------- .../migrations/sqlite/1693835579790-Init.ts | 10 +++++----- 7 files changed, 29 insertions(+), 29 deletions(-) diff --git a/packages/server/src/database/entities/ChatFlow.ts b/packages/server/src/database/entities/ChatFlow.ts index a4fdd130..a1a32a88 100644 --- a/packages/server/src/database/entities/ChatFlow.ts +++ b/packages/server/src/database/entities/ChatFlow.ts @@ -22,7 +22,7 @@ export class ChatFlow implements IChatFlow { @Column({ nullable: true }) apikeyid?: string - @Column({ nullable: true, type: 'text' }) + @Column({ nullable: true }) chatbotConfig?: string @CreateDateColumn() diff --git a/packages/server/src/database/entities/ChatMessage.ts b/packages/server/src/database/entities/ChatMessage.ts index 4b5306ee..23804846 100644 --- a/packages/server/src/database/entities/ChatMessage.ts +++ b/packages/server/src/database/entities/ChatMessage.ts @@ -17,7 +17,7 @@ export class ChatMessage implements IChatMessage { @Column({ type: 'text' }) content: string - @Column({ nullable: true, type: 'text' }) + @Column({ nullable: true }) sourceDocuments?: string @CreateDateColumn() diff --git a/packages/server/src/database/entities/Credential.ts b/packages/server/src/database/entities/Credential.ts index 822f2584..e77711dc 100644 --- a/packages/server/src/database/entities/Credential.ts +++ b/packages/server/src/database/entities/Credential.ts @@ -13,7 +13,7 @@ export class Credential implements ICredential { @Column() credentialName: string - @Column({ type: 'text' }) + @Column() encryptedData: string @CreateDateColumn() diff --git a/packages/server/src/database/entities/Tool.ts b/packages/server/src/database/entities/Tool.ts index 8e675eb0..d459eee3 100644 --- a/packages/server/src/database/entities/Tool.ts +++ b/packages/server/src/database/entities/Tool.ts @@ -19,10 +19,10 @@ export class Tool implements ITool { @Column({ nullable: true }) iconSrc?: string - @Column({ nullable: true, type: 'text' }) + @Column({ nullable: true }) schema?: string - @Column({ nullable: true, type: 'text' }) + @Column({ nullable: true }) func?: string @CreateDateColumn() diff --git a/packages/server/src/database/migrations/mysql/1693840429259-Init.ts b/packages/server/src/database/migrations/mysql/1693840429259-Init.ts index 6ae611dc..9d07206d 100644 --- a/packages/server/src/database/migrations/mysql/1693840429259-Init.ts +++ b/packages/server/src/database/migrations/mysql/1693840429259-Init.ts @@ -3,51 +3,51 @@ import { MigrationInterface, QueryRunner } from 'typeorm' export class Init1693840429259 implements MigrationInterface { public async up(queryRunner: QueryRunner): Promise { await queryRunner.query( - `CREATE TABLE \`chat_flow\` ( + `CREATE TABLE IF NOT EXISTS \`chat_flow\` ( \`id\` varchar(36) NOT NULL, \`name\` varchar(255) NOT NULL, \`flowData\` text NOT NULL, \`deployed\` tinyint DEFAULT NULL, \`isPublic\` tinyint DEFAULT NULL, \`apikeyid\` varchar(255) DEFAULT NULL, - \`chatbotConfig\` text, + \`chatbotConfig\` varchar(255) DEFAULT NULL, \`createdDate\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), \`updatedDate\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), PRIMARY KEY (\`id\`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;` ) await queryRunner.query( - `CREATE TABLE \`chat_message\` ( + `CREATE TABLE IF NOT EXISTS \`chat_message\` ( \`id\` varchar(36) NOT NULL, \`role\` varchar(255) NOT NULL, \`chatflowid\` varchar(255) NOT NULL, \`content\` text NOT NULL, - \`sourceDocuments\` text, + \`sourceDocuments\` varchar(255) DEFAULT NULL, \`createdDate\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), PRIMARY KEY (\`id\`), KEY \`IDX_e574527322272fd838f4f0f3d3\` (\`chatflowid\`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;` ) await queryRunner.query( - `CREATE TABLE \`credential\` ( + `CREATE TABLE IF NOT EXISTS \`credential\` ( \`id\` varchar(36) NOT NULL, \`name\` varchar(255) NOT NULL, \`credentialName\` varchar(255) NOT NULL, - \`encryptedData\` text NOT NULL, + \`encryptedData\` varchar(255) NOT NULL, \`createdDate\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), \`updatedDate\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), PRIMARY KEY (\`id\`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;` ) await queryRunner.query( - `CREATE TABLE \`tool\` ( + `CREATE TABLE IF NOT EXISTS \`tool\` ( \`id\` varchar(36) NOT NULL, \`name\` varchar(255) NOT NULL, \`description\` text NOT NULL, \`color\` varchar(255) NOT NULL, \`iconSrc\` varchar(255) DEFAULT NULL, - \`schema\` text, - \`func\` text, + \`schema\` varchar(255) DEFAULT NULL, + \`func\` varchar(255) DEFAULT NULL, \`createdDate\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), \`updatedDate\` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), PRIMARY KEY (\`id\`) diff --git a/packages/server/src/database/migrations/postgres/1693891895163-Init.ts b/packages/server/src/database/migrations/postgres/1693891895163-Init.ts index defb5f87..3ffe055c 100644 --- a/packages/server/src/database/migrations/postgres/1693891895163-Init.ts +++ b/packages/server/src/database/migrations/postgres/1693891895163-Init.ts @@ -3,51 +3,51 @@ import { MigrationInterface, QueryRunner } from 'typeorm' export class Init1693891895163 implements MigrationInterface { public async up(queryRunner: QueryRunner): Promise { await queryRunner.query( - `CREATE TABLE chat_flow ( + `CREATE TABLE IF NOT EXISTS chat_flow ( id uuid NOT NULL DEFAULT uuid_generate_v4(), "name" varchar NOT NULL, "flowData" text NOT NULL, deployed bool NULL, "isPublic" bool NULL, apikeyid varchar NULL, - "chatbotConfig" text NULL, + "chatbotConfig" varchar NULL, "createdDate" timestamp NOT NULL DEFAULT now(), "updatedDate" timestamp NOT NULL DEFAULT now(), CONSTRAINT "PK_3c7cea7d047ac4b91764574cdbf" PRIMARY KEY (id) );` ) await queryRunner.query( - `CREATE TABLE chat_message ( + `CREATE TABLE IF NOT EXISTS chat_message ( id uuid NOT NULL DEFAULT uuid_generate_v4(), "role" varchar NOT NULL, chatflowid varchar NOT NULL, "content" text NOT NULL, - "sourceDocuments" text NULL, + "sourceDocuments" varchar NULL, "createdDate" timestamp NOT NULL DEFAULT now(), CONSTRAINT "PK_3cc0d85193aade457d3077dd06b" PRIMARY KEY (id) );` ) - await queryRunner.query(`CREATE INDEX "IDX_e574527322272fd838f4f0f3d3" ON chat_message USING btree (chatflowid);`) + await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_e574527322272fd838f4f0f3d3" ON chat_message USING btree (chatflowid);`) await queryRunner.query( - `CREATE TABLE credential ( + `CREATE TABLE IF NOT EXISTS credential ( id uuid NOT NULL DEFAULT uuid_generate_v4(), "name" varchar NOT NULL, "credentialName" varchar NOT NULL, - "encryptedData" text NOT NULL, + "encryptedData" varchar NOT NULL, "createdDate" timestamp NOT NULL DEFAULT now(), "updatedDate" timestamp NOT NULL DEFAULT now(), CONSTRAINT "PK_3a5169bcd3d5463cefeec78be82" PRIMARY KEY (id) );` ) await queryRunner.query( - `CREATE TABLE tool ( + `CREATE TABLE IF NOT EXISTS tool ( id uuid NOT NULL DEFAULT uuid_generate_v4(), "name" varchar NOT NULL, description text NOT NULL, color varchar NOT NULL, "iconSrc" varchar NULL, - "schema" text NULL, - func text NULL, + "schema" varchar NULL, + func varchar NULL, "createdDate" timestamp NOT NULL DEFAULT now(), "updatedDate" timestamp NOT NULL DEFAULT now(), CONSTRAINT "PK_3bf5b1016a384916073184f99b7" PRIMARY KEY (id) diff --git a/packages/server/src/database/migrations/sqlite/1693835579790-Init.ts b/packages/server/src/database/migrations/sqlite/1693835579790-Init.ts index 2c199881..04b2e660 100644 --- a/packages/server/src/database/migrations/sqlite/1693835579790-Init.ts +++ b/packages/server/src/database/migrations/sqlite/1693835579790-Init.ts @@ -3,17 +3,17 @@ import { MigrationInterface, QueryRunner } from 'typeorm' export class Init1693835579790 implements MigrationInterface { public async up(queryRunner: QueryRunner): Promise { await queryRunner.query( - `CREATE TABLE "chat_flow" ("id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, "flowData" text NOT NULL, "deployed" boolean, "isPublic" boolean, "apikeyid" varchar, "chatbotConfig" text, "createdDate" datetime NOT NULL DEFAULT (datetime('now')), "updatedDate" datetime NOT NULL DEFAULT (datetime('now')));` + `CREATE TABLE IF NOT EXISTS "chat_flow" ("id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, "flowData" text NOT NULL, "deployed" boolean, "isPublic" boolean, "apikeyid" varchar, "chatbotConfig" varchar, "createdDate" datetime NOT NULL DEFAULT (datetime('now')), "updatedDate" datetime NOT NULL DEFAULT (datetime('now')));` ) await queryRunner.query( - `CREATE TABLE "chat_message" ("id" varchar PRIMARY KEY NOT NULL, "role" varchar NOT NULL, "chatflowid" varchar NOT NULL, "content" text NOT NULL, "sourceDocuments" text, "createdDate" datetime NOT NULL DEFAULT (datetime('now')));` + `CREATE TABLE IF NOT EXISTS "chat_message" ("id" varchar PRIMARY KEY NOT NULL, "role" varchar NOT NULL, "chatflowid" varchar NOT NULL, "content" text NOT NULL, "sourceDocuments" varchar, "createdDate" datetime NOT NULL DEFAULT (datetime('now')));` ) - await queryRunner.query(`CREATE INDEX "IDX_e574527322272fd838f4f0f3d3" ON "chat_message" ("chatflowid") ;`) + await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_e574527322272fd838f4f0f3d3" ON "chat_message" ("chatflowid") ;`) await queryRunner.query( - `CREATE TABLE "credential" ("id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, "credentialName" varchar NOT NULL, "encryptedData" text NOT NULL, "createdDate" datetime NOT NULL DEFAULT (datetime('now')), "updatedDate" datetime NOT NULL DEFAULT (datetime('now')));` + `CREATE TABLE IF NOT EXISTS "credential" ("id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, "credentialName" varchar NOT NULL, "encryptedData" varchar NOT NULL, "createdDate" datetime NOT NULL DEFAULT (datetime('now')), "updatedDate" datetime NOT NULL DEFAULT (datetime('now')));` ) await queryRunner.query( - `CREATE TABLE "tool" ("id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, "description" text NOT NULL, "color" varchar NOT NULL, "iconSrc" varchar, "schema" text, "func" text, "createdDate" datetime NOT NULL DEFAULT (datetime('now')), "updatedDate" datetime NOT NULL DEFAULT (datetime('now')));` + `CREATE TABLE IF NOT EXISTS "tool" ("id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, "description" text NOT NULL, "color" varchar NOT NULL, "iconSrc" varchar, "schema" varchar, "func" varchar, "createdDate" datetime NOT NULL DEFAULT (datetime('now')), "updatedDate" datetime NOT NULL DEFAULT (datetime('now')));` ) } From 427ec32dc60b1cba57ff8182bd6d725df54f67e0 Mon Sep 17 00:00:00 2001 From: chungyau97 Date: Tue, 5 Sep 2023 21:50:00 +0800 Subject: [PATCH 24/53] add sqlite modify chatflow --- .../server/src/database/entities/ChatFlow.ts | 2 +- .../sqlite/1693920824108-ModifyChatFlow.ts | 18 ++++++++++++++++++ .../src/database/migrations/sqlite/index.ts | 3 ++- 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 packages/server/src/database/migrations/sqlite/1693920824108-ModifyChatFlow.ts diff --git a/packages/server/src/database/entities/ChatFlow.ts b/packages/server/src/database/entities/ChatFlow.ts index a1a32a88..a4fdd130 100644 --- a/packages/server/src/database/entities/ChatFlow.ts +++ b/packages/server/src/database/entities/ChatFlow.ts @@ -22,7 +22,7 @@ export class ChatFlow implements IChatFlow { @Column({ nullable: true }) apikeyid?: string - @Column({ nullable: true }) + @Column({ nullable: true, type: 'text' }) chatbotConfig?: string @CreateDateColumn() diff --git a/packages/server/src/database/migrations/sqlite/1693920824108-ModifyChatFlow.ts b/packages/server/src/database/migrations/sqlite/1693920824108-ModifyChatFlow.ts new file mode 100644 index 00000000..429dc0ee --- /dev/null +++ b/packages/server/src/database/migrations/sqlite/1693920824108-ModifyChatFlow.ts @@ -0,0 +1,18 @@ +import { MigrationInterface, QueryRunner } from 'typeorm' + +export class ModifyChatFlow1693920824108 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `CREATE TABLE "temp_chat_flow" ("id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, "flowData" text NOT NULL, "deployed" boolean, "isPublic" boolean, "apikeyid" varchar, "chatbotConfig" text, "createdDate" datetime NOT NULL DEFAULT (datetime('now')), "updatedDate" datetime NOT NULL DEFAULT (datetime('now')));` + ) + await queryRunner.query( + `INSERT INTO "temp_chat_flow" ("id", "name", "flowData", "deployed", "isPublic", "apikeyid", "chatbotConfig", "createdDate", "updatedDate") SELECT "id", "name", "flowData", "deployed", "isPublic", "apikeyid", "chatbotConfig", "createdDate", "updatedDate" FROM "chat_flow";` + ) + await queryRunner.query(`DROP TABLE chat_flow;`) + await queryRunner.query(`ALTER TABLE temp_chat_flow RENAME TO chat_flow;`) + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DROP TABLE temp_chat_flow`) + } +} diff --git a/packages/server/src/database/migrations/sqlite/index.ts b/packages/server/src/database/migrations/sqlite/index.ts index 31fef34a..376a7746 100644 --- a/packages/server/src/database/migrations/sqlite/index.ts +++ b/packages/server/src/database/migrations/sqlite/index.ts @@ -1,3 +1,4 @@ import { Init1693835579790 } from './1693835579790-Init' +import { ModifyChatFlow1693920824108 } from './1693920824108-ModifyChatFlow' -export const sqliteMigrations = [Init1693835579790] +export const sqliteMigrations = [Init1693835579790, ModifyChatFlow1693920824108] From 22984618ca7a8428963da060db47e70aa8d3d34f Mon Sep 17 00:00:00 2001 From: chungyau97 Date: Tue, 5 Sep 2023 22:02:51 +0800 Subject: [PATCH 25/53] add sqlite modify chatmessage --- .../src/database/entities/ChatMessage.ts | 2 +- .../sqlite/1693921865247-ModifyChatMessage.ts | 18 ++++++++++++++++++ .../src/database/migrations/sqlite/index.ts | 3 ++- 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 packages/server/src/database/migrations/sqlite/1693921865247-ModifyChatMessage.ts diff --git a/packages/server/src/database/entities/ChatMessage.ts b/packages/server/src/database/entities/ChatMessage.ts index 23804846..4b5306ee 100644 --- a/packages/server/src/database/entities/ChatMessage.ts +++ b/packages/server/src/database/entities/ChatMessage.ts @@ -17,7 +17,7 @@ export class ChatMessage implements IChatMessage { @Column({ type: 'text' }) content: string - @Column({ nullable: true }) + @Column({ nullable: true, type: 'text' }) sourceDocuments?: string @CreateDateColumn() diff --git a/packages/server/src/database/migrations/sqlite/1693921865247-ModifyChatMessage.ts b/packages/server/src/database/migrations/sqlite/1693921865247-ModifyChatMessage.ts new file mode 100644 index 00000000..fc327e00 --- /dev/null +++ b/packages/server/src/database/migrations/sqlite/1693921865247-ModifyChatMessage.ts @@ -0,0 +1,18 @@ +import { MigrationInterface, QueryRunner } from 'typeorm' + +export class ModifyChatMessage1693921865247 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `CREATE TABLE "temp_chat_message" ("id" varchar PRIMARY KEY NOT NULL, "role" varchar NOT NULL, "chatflowid" varchar NOT NULL, "content" text NOT NULL, "sourceDocuments" text, "createdDate" datetime NOT NULL DEFAULT (datetime('now')));` + ) + await queryRunner.query( + `INSERT INTO "temp_chat_message" ("id", "role", "chatflowid", "content", "sourceDocuments", "createdDate") SELECT "id", "role", "chatflowid", "content", "sourceDocuments", "createdDate" FROM "chat_message";` + ) + await queryRunner.query(`DROP TABLE chat_message;`) + await queryRunner.query(`ALTER TABLE temp_chat_message RENAME TO chat_message;`) + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DROP TABLE temp_chat_message`) + } +} diff --git a/packages/server/src/database/migrations/sqlite/index.ts b/packages/server/src/database/migrations/sqlite/index.ts index 376a7746..6e24be67 100644 --- a/packages/server/src/database/migrations/sqlite/index.ts +++ b/packages/server/src/database/migrations/sqlite/index.ts @@ -1,4 +1,5 @@ import { Init1693835579790 } from './1693835579790-Init' import { ModifyChatFlow1693920824108 } from './1693920824108-ModifyChatFlow' +import { ModifyChatMessage1693921865247 } from './1693921865247-ModifyChatMessage' -export const sqliteMigrations = [Init1693835579790, ModifyChatFlow1693920824108] +export const sqliteMigrations = [Init1693835579790, ModifyChatFlow1693920824108, ModifyChatMessage1693921865247] From a7fa3f48e2b44291b7f8de1b1240e8d8b92d8dcf Mon Sep 17 00:00:00 2001 From: chungyau97 Date: Tue, 5 Sep 2023 22:18:28 +0800 Subject: [PATCH 26/53] add chat_message index --- .../migrations/sqlite/1693921865247-ModifyChatMessage.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/server/src/database/migrations/sqlite/1693921865247-ModifyChatMessage.ts b/packages/server/src/database/migrations/sqlite/1693921865247-ModifyChatMessage.ts index fc327e00..94cd6e0e 100644 --- a/packages/server/src/database/migrations/sqlite/1693921865247-ModifyChatMessage.ts +++ b/packages/server/src/database/migrations/sqlite/1693921865247-ModifyChatMessage.ts @@ -10,6 +10,7 @@ export class ModifyChatMessage1693921865247 implements MigrationInterface { ) await queryRunner.query(`DROP TABLE chat_message;`) await queryRunner.query(`ALTER TABLE temp_chat_message RENAME TO chat_message;`) + await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_e574527322272fd838f4f0f3d3" ON "chat_message" ("chatflowid") ;`) } public async down(queryRunner: QueryRunner): Promise { From 1c1b057512dd7dda4747abac82aebab6577929fd Mon Sep 17 00:00:00 2001 From: chungyau97 Date: Tue, 5 Sep 2023 22:27:17 +0800 Subject: [PATCH 27/53] add sqlite modify credential --- .../server/src/database/entities/Credential.ts | 2 +- .../sqlite/1693923551694-ModifyCredential.ts | 18 ++++++++++++++++++ .../src/database/migrations/sqlite/index.ts | 8 +++++++- 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 packages/server/src/database/migrations/sqlite/1693923551694-ModifyCredential.ts diff --git a/packages/server/src/database/entities/Credential.ts b/packages/server/src/database/entities/Credential.ts index e77711dc..822f2584 100644 --- a/packages/server/src/database/entities/Credential.ts +++ b/packages/server/src/database/entities/Credential.ts @@ -13,7 +13,7 @@ export class Credential implements ICredential { @Column() credentialName: string - @Column() + @Column({ type: 'text' }) encryptedData: string @CreateDateColumn() diff --git a/packages/server/src/database/migrations/sqlite/1693923551694-ModifyCredential.ts b/packages/server/src/database/migrations/sqlite/1693923551694-ModifyCredential.ts new file mode 100644 index 00000000..2a906a83 --- /dev/null +++ b/packages/server/src/database/migrations/sqlite/1693923551694-ModifyCredential.ts @@ -0,0 +1,18 @@ +import { MigrationInterface, QueryRunner } from 'typeorm' + +export class ModifyCredential1693923551694 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `CREATE TABLE "temp_credential" ("id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, "credentialName" varchar NOT NULL, "encryptedData" text NOT NULL, "createdDate" datetime NOT NULL DEFAULT (datetime('now')), "updatedDate" datetime NOT NULL DEFAULT (datetime('now')));` + ) + await queryRunner.query( + `INSERT INTO "temp_credential" ("id", "name", "credentialName", "encryptedData", "createdDate", "updatedDate") SELECT "id", "name", "credentialName", "encryptedData", "createdDate", "updatedDate" FROM "credential";` + ) + await queryRunner.query(`DROP TABLE credential;`) + await queryRunner.query(`ALTER TABLE temp_credential RENAME TO credential;`) + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DROP TABLE credential`) + } +} diff --git a/packages/server/src/database/migrations/sqlite/index.ts b/packages/server/src/database/migrations/sqlite/index.ts index 6e24be67..4a8251a6 100644 --- a/packages/server/src/database/migrations/sqlite/index.ts +++ b/packages/server/src/database/migrations/sqlite/index.ts @@ -1,5 +1,11 @@ import { Init1693835579790 } from './1693835579790-Init' import { ModifyChatFlow1693920824108 } from './1693920824108-ModifyChatFlow' import { ModifyChatMessage1693921865247 } from './1693921865247-ModifyChatMessage' +import { ModifyCredential1693923551694 } from './1693923551694-ModifyCredential' -export const sqliteMigrations = [Init1693835579790, ModifyChatFlow1693920824108, ModifyChatMessage1693921865247] +export const sqliteMigrations = [ + Init1693835579790, + ModifyChatFlow1693920824108, + ModifyChatMessage1693921865247, + ModifyCredential1693923551694 +] From aa1122641caf3b8fff5bc6810f161778a18d5cd1 Mon Sep 17 00:00:00 2001 From: chungyau97 Date: Tue, 5 Sep 2023 22:41:28 +0800 Subject: [PATCH 28/53] add sqlite modify tool --- packages/server/src/database/entities/Tool.ts | 4 ++-- .../sqlite/1693923551694-ModifyCredential.ts | 2 +- .../sqlite/1693924207475-ModifyTool.ts | 18 ++++++++++++++++++ .../src/database/migrations/sqlite/index.ts | 4 +++- 4 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 packages/server/src/database/migrations/sqlite/1693924207475-ModifyTool.ts diff --git a/packages/server/src/database/entities/Tool.ts b/packages/server/src/database/entities/Tool.ts index d459eee3..8e675eb0 100644 --- a/packages/server/src/database/entities/Tool.ts +++ b/packages/server/src/database/entities/Tool.ts @@ -19,10 +19,10 @@ export class Tool implements ITool { @Column({ nullable: true }) iconSrc?: string - @Column({ nullable: true }) + @Column({ nullable: true, type: 'text' }) schema?: string - @Column({ nullable: true }) + @Column({ nullable: true, type: 'text' }) func?: string @CreateDateColumn() diff --git a/packages/server/src/database/migrations/sqlite/1693923551694-ModifyCredential.ts b/packages/server/src/database/migrations/sqlite/1693923551694-ModifyCredential.ts index 2a906a83..fccb3c18 100644 --- a/packages/server/src/database/migrations/sqlite/1693923551694-ModifyCredential.ts +++ b/packages/server/src/database/migrations/sqlite/1693923551694-ModifyCredential.ts @@ -13,6 +13,6 @@ export class ModifyCredential1693923551694 implements MigrationInterface { } public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`DROP TABLE credential`) + await queryRunner.query(`DROP TABLE temp_credential`) } } diff --git a/packages/server/src/database/migrations/sqlite/1693924207475-ModifyTool.ts b/packages/server/src/database/migrations/sqlite/1693924207475-ModifyTool.ts new file mode 100644 index 00000000..ad27eb12 --- /dev/null +++ b/packages/server/src/database/migrations/sqlite/1693924207475-ModifyTool.ts @@ -0,0 +1,18 @@ +import { MigrationInterface, QueryRunner } from 'typeorm' + +export class ModifyTool1693924207475 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `CREATE TABLE "temp_tool" ("id" varchar PRIMARY KEY NOT NULL, "name" varchar NOT NULL, "description" text NOT NULL, "color" varchar NOT NULL, "iconSrc" varchar, "schema" text, "func" text, "createdDate" datetime NOT NULL DEFAULT (datetime('now')), "updatedDate" datetime NOT NULL DEFAULT (datetime('now')));` + ) + await queryRunner.query( + `INSERT INTO "temp_tool" ("id", "name", "description", "color", "iconSrc", "schema", "func", "createdDate", "updatedDate") SELECT "id", "name", "description", "color", "iconSrc", "schema", "func", "createdDate", "updatedDate" FROM "tool";` + ) + await queryRunner.query(`DROP TABLE tool;`) + await queryRunner.query(`ALTER TABLE temp_tool RENAME TO tool;`) + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DROP TABLE temp_tool`) + } +} diff --git a/packages/server/src/database/migrations/sqlite/index.ts b/packages/server/src/database/migrations/sqlite/index.ts index 4a8251a6..c3c1fe7a 100644 --- a/packages/server/src/database/migrations/sqlite/index.ts +++ b/packages/server/src/database/migrations/sqlite/index.ts @@ -2,10 +2,12 @@ import { Init1693835579790 } from './1693835579790-Init' import { ModifyChatFlow1693920824108 } from './1693920824108-ModifyChatFlow' import { ModifyChatMessage1693921865247 } from './1693921865247-ModifyChatMessage' import { ModifyCredential1693923551694 } from './1693923551694-ModifyCredential' +import { ModifyTool1693924207475 } from './1693924207475-ModifyTool' export const sqliteMigrations = [ Init1693835579790, ModifyChatFlow1693920824108, ModifyChatMessage1693921865247, - ModifyCredential1693923551694 + ModifyCredential1693923551694, + ModifyTool1693924207475 ] From 3920441ce06d85b6a7aa6f794c16fbbed791b879 Mon Sep 17 00:00:00 2001 From: Lorenzo Date: Tue, 5 Sep 2023 17:58:10 +0200 Subject: [PATCH 29/53] Added some options for SqlDatabaseChain --- .../SqlDatabaseChain/SqlDatabaseChain.ts | 94 +++++++++++++++++-- 1 file changed, 86 insertions(+), 8 deletions(-) diff --git a/packages/components/nodes/chains/SqlDatabaseChain/SqlDatabaseChain.ts b/packages/components/nodes/chains/SqlDatabaseChain/SqlDatabaseChain.ts index 04d704a5..0e4d1894 100644 --- a/packages/components/nodes/chains/SqlDatabaseChain/SqlDatabaseChain.ts +++ b/packages/components/nodes/chains/SqlDatabaseChain/SqlDatabaseChain.ts @@ -43,7 +43,7 @@ class SqlDatabaseChain_Chains implements INode { constructor() { this.label = 'Sql Database Chain' this.name = 'sqlDatabaseChain' - this.version = 2.0 + this.version = 3.0 this.type = 'SqlDatabaseChain' this.icon = 'sqlchain.svg' this.category = 'Chains' @@ -85,6 +85,41 @@ class SqlDatabaseChain_Chains implements INode { type: 'string', placeholder: '1270.0.0.1:5432/chinook' }, + { + label: 'Include Tables', + name: 'includesTables', + type: 'string', + description: 'Tables to include for queries.', + additionalParams: true, + optional: true + }, + { + label: 'Ignore Tables', + name: 'ignoreTables', + type: 'string', + description: 'Tables to ignore for queries.', + additionalParams: true, + optional: true + }, + { + label: "Sample table's rows info", + name: 'sampleRowsInTableInfo', + type: 'number', + description: 'Number of sample row for tables to load for info.', + placeholder: '3', + additionalParams: true, + optional: true + }, + { + label: 'Top Keys', + name: 'topK', + type: 'number', + description: + 'If you are querying for several rows of a table you can select the maximum number of results you want to get by using the "top_k" parameter (default is 10). This is useful for avoiding query results that exceed the prompt max length or consume tokens unnecessarily.', + placeholder: '10', + additionalParams: true, + optional: true + }, { label: 'Custom Prompt', name: 'customPrompt', @@ -105,9 +140,24 @@ class SqlDatabaseChain_Chains implements INode { const databaseType = nodeData.inputs?.database as DatabaseType const model = nodeData.inputs?.model as BaseLanguageModel const url = nodeData.inputs?.url - const customPrompt = nodeData.inputs?.customPrompt as string + const includesTables = nodeData.inputs?.includesTables + const splittedIncludesTables = includesTables == '' ? undefined : includesTables?.split(',') + const ignoreTables = nodeData.inputs?.ignoreTables?.split(',') + const splittedIgnoreTables = ignoreTables == '' ? undefined : includesTables?.split(',') + const sampleRowsInTableInfo = nodeData.inputs?.sampleRowsInTableInfo + const topK = nodeData.inputs?.topK + const customPrompt = nodeData.inputs?.customPrompt - const chain = await getSQLDBChain(databaseType, url, model, customPrompt) + const chain = await getSQLDBChain( + databaseType, + url, + model, + splittedIncludesTables, + splittedIgnoreTables, + sampleRowsInTableInfo, + topK, + customPrompt + ) return chain } @@ -115,9 +165,24 @@ class SqlDatabaseChain_Chains implements INode { const databaseType = nodeData.inputs?.database as DatabaseType const model = nodeData.inputs?.model as BaseLanguageModel const url = nodeData.inputs?.url - const customPrompt = nodeData.inputs?.customPrompt as string + const includesTables = nodeData.inputs?.includesTables + const splittedIncludesTables = includesTables == '' ? undefined : includesTables?.split(',') + const ignoreTables = nodeData.inputs?.ignoreTables?.split(',') + const splittedIgnoreTables = ignoreTables == '' ? undefined : includesTables?.split(',') + const sampleRowsInTableInfo = nodeData.inputs?.sampleRowsInTableInfo + const topK = nodeData.inputs?.topK + const customPrompt = nodeData.inputs?.customPrompt - const chain = await getSQLDBChain(databaseType, url, model, customPrompt) + const chain = await getSQLDBChain( + databaseType, + url, + model, + splittedIncludesTables, + splittedIgnoreTables, + sampleRowsInTableInfo, + topK, + customPrompt + ) const loggerHandler = new ConsoleCallbackHandler(options.logger) if (options.socketIO && options.socketIOClientId) { @@ -131,7 +196,16 @@ class SqlDatabaseChain_Chains implements INode { } } -const getSQLDBChain = async (databaseType: DatabaseType, url: string, llm: BaseLanguageModel, customPrompt?: string) => { +const getSQLDBChain = async ( + databaseType: DatabaseType, + url: string, + llm: BaseLanguageModel, + includesTables?: string[], + ignoreTables?: string[], + sampleRowsInTableInfo?: number, + topK?: number, + customPrompt?: string +) => { const datasource = new DataSource( databaseType === 'sqlite' ? { @@ -145,13 +219,17 @@ const getSQLDBChain = async (databaseType: DatabaseType, url: string, llm: BaseL ) const db = await SqlDatabase.fromDataSourceParams({ - appDataSource: datasource + appDataSource: datasource, + includesTables: includesTables, + ignoreTables: ignoreTables, + sampleRowsInTableInfo: sampleRowsInTableInfo }) const obj: SqlDatabaseChainInput = { llm, database: db, - verbose: process.env.DEBUG === 'true' ? true : false + verbose: process.env.DEBUG === 'true' ? true : false, + topK: topK } if (customPrompt) { From 86e09d726ab54715f3b91207e2f16bc8ebe25a98 Mon Sep 17 00:00:00 2001 From: Pooria Arab <42897904+pooriaarab@users.noreply.github.com> Date: Tue, 5 Sep 2023 11:23:08 -0700 Subject: [PATCH 30/53] Update Chroma_Existing.ts to add metadatafilter --- .../nodes/vectorstores/Chroma/Chroma_Existing.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/components/nodes/vectorstores/Chroma/Chroma_Existing.ts b/packages/components/nodes/vectorstores/Chroma/Chroma_Existing.ts index f55faa40..1d360182 100644 --- a/packages/components/nodes/vectorstores/Chroma/Chroma_Existing.ts +++ b/packages/components/nodes/vectorstores/Chroma/Chroma_Existing.ts @@ -51,6 +51,13 @@ class Chroma_Existing_VectorStores implements INode { type: 'string', optional: true }, + { + label: 'Chroma Metadata Filter', + name: 'chromaMetadataFilter', + type: 'json', + optional: true, + additionalParams: true + }, { label: 'Top K', name: 'topK', @@ -86,13 +93,18 @@ class Chroma_Existing_VectorStores implements INode { const credentialData = await getCredentialData(nodeData.credential ?? '', options) const chromaApiKey = getCredentialParam('chromaApiKey', credentialData, nodeData) + const chromaMetadataFilter = nodeData.inputs?.chromaMetadataFilter; + const metadataFilter = chromaMetadataFilter ? JSON.parse(chromaMetadataFilter) : {}; + const obj: { collectionName: string url?: string chromaApiKey?: string + metadataFilter?: any } = { collectionName } if (chromaURL) obj.url = chromaURL if (chromaApiKey) obj.chromaApiKey = chromaApiKey + if (chromaMetadataFilter) obj.metadataFilter = metadataFilter const vectorStore = await ChromaExtended.fromExistingCollection(embeddings, obj) From e5167f3e20de169c8363777cb2a1106ed040715f Mon Sep 17 00:00:00 2001 From: Martin Andrews Date: Tue, 5 Sep 2023 18:43:14 +0000 Subject: [PATCH 31/53] First draft of PaLM API LLM component --- .../GoogleMakerSuite.credential.ts | 23 +++ .../nodes/llms/GooglePaLM/GooglePaLM.ts | 158 ++++++++++++++++++ .../llms/GooglePaLM/Google_PaLM_Logo.svg | 67 ++++++++ packages/components/package.json | 1 + 4 files changed, 249 insertions(+) create mode 100644 packages/components/credentials/GoogleMakerSuite.credential.ts create mode 100644 packages/components/nodes/llms/GooglePaLM/GooglePaLM.ts create mode 100644 packages/components/nodes/llms/GooglePaLM/Google_PaLM_Logo.svg diff --git a/packages/components/credentials/GoogleMakerSuite.credential.ts b/packages/components/credentials/GoogleMakerSuite.credential.ts new file mode 100644 index 00000000..83b850a3 --- /dev/null +++ b/packages/components/credentials/GoogleMakerSuite.credential.ts @@ -0,0 +1,23 @@ +import { INodeParams, INodeCredential } from '../src/Interface' + +class GoogleMakerSuite implements INodeCredential { + label: string + name: string + version: number + inputs: INodeParams[] + + constructor() { + this.label = 'Google MakerSuite' + this.name = 'googleMakerSuite' + this.version = 1.0 + this.inputs = [ + { + label: 'MakerSuite API Key', + name: 'googleMakerSuiteKey', + type: 'password' + } + ] + } +} + +module.exports = { credClass: GoogleMakerSuite } diff --git a/packages/components/nodes/llms/GooglePaLM/GooglePaLM.ts b/packages/components/nodes/llms/GooglePaLM/GooglePaLM.ts new file mode 100644 index 00000000..c286531c --- /dev/null +++ b/packages/components/nodes/llms/GooglePaLM/GooglePaLM.ts @@ -0,0 +1,158 @@ +import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface' +import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils' +import { GooglePaLM, GooglePaLMTextInput } from 'langchain/llms/googlepalm' + +class GooglePaLM_LLMs implements INode { + label: string + name: string + version: number + type: string + icon: string + category: string + description: string + baseClasses: string[] + credential: INodeParams + inputs: INodeParams[] + + constructor() { + this.label = 'GooglePaLM' + this.name = 'GooglePaLM' + this.version = 1.0 + this.type = 'GooglePaLM' + this.icon = 'Google_PaLM_Logo.svg' + this.category = 'LLMs' + this.description = 'Wrapper around Google MakerSuite PaLM large language models' + this.baseClasses = [this.type, ...getBaseClasses(GooglePaLM)] + this.credential = { + label: 'Connect Credential', + name: 'credential', + type: 'credential', + credentialNames: ['googleMakerSuite'], + description: + 'Google MakerSuite API credential. Get this from https://makersuite.google.com/app/apikey' + + } + this.inputs = [ + { + label: 'Model Name', + name: 'modelName', + type: 'options', + options: [ + { + label: 'models/text-bison-001', + name: 'models/text-bison-001' + } + ], + default: 'models/text-bison-001', + optional: true + }, + { + label: 'Temperature', + name: 'temperature', + type: 'number', + step: 0.1, + default: 0.7, + optional: true, + description: "Controls the randomness of the output.\n"+ + "Values can range from [0.0,1.0], inclusive. A value closer to 1.0 "+ + "will produce responses that are more varied and creative, while"+ + "a value closer to 0.0 will typically result in more straightforward"+ + "responses from the model." + }, + { + label: 'Max Output Tokens', + name: 'maxOutputTokens', + type: 'number', + step: 1, + optional: true, + additionalParams: true, + description: "Maximum number of tokens to generate in the completion." + }, + { + label: 'Top Probability', + name: 'topP', + type: 'number', + step: 0.1, + optional: true, + additionalParams: true, + description: "Top-p changes how the model selects tokens for output.\n"+ + "Tokens are selected from most probable to least until "+ + "the sum of their probabilities equals the top-p value.\n"+ + "For example, if tokens A, B, and C have a probability of .3, .2, and .1 "+ + "and the top-p value is .5, then the model will select either A or B "+ + "as the next token (using temperature)." + }, + { + label: 'Top-k', + name: 'topK', + type: 'number', + step: 1, + optional: true, + additionalParams: true, + description: "Top-k changes how the model selects tokens for output.\n"+ + "A top-k of 1 means the selected token is the most probable among "+ + "all tokens in the model’s vocabulary (also called greedy decoding), "+ + "while a top-k of 3 means that the next token is selected from "+ + "among the 3 most probable tokens (using temperature)." + }, + { + label: 'Stop Sequences', + name: 'stopSequencesObj', + type: 'json', + optional: true, + additionalParams: true + //default: { list:[] }, + //description: + // "The 'list' field should contain a list of character strings (up to 5) that will stop output generation.\n"+ + // " * If specified, the API will stop at the first appearance of a stop sequence.\n"+ + // "Note: The stop sequence will not be included as part of the response." + } + /* + { + label: 'Safety Settings', + name: 'safetySettings', + type: 'json', + optional: true, + additionalParams: true + } + */ + ] + } + + async init(nodeData: INodeData, _: string, options: ICommonObject): Promise { + const modelName = nodeData.inputs?.modelName as string + const temperature = nodeData.inputs?.temperature as string + const maxOutputTokens = nodeData.inputs?.maxOutputTokens as string + const topP = nodeData.inputs?.topP as string + const topK = nodeData.inputs?.topK as string + const stopSequencesObj = nodeData.inputs?.stopSequencesObj + + const credentialData = await getCredentialData(nodeData.credential ?? '', options) + const googleMakerSuiteKey = getCredentialParam('googleMakerSuiteKey', credentialData, nodeData) + + const obj: Partial = { + modelName: modelName, + temperature: parseFloat(temperature), + apiKey: googleMakerSuiteKey + } + + if (maxOutputTokens) obj.maxOutputTokens = parseInt(maxOutputTokens, 10) + if (topP) obj.topP = parseFloat(topP) + if (topK) obj.topK = parseFloat(topK) + + let parsedStopSequences: any | undefined = undefined + if (stopSequencesObj) { + try { + parsedStopSequences = typeof stopSequencesObj === 'object' ? stopSequencesObj : JSON.parse(stopSequencesObj) + obj.stopSequences = parsedStopSequences.list || [] + } catch (exception) { + throw new Error("Invalid JSON in the GooglePaLM's stopSequences: " + exception) + } + } + + const model = new GooglePaLM(obj) + return model + } +} + +module.exports = { nodeClass: GooglePaLM_LLMs } diff --git a/packages/components/nodes/llms/GooglePaLM/Google_PaLM_Logo.svg b/packages/components/nodes/llms/GooglePaLM/Google_PaLM_Logo.svg new file mode 100644 index 00000000..5c345fe1 --- /dev/null +++ b/packages/components/nodes/llms/GooglePaLM/Google_PaLM_Logo.svg @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/components/package.json b/packages/components/package.json index 1837609e..d3dd4e53 100644 --- a/packages/components/package.json +++ b/packages/components/package.json @@ -19,6 +19,7 @@ "@aws-sdk/client-dynamodb": "^3.360.0", "@dqbd/tiktoken": "^1.0.7", "@getzep/zep-js": "^0.6.3", + "@google-ai/generativelanguage": "^0.2.1", "@huggingface/inference": "^2.6.1", "@notionhq/client": "^2.2.8", "@opensearch-project/opensearch": "^1.2.0", From 19824bf3399b7ad9fb00639a39885f096cc14df3 Mon Sep 17 00:00:00 2001 From: Martin Andrews Date: Wed, 6 Sep 2023 08:41:12 +0000 Subject: [PATCH 32/53] Moved APIkey helper text, and fixed linter complaints --- .../GoogleMakerSuite.credential.ts | 3 + .../nodes/llms/GooglePaLM/GooglePaLM.ts | 58 +++++++++---------- 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/packages/components/credentials/GoogleMakerSuite.credential.ts b/packages/components/credentials/GoogleMakerSuite.credential.ts index 83b850a3..f37cbf88 100644 --- a/packages/components/credentials/GoogleMakerSuite.credential.ts +++ b/packages/components/credentials/GoogleMakerSuite.credential.ts @@ -4,12 +4,15 @@ class GoogleMakerSuite implements INodeCredential { label: string name: string version: number + description: string inputs: INodeParams[] constructor() { this.label = 'Google MakerSuite' this.name = 'googleMakerSuite' this.version = 1.0 + this.description = + 'Use the Google MakerSuite API credential site to get this key.' this.inputs = [ { label: 'MakerSuite API Key', diff --git a/packages/components/nodes/llms/GooglePaLM/GooglePaLM.ts b/packages/components/nodes/llms/GooglePaLM/GooglePaLM.ts index c286531c..24630360 100644 --- a/packages/components/nodes/llms/GooglePaLM/GooglePaLM.ts +++ b/packages/components/nodes/llms/GooglePaLM/GooglePaLM.ts @@ -27,12 +27,9 @@ class GooglePaLM_LLMs implements INode { label: 'Connect Credential', name: 'credential', type: 'credential', - credentialNames: ['googleMakerSuite'], - description: - 'Google MakerSuite API credential. Get this from https://makersuite.google.com/app/apikey' - + credentialNames: ['googleMakerSuite'] } - this.inputs = [ + this.inputs = [ { label: 'Model Name', name: 'modelName', @@ -52,12 +49,13 @@ class GooglePaLM_LLMs implements INode { type: 'number', step: 0.1, default: 0.7, - optional: true, - description: "Controls the randomness of the output.\n"+ - "Values can range from [0.0,1.0], inclusive. A value closer to 1.0 "+ - "will produce responses that are more varied and creative, while"+ - "a value closer to 0.0 will typically result in more straightforward"+ - "responses from the model." + optional: true, + description: + 'Controls the randomness of the output.\n' + + 'Values can range from [0.0,1.0], inclusive. A value closer to 1.0 ' + + 'will produce responses that are more varied and creative, while ' + + 'a value closer to 0.0 will typically result in more straightforward ' + + 'responses from the model.' }, { label: 'Max Output Tokens', @@ -66,7 +64,7 @@ class GooglePaLM_LLMs implements INode { step: 1, optional: true, additionalParams: true, - description: "Maximum number of tokens to generate in the completion." + description: 'Maximum number of tokens to generate in the completion.' }, { label: 'Top Probability', @@ -74,13 +72,14 @@ class GooglePaLM_LLMs implements INode { type: 'number', step: 0.1, optional: true, - additionalParams: true, - description: "Top-p changes how the model selects tokens for output.\n"+ - "Tokens are selected from most probable to least until "+ - "the sum of their probabilities equals the top-p value.\n"+ - "For example, if tokens A, B, and C have a probability of .3, .2, and .1 "+ - "and the top-p value is .5, then the model will select either A or B "+ - "as the next token (using temperature)." + additionalParams: true, + description: + 'Top-p changes how the model selects tokens for output.\n' + + 'Tokens are selected from most probable to least until ' + + 'the sum of their probabilities equals the top-p value.\n' + + 'For example, if tokens A, B, and C have a probability of .3, .2, and .1 ' + + 'and the top-p value is .5, then the model will select either A or B ' + + 'as the next token (using temperature).' }, { label: 'Top-k', @@ -89,11 +88,12 @@ class GooglePaLM_LLMs implements INode { step: 1, optional: true, additionalParams: true, - description: "Top-k changes how the model selects tokens for output.\n"+ - "A top-k of 1 means the selected token is the most probable among "+ - "all tokens in the model’s vocabulary (also called greedy decoding), "+ - "while a top-k of 3 means that the next token is selected from "+ - "among the 3 most probable tokens (using temperature)." + description: + 'Top-k changes how the model selects tokens for output.\n' + + 'A top-k of 1 means the selected token is the most probable among ' + + 'all tokens in the model vocabulary (also called greedy decoding), ' + + 'while a top-k of 3 means that the next token is selected from ' + + 'among the 3 most probable tokens (using temperature).' }, { label: 'Stop Sequences', @@ -102,11 +102,11 @@ class GooglePaLM_LLMs implements INode { optional: true, additionalParams: true //default: { list:[] }, - //description: - // "The 'list' field should contain a list of character strings (up to 5) that will stop output generation.\n"+ - // " * If specified, the API will stop at the first appearance of a stop sequence.\n"+ - // "Note: The stop sequence will not be included as part of the response." - } + //description: + // 'The "list" field should contain a list of character strings (up to 5) that will stop output generation.\n' + + // ' * If specified, the API will stop at the first appearance of a stop sequence.\n' + + // 'Note: The stop sequence will not be included as part of the response.' + } /* { label: 'Safety Settings', From 6f1f5ef06b58afd1c6780e46e2e1aeaae1c26e54 Mon Sep 17 00:00:00 2001 From: chungyau97 Date: Wed, 6 Sep 2023 18:37:30 +0800 Subject: [PATCH 33/53] add postgres modify chatflow --- .../postgres/1693995626941-ModifyChatFlow.ts | 11 +++++++++++ .../server/src/database/migrations/postgres/index.ts | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 packages/server/src/database/migrations/postgres/1693995626941-ModifyChatFlow.ts diff --git a/packages/server/src/database/migrations/postgres/1693995626941-ModifyChatFlow.ts b/packages/server/src/database/migrations/postgres/1693995626941-ModifyChatFlow.ts new file mode 100644 index 00000000..86f09430 --- /dev/null +++ b/packages/server/src/database/migrations/postgres/1693995626941-ModifyChatFlow.ts @@ -0,0 +1,11 @@ +import { MigrationInterface, QueryRunner } from 'typeorm' + +export class ModifyChatFlow1693995626941 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "chat_flow" ALTER COLUMN "chatbotConfig" TYPE TEXT`) + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "chat_flow" ALTER COLUMN "chatbotConfig" TYPE VARCHAR`) + } +} diff --git a/packages/server/src/database/migrations/postgres/index.ts b/packages/server/src/database/migrations/postgres/index.ts index c8805785..ac03fcc4 100644 --- a/packages/server/src/database/migrations/postgres/index.ts +++ b/packages/server/src/database/migrations/postgres/index.ts @@ -1,3 +1,4 @@ import { Init1693891895163 } from './1693891895163-Init' +import { ModifyChatFlow1693995626941 } from './1693995626941-ModifyChatFlow' -export const postgresMigrations = [Init1693891895163] +export const postgresMigrations = [Init1693891895163, ModifyChatFlow1693995626941] From 5facb8fba855713a3b0e756c8854a053f0a7e8b1 Mon Sep 17 00:00:00 2001 From: chungyau97 Date: Wed, 6 Sep 2023 18:43:52 +0800 Subject: [PATCH 34/53] add postgres modify chatmessage --- .../postgres/1693996694528-ModifyChatMessage.ts | 11 +++++++++++ .../server/src/database/migrations/postgres/index.ts | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 packages/server/src/database/migrations/postgres/1693996694528-ModifyChatMessage.ts diff --git a/packages/server/src/database/migrations/postgres/1693996694528-ModifyChatMessage.ts b/packages/server/src/database/migrations/postgres/1693996694528-ModifyChatMessage.ts new file mode 100644 index 00000000..4933e8f7 --- /dev/null +++ b/packages/server/src/database/migrations/postgres/1693996694528-ModifyChatMessage.ts @@ -0,0 +1,11 @@ +import { MigrationInterface, QueryRunner } from 'typeorm' + +export class ModifyChatMessage1693996694528 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "chat_message" ALTER COLUMN "sourceDocuments" TYPE TEXT`) + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "chat_message" ALTER COLUMN "sourceDocuments" TYPE VARCHAR`) + } +} diff --git a/packages/server/src/database/migrations/postgres/index.ts b/packages/server/src/database/migrations/postgres/index.ts index ac03fcc4..be15aab0 100644 --- a/packages/server/src/database/migrations/postgres/index.ts +++ b/packages/server/src/database/migrations/postgres/index.ts @@ -1,4 +1,5 @@ import { Init1693891895163 } from './1693891895163-Init' import { ModifyChatFlow1693995626941 } from './1693995626941-ModifyChatFlow' +import { ModifyChatMessage1693996694528 } from './1693996694528-ModifyChatMessage' -export const postgresMigrations = [Init1693891895163, ModifyChatFlow1693995626941] +export const postgresMigrations = [Init1693891895163, ModifyChatFlow1693995626941, ModifyChatMessage1693996694528] From d92ca34b00a21fcafbbc9ae5f5101dd5006ab6d6 Mon Sep 17 00:00:00 2001 From: chungyau97 Date: Wed, 6 Sep 2023 18:48:18 +0800 Subject: [PATCH 35/53] add postgres modify credential --- .../postgres/1693997070000-ModifyCredential.ts | 11 +++++++++++ .../server/src/database/migrations/postgres/index.ts | 8 +++++++- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 packages/server/src/database/migrations/postgres/1693997070000-ModifyCredential.ts diff --git a/packages/server/src/database/migrations/postgres/1693997070000-ModifyCredential.ts b/packages/server/src/database/migrations/postgres/1693997070000-ModifyCredential.ts new file mode 100644 index 00000000..b19ec428 --- /dev/null +++ b/packages/server/src/database/migrations/postgres/1693997070000-ModifyCredential.ts @@ -0,0 +1,11 @@ +import { MigrationInterface, QueryRunner } from 'typeorm' + +export class ModifyCredential1693997070000 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "credential" ALTER COLUMN "encryptedData" TYPE TEXT`) + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "credential" ALTER COLUMN "encryptedData" TYPE VARCHAR`) + } +} diff --git a/packages/server/src/database/migrations/postgres/index.ts b/packages/server/src/database/migrations/postgres/index.ts index be15aab0..55fe514b 100644 --- a/packages/server/src/database/migrations/postgres/index.ts +++ b/packages/server/src/database/migrations/postgres/index.ts @@ -1,5 +1,11 @@ import { Init1693891895163 } from './1693891895163-Init' import { ModifyChatFlow1693995626941 } from './1693995626941-ModifyChatFlow' import { ModifyChatMessage1693996694528 } from './1693996694528-ModifyChatMessage' +import { ModifyCredential1693997070000 } from './1693997070000-ModifyCredential' -export const postgresMigrations = [Init1693891895163, ModifyChatFlow1693995626941, ModifyChatMessage1693996694528] +export const postgresMigrations = [ + Init1693891895163, + ModifyChatFlow1693995626941, + ModifyChatMessage1693996694528, + ModifyCredential1693997070000 +] From 0d6d15ecf445948cf33dd28617942cba22b252e9 Mon Sep 17 00:00:00 2001 From: chungyau97 Date: Wed, 6 Sep 2023 18:55:35 +0800 Subject: [PATCH 36/53] add postgres modify tool --- .../postgres/1693995626941-ModifyChatFlow.ts | 4 ++-- .../postgres/1693996694528-ModifyChatMessage.ts | 4 ++-- .../postgres/1693997070000-ModifyCredential.ts | 4 ++-- .../migrations/postgres/1693997339912-ModifyTool.ts | 11 +++++++++++ .../server/src/database/migrations/postgres/index.ts | 4 +++- 5 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 packages/server/src/database/migrations/postgres/1693997339912-ModifyTool.ts diff --git a/packages/server/src/database/migrations/postgres/1693995626941-ModifyChatFlow.ts b/packages/server/src/database/migrations/postgres/1693995626941-ModifyChatFlow.ts index 86f09430..aee6d3fe 100644 --- a/packages/server/src/database/migrations/postgres/1693995626941-ModifyChatFlow.ts +++ b/packages/server/src/database/migrations/postgres/1693995626941-ModifyChatFlow.ts @@ -2,10 +2,10 @@ import { MigrationInterface, QueryRunner } from 'typeorm' export class ModifyChatFlow1693995626941 implements MigrationInterface { public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE "chat_flow" ALTER COLUMN "chatbotConfig" TYPE TEXT`) + await queryRunner.query(`ALTER TABLE "chat_flow" ALTER COLUMN "chatbotConfig" TYPE TEXT;`) } public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE "chat_flow" ALTER COLUMN "chatbotConfig" TYPE VARCHAR`) + await queryRunner.query(`ALTER TABLE "chat_flow" ALTER COLUMN "chatbotConfig" TYPE VARCHAR;`) } } diff --git a/packages/server/src/database/migrations/postgres/1693996694528-ModifyChatMessage.ts b/packages/server/src/database/migrations/postgres/1693996694528-ModifyChatMessage.ts index 4933e8f7..da288783 100644 --- a/packages/server/src/database/migrations/postgres/1693996694528-ModifyChatMessage.ts +++ b/packages/server/src/database/migrations/postgres/1693996694528-ModifyChatMessage.ts @@ -2,10 +2,10 @@ import { MigrationInterface, QueryRunner } from 'typeorm' export class ModifyChatMessage1693996694528 implements MigrationInterface { public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE "chat_message" ALTER COLUMN "sourceDocuments" TYPE TEXT`) + await queryRunner.query(`ALTER TABLE "chat_message" ALTER COLUMN "sourceDocuments" TYPE TEXT;`) } public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE "chat_message" ALTER COLUMN "sourceDocuments" TYPE VARCHAR`) + await queryRunner.query(`ALTER TABLE "chat_message" ALTER COLUMN "sourceDocuments" TYPE VARCHAR;`) } } diff --git a/packages/server/src/database/migrations/postgres/1693997070000-ModifyCredential.ts b/packages/server/src/database/migrations/postgres/1693997070000-ModifyCredential.ts index b19ec428..ef45201a 100644 --- a/packages/server/src/database/migrations/postgres/1693997070000-ModifyCredential.ts +++ b/packages/server/src/database/migrations/postgres/1693997070000-ModifyCredential.ts @@ -2,10 +2,10 @@ import { MigrationInterface, QueryRunner } from 'typeorm' export class ModifyCredential1693997070000 implements MigrationInterface { public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE "credential" ALTER COLUMN "encryptedData" TYPE TEXT`) + await queryRunner.query(`ALTER TABLE "credential" ALTER COLUMN "encryptedData" TYPE TEXT;`) } public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE "credential" ALTER COLUMN "encryptedData" TYPE VARCHAR`) + await queryRunner.query(`ALTER TABLE "credential" ALTER COLUMN "encryptedData" TYPE VARCHAR;`) } } diff --git a/packages/server/src/database/migrations/postgres/1693997339912-ModifyTool.ts b/packages/server/src/database/migrations/postgres/1693997339912-ModifyTool.ts new file mode 100644 index 00000000..a4bf95c4 --- /dev/null +++ b/packages/server/src/database/migrations/postgres/1693997339912-ModifyTool.ts @@ -0,0 +1,11 @@ +import { MigrationInterface, QueryRunner } from 'typeorm' + +export class ModifyTool1693997339912 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "tool" ALTER COLUMN "schema" TYPE TEXT, ALTER COLUMN "func" TYPE TEXT;`) + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "tool" ALTER COLUMN "schema" TYPE VARCHAR, ALTER COLUMN "func" TYPE VARCHAR;`) + } +} diff --git a/packages/server/src/database/migrations/postgres/index.ts b/packages/server/src/database/migrations/postgres/index.ts index 55fe514b..2bac9f33 100644 --- a/packages/server/src/database/migrations/postgres/index.ts +++ b/packages/server/src/database/migrations/postgres/index.ts @@ -2,10 +2,12 @@ import { Init1693891895163 } from './1693891895163-Init' import { ModifyChatFlow1693995626941 } from './1693995626941-ModifyChatFlow' import { ModifyChatMessage1693996694528 } from './1693996694528-ModifyChatMessage' import { ModifyCredential1693997070000 } from './1693997070000-ModifyCredential' +import { ModifyTool1693997339912 } from './1693997339912-ModifyTool' export const postgresMigrations = [ Init1693891895163, ModifyChatFlow1693995626941, ModifyChatMessage1693996694528, - ModifyCredential1693997070000 + ModifyCredential1693997070000, + ModifyTool1693997339912 ] From fa1060f9eb025781f65f5a63b197430794eb8eb1 Mon Sep 17 00:00:00 2001 From: chungyau97 Date: Wed, 6 Sep 2023 19:15:53 +0800 Subject: [PATCH 37/53] add mysql modify chat_flow --- .../migrations/mysql/1693997791471-ModifyChatFlow.ts | 11 +++++++++++ .../server/src/database/migrations/mysql/index.ts | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 packages/server/src/database/migrations/mysql/1693997791471-ModifyChatFlow.ts diff --git a/packages/server/src/database/migrations/mysql/1693997791471-ModifyChatFlow.ts b/packages/server/src/database/migrations/mysql/1693997791471-ModifyChatFlow.ts new file mode 100644 index 00000000..d0023b67 --- /dev/null +++ b/packages/server/src/database/migrations/mysql/1693997791471-ModifyChatFlow.ts @@ -0,0 +1,11 @@ +import { MigrationInterface, QueryRunner } from 'typeorm' + +export class ModifyChatFlow1693997791471 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`chat_flow\` MODIFY \`chatbotConfig\` TEXT;`) + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`chat_flow\` MODIFY \`chatbotConfig\` VARCHAR;`) + } +} diff --git a/packages/server/src/database/migrations/mysql/index.ts b/packages/server/src/database/migrations/mysql/index.ts index 79fa17ad..45102969 100644 --- a/packages/server/src/database/migrations/mysql/index.ts +++ b/packages/server/src/database/migrations/mysql/index.ts @@ -1,3 +1,4 @@ import { Init1693840429259 } from './1693840429259-Init' +import { ModifyChatFlow1693997791471 } from './1693997791471-ModifyChatFlow' -export const mysqlMigrations = [Init1693840429259] +export const mysqlMigrations = [Init1693840429259, ModifyChatFlow1693997791471] From 1d4761dc2cc579db2e1368af74285002b5905dfa Mon Sep 17 00:00:00 2001 From: chungyau97 Date: Wed, 6 Sep 2023 19:20:15 +0800 Subject: [PATCH 38/53] add mysql modify chat_message --- .../mysql/1693999022236-ModifyChatMessage.ts | 11 +++++++++++ .../server/src/database/migrations/mysql/index.ts | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 packages/server/src/database/migrations/mysql/1693999022236-ModifyChatMessage.ts diff --git a/packages/server/src/database/migrations/mysql/1693999022236-ModifyChatMessage.ts b/packages/server/src/database/migrations/mysql/1693999022236-ModifyChatMessage.ts new file mode 100644 index 00000000..3f6eaa4e --- /dev/null +++ b/packages/server/src/database/migrations/mysql/1693999022236-ModifyChatMessage.ts @@ -0,0 +1,11 @@ +import { MigrationInterface, QueryRunner } from 'typeorm' + +export class ModifyChatMessage1693999022236 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`chat_message\` MODIFY \`sourceDocuments\` TEXT;`) + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`chat_message\` MODIFY \`sourceDocuments\` VARCHAR;`) + } +} diff --git a/packages/server/src/database/migrations/mysql/index.ts b/packages/server/src/database/migrations/mysql/index.ts index 45102969..d62545bf 100644 --- a/packages/server/src/database/migrations/mysql/index.ts +++ b/packages/server/src/database/migrations/mysql/index.ts @@ -1,4 +1,5 @@ import { Init1693840429259 } from './1693840429259-Init' import { ModifyChatFlow1693997791471 } from './1693997791471-ModifyChatFlow' +import { ModifyChatMessage1693999022236 } from './1693999022236-ModifyChatMessage' -export const mysqlMigrations = [Init1693840429259, ModifyChatFlow1693997791471] +export const mysqlMigrations = [Init1693840429259, ModifyChatFlow1693997791471, ModifyChatMessage1693999022236] From b9bdf8435c6a7cabcbf5a884343cf93faeed0b7a Mon Sep 17 00:00:00 2001 From: chungyau97 Date: Wed, 6 Sep 2023 19:56:18 +0800 Subject: [PATCH 39/53] add mysql modify credential --- .../mysql/1693999261583-ModifyCredential.ts | 11 +++++++++++ .../server/src/database/migrations/mysql/index.ts | 8 +++++++- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 packages/server/src/database/migrations/mysql/1693999261583-ModifyCredential.ts diff --git a/packages/server/src/database/migrations/mysql/1693999261583-ModifyCredential.ts b/packages/server/src/database/migrations/mysql/1693999261583-ModifyCredential.ts new file mode 100644 index 00000000..54c33af1 --- /dev/null +++ b/packages/server/src/database/migrations/mysql/1693999261583-ModifyCredential.ts @@ -0,0 +1,11 @@ +import { MigrationInterface, QueryRunner } from 'typeorm' + +export class ModifyCredential1693999261583 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`credential\` MODIFY \`encryptedData\` TEXT NOT NULL;`) + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`credential\` MODIFY \`encryptedData\` VARCHAR NOT NULL;`) + } +} diff --git a/packages/server/src/database/migrations/mysql/index.ts b/packages/server/src/database/migrations/mysql/index.ts index d62545bf..f946cb5f 100644 --- a/packages/server/src/database/migrations/mysql/index.ts +++ b/packages/server/src/database/migrations/mysql/index.ts @@ -1,5 +1,11 @@ import { Init1693840429259 } from './1693840429259-Init' import { ModifyChatFlow1693997791471 } from './1693997791471-ModifyChatFlow' import { ModifyChatMessage1693999022236 } from './1693999022236-ModifyChatMessage' +import { ModifyCredential1693999261583 } from './1693999261583-ModifyCredential' -export const mysqlMigrations = [Init1693840429259, ModifyChatFlow1693997791471, ModifyChatMessage1693999022236] +export const mysqlMigrations = [ + Init1693840429259, + ModifyChatFlow1693997791471, + ModifyChatMessage1693999022236, + ModifyCredential1693999261583 +] From 2574b02dd7717ad2184b59bcdee89648311942f1 Mon Sep 17 00:00:00 2001 From: chungyau97 Date: Wed, 6 Sep 2023 20:03:06 +0800 Subject: [PATCH 40/53] add mysql modify tool --- .../migrations/mysql/1694001465232-ModifyTool.ts | 11 +++++++++++ .../server/src/database/migrations/mysql/index.ts | 4 +++- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 packages/server/src/database/migrations/mysql/1694001465232-ModifyTool.ts diff --git a/packages/server/src/database/migrations/mysql/1694001465232-ModifyTool.ts b/packages/server/src/database/migrations/mysql/1694001465232-ModifyTool.ts new file mode 100644 index 00000000..934506cb --- /dev/null +++ b/packages/server/src/database/migrations/mysql/1694001465232-ModifyTool.ts @@ -0,0 +1,11 @@ +import { MigrationInterface, QueryRunner } from 'typeorm' + +export class ModifyTool1694001465232 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`tool\` MODIFY \`schema\` TEXT, MODIFY \`func\` TEXT;`) + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`tool\` MODIFY \`schema\` VARCHAR, MODIFY \`func\` VARCHAR;`) + } +} diff --git a/packages/server/src/database/migrations/mysql/index.ts b/packages/server/src/database/migrations/mysql/index.ts index f946cb5f..124eb70f 100644 --- a/packages/server/src/database/migrations/mysql/index.ts +++ b/packages/server/src/database/migrations/mysql/index.ts @@ -2,10 +2,12 @@ import { Init1693840429259 } from './1693840429259-Init' import { ModifyChatFlow1693997791471 } from './1693997791471-ModifyChatFlow' import { ModifyChatMessage1693999022236 } from './1693999022236-ModifyChatMessage' import { ModifyCredential1693999261583 } from './1693999261583-ModifyCredential' +import { ModifyTool1694001465232 } from './1694001465232-ModifyTool' export const mysqlMigrations = [ Init1693840429259, ModifyChatFlow1693997791471, ModifyChatMessage1693999022236, - ModifyCredential1693999261583 + ModifyCredential1693999261583, + ModifyTool1694001465232 ] From a0b9af975428667817ef43800f7bccc754cd7c3c Mon Sep 17 00:00:00 2001 From: Martin Andrews Date: Thu, 7 Sep 2023 11:09:40 +0000 Subject: [PATCH 41/53] Added Google PaLM chat model --- .../ChatGooglePaLM/ChatGooglePaLM.ts | 140 ++++++++++++++++++ .../ChatGooglePaLM/Google_PaLM_Logo.svg | 67 +++++++++ 2 files changed, 207 insertions(+) create mode 100644 packages/components/nodes/chatmodels/ChatGooglePaLM/ChatGooglePaLM.ts create mode 100644 packages/components/nodes/chatmodels/ChatGooglePaLM/Google_PaLM_Logo.svg diff --git a/packages/components/nodes/chatmodels/ChatGooglePaLM/ChatGooglePaLM.ts b/packages/components/nodes/chatmodels/ChatGooglePaLM/ChatGooglePaLM.ts new file mode 100644 index 00000000..38cb1168 --- /dev/null +++ b/packages/components/nodes/chatmodels/ChatGooglePaLM/ChatGooglePaLM.ts @@ -0,0 +1,140 @@ +import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface' +import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils' +import { ChatGooglePaLM, GooglePaLMChatInput } from 'langchain/chat_models/googlepalm' + +class ChatGooglePaLM_ChatModels implements INode { + label: string + name: string + version: number + type: string + icon: string + category: string + description: string + baseClasses: string[] + credential: INodeParams + inputs: INodeParams[] + + constructor() { + this.label = 'ChatGooglePaLM' + this.name = 'chatGooglePaLM' + this.version = 1.0 + this.type = 'ChatGooglePaLM' + this.icon = 'Google_PaLM_Logo.svg' + this.category = 'Chat Models' + this.description = 'Wrapper around Google MakerSuite PaLM large language models using the Chat endpoint' + this.baseClasses = [this.type, ...getBaseClasses(ChatGooglePaLM)] + this.credential = { + label: 'Connect Credential', + name: 'credential', + type: 'credential', + credentialNames: ['googleMakerSuite'] + } + this.inputs = [ + { + label: 'Model Name', + name: 'modelName', + type: 'options', + options: [ + { + label: 'models/chat-bison-001', + name: 'models/chat-bison-001' + } + ], + default: 'models/chat-bison-001', + optional: true + }, + { + label: 'Temperature', + name: 'temperature', + type: 'number', + step: 0.1, + default: 0.7, + optional: true, + description: + 'Controls the randomness of the output.\n' + + 'Values can range from [0.0,1.0], inclusive. A value closer to 1.0 ' + + 'will produce responses that are more varied and creative, while ' + + 'a value closer to 0.0 will typically result in more straightforward ' + + 'responses from the model.' + }, + { + label: 'Top Probability', + name: 'topP', + type: 'number', + step: 0.1, + optional: true, + additionalParams: true, + description: + 'Top-p changes how the model selects tokens for output.\n' + + 'Tokens are selected from most probable to least until ' + + 'the sum of their probabilities equals the top-p value.\n' + + 'For example, if tokens A, B, and C have a probability of .3, .2, and .1 ' + + 'and the top-p value is .5, then the model will select either A or B ' + + 'as the next token (using temperature).' + }, + { + label: 'Top-k', + name: 'topK', + type: 'number', + step: 1, + optional: true, + additionalParams: true, + description: + 'Top-k changes how the model selects tokens for output.\n' + + 'A top-k of 1 means the selected token is the most probable among ' + + 'all tokens in the model vocabulary (also called greedy decoding), ' + + 'while a top-k of 3 means that the next token is selected from ' + + 'among the 3 most probable tokens (using temperature).' + } + /* + { + label: 'Examples', + name: 'examplesObj', + type: 'json', + optional: true, + additionalParams: true + //default: { list:[] }, + //description: + // 'The "examples" field should contain a list of pairs of strings to use as prior turns for this conversation.' + } + */ + ] + } + + async init(nodeData: INodeData, _: string, options: ICommonObject): Promise { + const modelName = nodeData.inputs?.modelName as string + const temperature = nodeData.inputs?.temperature as string + const topP = nodeData.inputs?.topP as string + const topK = nodeData.inputs?.topK as string + //const examplesObj = nodeData.inputs?.examplesObj + + const credentialData = await getCredentialData(nodeData.credential ?? '', options) + const googleMakerSuiteKey = getCredentialParam('googleMakerSuiteKey', credentialData, nodeData) + + const obj: Partial = { + modelName: modelName, + temperature: parseFloat(temperature), + apiKey: googleMakerSuiteKey + } + + if (topP) obj.topP = parseFloat(topP) + if (topK) obj.topK = parseFloat(topK) + + /* + let parsedExamples: any | undefined = undefined + if (examplesObj) { + try { + parsedExamples = typeof examplseObj === 'object' ? examplseObj : JSON.parse(examplseObj) + obj.examples = parsedExamples.examples || [] + } catch (exception) { + throw new Error("Invalid JSON in the GooglePaLM's examplseObj: " + exception) + } + } + */ + + const model = new ChatGooglePaLM(obj) + return model + } +} + +module.exports = { nodeClass: ChatGooglePaLM_ChatModels } diff --git a/packages/components/nodes/chatmodels/ChatGooglePaLM/Google_PaLM_Logo.svg b/packages/components/nodes/chatmodels/ChatGooglePaLM/Google_PaLM_Logo.svg new file mode 100644 index 00000000..5c345fe1 --- /dev/null +++ b/packages/components/nodes/chatmodels/ChatGooglePaLM/Google_PaLM_Logo.svg @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From bf459bf5abb507df9e3d7b4c22ce92ac93b4d91d Mon Sep 17 00:00:00 2001 From: Pooria Arab <42897904+pooriaarab@users.noreply.github.com> Date: Thu, 7 Sep 2023 08:00:09 -0700 Subject: [PATCH 42/53] Update Chroma_Existing.ts - first OSS PR that works!! --- .../nodes/vectorstores/Chroma/Chroma_Existing.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/components/nodes/vectorstores/Chroma/Chroma_Existing.ts b/packages/components/nodes/vectorstores/Chroma/Chroma_Existing.ts index 1d360182..30662d61 100644 --- a/packages/components/nodes/vectorstores/Chroma/Chroma_Existing.ts +++ b/packages/components/nodes/vectorstores/Chroma/Chroma_Existing.ts @@ -93,18 +93,20 @@ class Chroma_Existing_VectorStores implements INode { const credentialData = await getCredentialData(nodeData.credential ?? '', options) const chromaApiKey = getCredentialParam('chromaApiKey', credentialData, nodeData) - const chromaMetadataFilter = nodeData.inputs?.chromaMetadataFilter; - const metadataFilter = chromaMetadataFilter ? JSON.parse(chromaMetadataFilter) : {}; + const chromaMetadataFilter = nodeData.inputs?.chromaMetadataFilter + const metadataFilter = chromaMetadataFilter ? JSON.parse(chromaMetadataFilter) : {} const obj: { collectionName: string url?: string chromaApiKey?: string - metadataFilter?: any + filter?: object | undefined } = { collectionName } if (chromaURL) obj.url = chromaURL - if (chromaApiKey) obj.chromaApiKey = chromaApiKey - if (chromaMetadataFilter) obj.metadataFilter = metadataFilter + if (chromaMetadataFilter) { + const metadatafilter = typeof chromaMetadataFilter === 'object' ? chromaMetadataFilter : JSON.parse(chromaMetadataFilter) + obj.filter = metadatafilter + } const vectorStore = await ChromaExtended.fromExistingCollection(embeddings, obj) From 43e9b63dcdcc4a35a11e77f181cab4903206960e Mon Sep 17 00:00:00 2001 From: Martin Andrews Date: Thu, 7 Sep 2023 15:03:04 +0000 Subject: [PATCH 43/53] Added Google PaLM embeddings model --- .../GooglePaLMEmbedding.ts | 65 ++++++++++++++++++ .../GooglePaLMEmbedding/Google_PaLM_Logo.svg | 67 +++++++++++++++++++ 2 files changed, 132 insertions(+) create mode 100644 packages/components/nodes/embeddings/GooglePaLMEmbedding/GooglePaLMEmbedding.ts create mode 100644 packages/components/nodes/embeddings/GooglePaLMEmbedding/Google_PaLM_Logo.svg diff --git a/packages/components/nodes/embeddings/GooglePaLMEmbedding/GooglePaLMEmbedding.ts b/packages/components/nodes/embeddings/GooglePaLMEmbedding/GooglePaLMEmbedding.ts new file mode 100644 index 00000000..81507d00 --- /dev/null +++ b/packages/components/nodes/embeddings/GooglePaLMEmbedding/GooglePaLMEmbedding.ts @@ -0,0 +1,65 @@ +import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface' +import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils' +import { GooglePaLMEmbeddings, GooglePaLMEmbeddingsParams } from 'langchain/embeddings/googlepalm' + +class GooglePaLMEmbedding_Embeddings implements INode { + label: string + name: string + version: number + type: string + icon: string + category: string + description: string + baseClasses: string[] + credential: INodeParams + inputs: INodeParams[] + + constructor() { + this.label = 'Google PaLM Embeddings' + this.name = 'googlePaLMEmbeddings' + this.version = 1.0 + this.type = 'GooglePaLMEmbeddings' + this.icon = 'Google_PaLM_Logo.svg' + this.category = 'Embeddings' + this.description = 'Google MakerSuite PaLM API to generate embeddings for a given text' + this.baseClasses = [this.type, ...getBaseClasses(GooglePaLMEmbeddings)] + this.credential = { + label: 'Connect Credential', + name: 'credential', + type: 'credential', + credentialNames: ['googleMakerSuite'] + } + this.inputs = [ + { + label: 'Model Name', + name: 'modelName', + type: 'options', + options: [ + { + label: 'models/embedding-gecko-001', + name: 'models/embedding-gecko-001' + } + ], + default: 'models/embedding-gecko-001', + optional: true + } + ] + } + + async init(nodeData: INodeData, _: string, options: ICommonObject): Promise { + const modelName = nodeData.inputs?.modelName as string + + const credentialData = await getCredentialData(nodeData.credential ?? '', options) + const googleMakerSuiteKey = getCredentialParam('googleMakerSuiteKey', credentialData, nodeData) + + const obj: Partial = { + modelName: modelName, + apiKey: googleMakerSuiteKey + } + + const model = new GooglePaLMEmbeddings(obj) + return model + } +} + +module.exports = { nodeClass: GooglePaLMEmbedding_Embeddings } diff --git a/packages/components/nodes/embeddings/GooglePaLMEmbedding/Google_PaLM_Logo.svg b/packages/components/nodes/embeddings/GooglePaLMEmbedding/Google_PaLM_Logo.svg new file mode 100644 index 00000000..5c345fe1 --- /dev/null +++ b/packages/components/nodes/embeddings/GooglePaLMEmbedding/Google_PaLM_Logo.svg @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From ad8141e0788814bf43c77e09e59471e38c057a70 Mon Sep 17 00:00:00 2001 From: Henry Date: Fri, 8 Sep 2023 11:49:22 +0100 Subject: [PATCH 44/53] Apache License 2.0 --- LICENSE.md | 189 ++++++++++++++++++++++++++++--- README-ZH.md | 10 +- README.md | 4 +- packages/components/README-ZH.md | 6 +- packages/components/README.md | 4 +- packages/server/README-ZH.md | 2 +- packages/server/README.md | 4 +- packages/ui/README-ZH.md | 6 +- packages/ui/README.md | 4 +- 9 files changed, 192 insertions(+), 37 deletions(-) diff --git a/LICENSE.md b/LICENSE.md index 56552bdf..4a27187d 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,21 +1,176 @@ -The MIT License + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ -Copyright (c) 2023 FlowiseAI +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: +1. Definitions. -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS diff --git a/README-ZH.md b/README-ZH.md index 10efce8b..2805ef9b 100644 --- a/README-ZH.md +++ b/README-ZH.md @@ -2,7 +2,7 @@ -# Flowise - 轻松构建LLM应用程序 +# Flowise - 轻松构建 LLM 应用程序 [![发布说明](https://img.shields.io/github/release/FlowiseAI/Flowise)](https://github.com/FlowiseAI/Flowise/releases) [![Discord](https://img.shields.io/discord/1087698854775881778?label=Discord&logo=discord)](https://discord.gg/jbaHfsRVBW) @@ -10,13 +10,13 @@ [![GitHub星图](https://img.shields.io/github/stars/FlowiseAI/Flowise?style=social)](https://star-history.com/#FlowiseAI/Flowise) [![GitHub分支](https://img.shields.io/github/forks/FlowiseAI/Flowise?style=social)](https://github.com/FlowiseAI/Flowise/fork) -[English](<./README.md>) | 中文 +[English](./README.md) | 中文

拖放界面构建定制化的LLM流程

-## ⚡快速入门 +## ⚡ 快速入门 下载并安装 [NodeJS](https://nodejs.org/en/download) >= 18.15.0 @@ -67,7 +67,7 @@ ## 👨‍💻 开发者 -Flowise 在一个单一的代码库中有3个不同的模块。 +Flowise 在一个单一的代码库中有 3 个不同的模块。 - `server`:用于提供 API 逻辑的 Node 后端 - `ui`:React 前端 @@ -185,4 +185,4 @@ Flowise 支持不同的环境变量来配置您的实例。您可以在 `package ## 📄 许可证 -此代码库中的源代码在[MIT许可证](LICENSE.md)下提供。 +此代码库中的源代码在[Apache License Version 2.0 许可证](LICENSE.md)下提供。 diff --git a/README.md b/README.md index 36c53b4b..9f685846 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ [![GitHub star chart](https://img.shields.io/github/stars/FlowiseAI/Flowise?style=social)](https://star-history.com/#FlowiseAI/Flowise) [![GitHub fork](https://img.shields.io/github/forks/FlowiseAI/Flowise?style=social)](https://github.com/FlowiseAI/Flowise/fork) -English | [中文](<./README-ZH.md>) +English | [中文](./README-ZH.md)

Drag & drop UI to build your customized LLM flow

@@ -186,4 +186,4 @@ See [contributing guide](CONTRIBUTING.md). Reach out to us at [Discord](https:// ## 📄 License -Source code in this repository is made available under the [MIT License](LICENSE.md). +Source code in this repository is made available under the [Apache License Version 2.0](LICENSE.md). diff --git a/packages/components/README-ZH.md b/packages/components/README-ZH.md index 12cb240b..52d43eb2 100644 --- a/packages/components/README-ZH.md +++ b/packages/components/README-ZH.md @@ -2,9 +2,9 @@ # 流式组件 -[English](<./README.md>) | 中文 +[English](./README.md) | 中文 -Flowise的应用集成。包含节点和凭据。 +Flowise 的应用集成。包含节点和凭据。 ![Flowise](https://github.com/FlowiseAI/Flowise/blob/main/images/flowise.gif?raw=true) @@ -16,4 +16,4 @@ npm i flowise-components ## 许可证 -此存储库中的源代码在[MIT许可证](https://github.com/FlowiseAI/Flowise/blob/master/LICENSE.md)下提供。 +此存储库中的源代码在[Apache License Version 2.0 许可证](https://github.com/FlowiseAI/Flowise/blob/master/LICENSE.md)下提供。 diff --git a/packages/components/README.md b/packages/components/README.md index 8d561e34..f8e08374 100644 --- a/packages/components/README.md +++ b/packages/components/README.md @@ -2,7 +2,7 @@ # Flowise Components -English | [中文](<./README-ZH.md>) +English | [中文](./README-ZH.md) Apps integration for Flowise. Contain Nodes and Credentials. @@ -16,4 +16,4 @@ npm i flowise-components ## License -Source code in this repository is made available under the [MIT License](https://github.com/FlowiseAI/Flowise/blob/master/LICENSE.md). +Source code in this repository is made available under the [Apache License Version 2.0](https://github.com/FlowiseAI/Flowise/blob/master/LICENSE.md). diff --git a/packages/server/README-ZH.md b/packages/server/README-ZH.md index e58f08bf..8c40fd11 100644 --- a/packages/server/README-ZH.md +++ b/packages/server/README-ZH.md @@ -97,4 +97,4 @@ npx flowise start --PORT=3000 --DEBUG=true ## 📄 许可证 -本仓库中的源代码在[MIT 许可证](https://github.com/FlowiseAI/Flowise/blob/master/LICENSE.md)下提供。 +本仓库中的源代码在[Apache License Version 2.0 许可证](https://github.com/FlowiseAI/Flowise/blob/master/LICENSE.md)下提供。 diff --git a/packages/server/README.md b/packages/server/README.md index b561b0b0..049e7261 100644 --- a/packages/server/README.md +++ b/packages/server/README.md @@ -2,7 +2,7 @@ # Flowise - Low-Code LLM apps builder -English | [中文](<./README-ZH.md>) +English | [中文](./README-ZH.md) ![Flowise](https://github.com/FlowiseAI/Flowise/blob/main/images/flowise.gif?raw=true) @@ -77,4 +77,4 @@ See [contributing guide](https://github.com/FlowiseAI/Flowise/blob/master/CONTRI ## 📄 License -Source code in this repository is made available under the [MIT License](https://github.com/FlowiseAI/Flowise/blob/master/LICENSE.md). +Source code in this repository is made available under the [Apache License Version 2.0](https://github.com/FlowiseAI/Flowise/blob/master/LICENSE.md). diff --git a/packages/ui/README-ZH.md b/packages/ui/README-ZH.md index c6307935..e34c3de0 100644 --- a/packages/ui/README-ZH.md +++ b/packages/ui/README-ZH.md @@ -2,9 +2,9 @@ # 流程界面 -[English](<./README.md>) | 中文 +[English](./README.md) | 中文 -Flowise的React前端界面。 +Flowise 的 React 前端界面。 ![Flowise](https://github.com/FlowiseAI/Flowise/blob/main/images/flowise.gif?raw=true) @@ -16,4 +16,4 @@ npm i flowise-ui ## 许可证 -本仓库中的源代码在[MIT许可证](https://github.com/FlowiseAI/Flowise/blob/master/LICENSE.md)下提供。 +本仓库中的源代码在[Apache License Version 2.0 许可证](https://github.com/FlowiseAI/Flowise/blob/master/LICENSE.md)下提供。 diff --git a/packages/ui/README.md b/packages/ui/README.md index 487172f8..b476d47f 100644 --- a/packages/ui/README.md +++ b/packages/ui/README.md @@ -2,7 +2,7 @@ # Flowise UI -English | [中文](<./README-ZH.md>) +English | [中文](./README-ZH.md) React frontend ui for Flowise. @@ -16,4 +16,4 @@ npm i flowise-ui ## License -Source code in this repository is made available under the [MIT License](https://github.com/FlowiseAI/Flowise/blob/master/LICENSE.md). +Source code in this repository is made available under the [Apache License Version 2.0](https://github.com/FlowiseAI/Flowise/blob/master/LICENSE.md). From 06a5a71d2677054fad3c331c1951ead70c58300b Mon Sep 17 00:00:00 2001 From: Henry Date: Fri, 8 Sep 2023 12:42:26 +0100 Subject: [PATCH 45/53] update apify for metadata --- .../ApifyWebsiteContentCrawler.ts | 53 +++++++++++++++---- 1 file changed, 44 insertions(+), 9 deletions(-) diff --git a/packages/components/nodes/documentloaders/ApifyWebsiteContentCrawler/ApifyWebsiteContentCrawler.ts b/packages/components/nodes/documentloaders/ApifyWebsiteContentCrawler/ApifyWebsiteContentCrawler.ts index a5e6a6e0..9ecaa594 100644 --- a/packages/components/nodes/documentloaders/ApifyWebsiteContentCrawler/ApifyWebsiteContentCrawler.ts +++ b/packages/components/nodes/documentloaders/ApifyWebsiteContentCrawler/ApifyWebsiteContentCrawler.ts @@ -21,11 +21,17 @@ class ApifyWebsiteContentCrawler_DocumentLoaders implements INode { this.name = 'apifyWebsiteContentCrawler' this.type = 'Document' this.icon = 'apify-symbol-transparent.svg' - this.version = 1.0 + this.version = 2.0 this.category = 'Document Loaders' this.description = 'Load data from Apify Website Content Crawler' this.baseClasses = [this.type] this.inputs = [ + { + label: 'Text Splitter', + name: 'textSplitter', + type: 'TextSplitter', + optional: true + }, { label: 'Start URLs', name: 'urls', @@ -64,14 +70,16 @@ class ApifyWebsiteContentCrawler_DocumentLoaders implements INode { name: 'maxCrawlDepth', type: 'number', optional: true, - default: 1 + default: 1, + additionalParams: true }, { label: 'Max crawl pages', name: 'maxCrawlPages', type: 'number', optional: true, - default: 3 + default: 3, + additionalParams: true }, { label: 'Additional input', @@ -80,13 +88,15 @@ class ApifyWebsiteContentCrawler_DocumentLoaders implements INode { default: JSON.stringify({}), description: 'For additional input options for the crawler see documentation.', - optional: true + optional: true, + additionalParams: true }, { - label: 'Text Splitter', - name: 'textSplitter', - type: 'TextSplitter', - optional: true + label: 'Metadata', + name: 'metadata', + type: 'json', + optional: true, + additionalParams: true } ] this.credential = { @@ -99,6 +109,7 @@ class ApifyWebsiteContentCrawler_DocumentLoaders implements INode { async init(nodeData: INodeData, _: string, options: ICommonObject): Promise { const textSplitter = nodeData.inputs?.textSplitter as TextSplitter + const metadata = nodeData.inputs?.metadata // Get input options and merge with additional input const urls = nodeData.inputs?.urls as string @@ -132,7 +143,31 @@ class ApifyWebsiteContentCrawler_DocumentLoaders implements INode { } }) - return textSplitter ? loader.loadAndSplit(textSplitter) : loader.load() + let docs = [] + + if (textSplitter) { + docs = await loader.loadAndSplit(textSplitter) + } else { + docs = await loader.load() + } + + if (metadata) { + const parsedMetadata = typeof metadata === 'object' ? metadata : JSON.parse(metadata) + let finaldocs = [] + for (const doc of docs) { + const newdoc = { + ...doc, + metadata: { + ...doc.metadata, + ...parsedMetadata + } + } + finaldocs.push(newdoc) + } + return finaldocs + } + + return docs } } From f9f18b6d2c7631b6e2e97b0f54d2a0c39a7e1173 Mon Sep 17 00:00:00 2001 From: Henry Heng Date: Fri, 8 Sep 2023 14:32:46 +0100 Subject: [PATCH 46/53] Update Chroma_Existing.ts add accidentally removed chromaApiKey --- packages/components/nodes/vectorstores/Chroma/Chroma_Existing.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/components/nodes/vectorstores/Chroma/Chroma_Existing.ts b/packages/components/nodes/vectorstores/Chroma/Chroma_Existing.ts index 30662d61..e268434c 100644 --- a/packages/components/nodes/vectorstores/Chroma/Chroma_Existing.ts +++ b/packages/components/nodes/vectorstores/Chroma/Chroma_Existing.ts @@ -103,6 +103,7 @@ class Chroma_Existing_VectorStores implements INode { filter?: object | undefined } = { collectionName } if (chromaURL) obj.url = chromaURL + if (chromaApiKey) obj.chromaApiKey = chromaApiKey if (chromaMetadataFilter) { const metadatafilter = typeof chromaMetadataFilter === 'object' ? chromaMetadataFilter : JSON.parse(chromaMetadataFilter) obj.filter = metadatafilter From ba9c1cd5682f3a120f56246c058fb7b35cdf6fcf Mon Sep 17 00:00:00 2001 From: Henry Heng Date: Fri, 8 Sep 2023 14:34:07 +0100 Subject: [PATCH 47/53] Update Chroma_Existing.ts remove not needed code --- packages/components/nodes/vectorstores/Chroma/Chroma_Existing.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/components/nodes/vectorstores/Chroma/Chroma_Existing.ts b/packages/components/nodes/vectorstores/Chroma/Chroma_Existing.ts index e268434c..ff929ef1 100644 --- a/packages/components/nodes/vectorstores/Chroma/Chroma_Existing.ts +++ b/packages/components/nodes/vectorstores/Chroma/Chroma_Existing.ts @@ -94,7 +94,6 @@ class Chroma_Existing_VectorStores implements INode { const chromaApiKey = getCredentialParam('chromaApiKey', credentialData, nodeData) const chromaMetadataFilter = nodeData.inputs?.chromaMetadataFilter - const metadataFilter = chromaMetadataFilter ? JSON.parse(chromaMetadataFilter) : {} const obj: { collectionName: string From c4c007b16402c32a39c2c483eef550aa21b1625d Mon Sep 17 00:00:00 2001 From: chungyau97 Date: Sat, 9 Sep 2023 23:25:28 +0800 Subject: [PATCH 48/53] add migration queries for rate limit --- packages/server/src/database/entities/ChatFlow.ts | 2 +- .../migrations/mysql/1694099200729-AddApiConfig.ts | 11 +++++++++++ .../server/src/database/migrations/mysql/index.ts | 4 +++- .../migrations/postgres/1694099183389-AddApiConfig.ts | 11 +++++++++++ .../server/src/database/migrations/postgres/index.ts | 4 +++- .../migrations/sqlite/1694090982460-AddApiConfig.ts | 11 +++++++++++ .../server/src/database/migrations/sqlite/index.ts | 4 +++- packages/ui/src/views/chatflows/Configuration.js | 6 +++--- 8 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 packages/server/src/database/migrations/mysql/1694099200729-AddApiConfig.ts create mode 100644 packages/server/src/database/migrations/postgres/1694099183389-AddApiConfig.ts create mode 100644 packages/server/src/database/migrations/sqlite/1694090982460-AddApiConfig.ts diff --git a/packages/server/src/database/entities/ChatFlow.ts b/packages/server/src/database/entities/ChatFlow.ts index 6f66d694..29f58e5c 100644 --- a/packages/server/src/database/entities/ChatFlow.ts +++ b/packages/server/src/database/entities/ChatFlow.ts @@ -25,7 +25,7 @@ export class ChatFlow implements IChatFlow { @Column({ nullable: true, type: 'text' }) chatbotConfig?: string - @Column({ nullable: true }) + @Column({ nullable: true, type: 'text' }) apiConfig?: string @CreateDateColumn() diff --git a/packages/server/src/database/migrations/mysql/1694099200729-AddApiConfig.ts b/packages/server/src/database/migrations/mysql/1694099200729-AddApiConfig.ts new file mode 100644 index 00000000..c82b36ea --- /dev/null +++ b/packages/server/src/database/migrations/mysql/1694099200729-AddApiConfig.ts @@ -0,0 +1,11 @@ +import { MigrationInterface, QueryRunner } from 'typeorm' + +export class AddApiConfig1694099200729 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`chat_flow\` ADD COLUMN \`apiConfig\` TEXT;`) + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`chat_flow\` DROP COLUMN \`apiConfig\`;`) + } +} diff --git a/packages/server/src/database/migrations/mysql/index.ts b/packages/server/src/database/migrations/mysql/index.ts index 124eb70f..e5c16773 100644 --- a/packages/server/src/database/migrations/mysql/index.ts +++ b/packages/server/src/database/migrations/mysql/index.ts @@ -3,11 +3,13 @@ import { ModifyChatFlow1693997791471 } from './1693997791471-ModifyChatFlow' import { ModifyChatMessage1693999022236 } from './1693999022236-ModifyChatMessage' import { ModifyCredential1693999261583 } from './1693999261583-ModifyCredential' import { ModifyTool1694001465232 } from './1694001465232-ModifyTool' +import { AddApiConfig1694099200729 } from './1694099200729-AddApiConfig' export const mysqlMigrations = [ Init1693840429259, ModifyChatFlow1693997791471, ModifyChatMessage1693999022236, ModifyCredential1693999261583, - ModifyTool1694001465232 + ModifyTool1694001465232, + AddApiConfig1694099200729 ] diff --git a/packages/server/src/database/migrations/postgres/1694099183389-AddApiConfig.ts b/packages/server/src/database/migrations/postgres/1694099183389-AddApiConfig.ts new file mode 100644 index 00000000..832c2fa3 --- /dev/null +++ b/packages/server/src/database/migrations/postgres/1694099183389-AddApiConfig.ts @@ -0,0 +1,11 @@ +import { MigrationInterface, QueryRunner } from 'typeorm' + +export class AddApiConfig1694099183389 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "chat_flow" ADD COLUMN "apiConfig" TEXT;`) + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "chat_flow" DROP COLUMN "apiConfig";`) + } +} diff --git a/packages/server/src/database/migrations/postgres/index.ts b/packages/server/src/database/migrations/postgres/index.ts index 2bac9f33..04579cd6 100644 --- a/packages/server/src/database/migrations/postgres/index.ts +++ b/packages/server/src/database/migrations/postgres/index.ts @@ -3,11 +3,13 @@ import { ModifyChatFlow1693995626941 } from './1693995626941-ModifyChatFlow' import { ModifyChatMessage1693996694528 } from './1693996694528-ModifyChatMessage' import { ModifyCredential1693997070000 } from './1693997070000-ModifyCredential' import { ModifyTool1693997339912 } from './1693997339912-ModifyTool' +import { AddApiConfig1694099183389 } from './1694099183389-AddApiConfig' export const postgresMigrations = [ Init1693891895163, ModifyChatFlow1693995626941, ModifyChatMessage1693996694528, ModifyCredential1693997070000, - ModifyTool1693997339912 + ModifyTool1693997339912, + AddApiConfig1694099183389 ] diff --git a/packages/server/src/database/migrations/sqlite/1694090982460-AddApiConfig.ts b/packages/server/src/database/migrations/sqlite/1694090982460-AddApiConfig.ts new file mode 100644 index 00000000..6bdff60f --- /dev/null +++ b/packages/server/src/database/migrations/sqlite/1694090982460-AddApiConfig.ts @@ -0,0 +1,11 @@ +import { MigrationInterface, QueryRunner } from 'typeorm' + +export class AddApiConfig1694090982460 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "chat_flow" ADD COLUMN "apiConfig" TEXT;`) + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "chat_flow" DROP COLUMN "apiConfig";`) + } +} diff --git a/packages/server/src/database/migrations/sqlite/index.ts b/packages/server/src/database/migrations/sqlite/index.ts index c3c1fe7a..234dd220 100644 --- a/packages/server/src/database/migrations/sqlite/index.ts +++ b/packages/server/src/database/migrations/sqlite/index.ts @@ -3,11 +3,13 @@ import { ModifyChatFlow1693920824108 } from './1693920824108-ModifyChatFlow' import { ModifyChatMessage1693921865247 } from './1693921865247-ModifyChatMessage' import { ModifyCredential1693923551694 } from './1693923551694-ModifyCredential' import { ModifyTool1693924207475 } from './1693924207475-ModifyTool' +import { AddApiConfig1694090982460 } from './1694090982460-AddApiConfig' export const sqliteMigrations = [ Init1693835579790, ModifyChatFlow1693920824108, ModifyChatMessage1693921865247, ModifyCredential1693923551694, - ModifyTool1693924207475 + ModifyTool1693924207475, + AddApiConfig1694090982460 ] diff --git a/packages/ui/src/views/chatflows/Configuration.js b/packages/ui/src/views/chatflows/Configuration.js index 4268fd08..51826c44 100644 --- a/packages/ui/src/views/chatflows/Configuration.js +++ b/packages/ui/src/views/chatflows/Configuration.js @@ -28,9 +28,9 @@ const Configuration = () => { const enqueueSnackbar = (...args) => dispatch(enqueueSnackbarAction(...args)) const closeSnackbar = (...args) => dispatch(closeSnackbarAction(...args)) - const [limitMax, setLimitMax] = useState(apiConfig?.rateLimit?.limitMax ?? 20) - const [limitDuration, setLimitDuration] = useState(apiConfig?.rateLimit?.limitDuration ?? 120) - const [limitMsg, setLimitMsg] = useState(apiConfig?.rateLimit?.limitMsg ?? "Please don't spam me") + const [limitMax, setLimitMax] = useState(apiConfig?.rateLimit?.limitMax ?? '') + const [limitDuration, setLimitDuration] = useState(apiConfig?.rateLimit?.limitDuration ?? '') + const [limitMsg, setLimitMsg] = useState(apiConfig?.rateLimit?.limitMsg ?? '') const formatObj = () => { const obj = { From c4243d6bd1b71d1f8bee05daf2b8a49d74f9d4f9 Mon Sep 17 00:00:00 2001 From: chungyau97 Date: Sat, 9 Sep 2023 23:26:08 +0800 Subject: [PATCH 49/53] add hosting proxy configuration --- docker/.env.example | 2 ++ packages/server/.env.example | 2 ++ packages/server/src/index.ts | 16 +++++++++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/docker/.env.example b/docker/.env.example index 16b19cdc..bee2dfbf 100644 --- a/docker/.env.example +++ b/docker/.env.example @@ -5,6 +5,8 @@ APIKEY_PATH=/root/.flowise SECRETKEY_PATH=/root/.flowise LOG_PATH=/root/.flowise/logs +# NUMBER_OF_PROXIES= 1 + # DATABASE_TYPE=postgres # DATABASE_PORT="" # DATABASE_HOST="" diff --git a/packages/server/.env.example b/packages/server/.env.example index bedbf638..07dbf6b6 100644 --- a/packages/server/.env.example +++ b/packages/server/.env.example @@ -5,6 +5,8 @@ PASSPHRASE=MYPASSPHRASE # Passphrase used to create encryption key # SECRETKEY_PATH=/your_api_key_path/.flowise # LOG_PATH=/your_log_path/.flowise/logs +# NUMBER_OF_PROXIES= 1 + # DATABASE_TYPE=postgres # DATABASE_PORT="" # DATABASE_HOST="" diff --git a/packages/server/src/index.ts b/packages/server/src/index.ts index 7143bdc5..8d83cb8a 100644 --- a/packages/server/src/index.ts +++ b/packages/server/src/index.ts @@ -102,6 +102,9 @@ export class App { this.app.use(express.json({ limit: '50mb' })) this.app.use(express.urlencoded({ limit: '50mb', extended: true })) + if (process.env.NUMBER_OF_PROXIES && parseInt(process.env.NUMBER_OF_PROXIES) > 0) + this.app.set('trust proxy', parseInt(process.env.NUMBER_OF_PROXIES)) + // Allow access from * this.app.use(cors()) @@ -121,7 +124,8 @@ export class App { '/api/v1/prediction/', '/api/v1/node-icon/', '/api/v1/components-credentials-icon/', - '/api/v1/chatflows-streaming' + '/api/v1/chatflows-streaming', + '/api/v1/ip' ] this.app.use((req, res, next) => { if (req.url.includes('/api/v1/')) { @@ -132,6 +136,16 @@ export class App { const upload = multer({ dest: `${path.join(__dirname, '..', 'uploads')}/` }) + // ---------------------------------------- + // Configure number of proxies in Host Environment + // ---------------------------------------- + this.app.get('/api/v1/ip', (request, response) => { + response.send({ + ip: request.ip, + msg: 'See the IP returned in the response. If it matches your IP address (which you can get by going to http://ip.nfriedly.com/ or https://api.ipify.org/), then the number of proxies is correct and the rate limiter should now work correctly. If not, then keep increasing the number until it does.' + }) + }) + // ---------------------------------------- // Components // ---------------------------------------- From 7e3a68965628033d7f19880cec3fe5496946dde3 Mon Sep 17 00:00:00 2001 From: Lorenzo Date: Mon, 11 Sep 2023 17:12:35 +0200 Subject: [PATCH 50/53] Remove the typo code --- .../nodes/chains/SqlDatabaseChain/SqlDatabaseChain.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/components/nodes/chains/SqlDatabaseChain/SqlDatabaseChain.ts b/packages/components/nodes/chains/SqlDatabaseChain/SqlDatabaseChain.ts index 0e4d1894..12081b66 100644 --- a/packages/components/nodes/chains/SqlDatabaseChain/SqlDatabaseChain.ts +++ b/packages/components/nodes/chains/SqlDatabaseChain/SqlDatabaseChain.ts @@ -142,7 +142,7 @@ class SqlDatabaseChain_Chains implements INode { const url = nodeData.inputs?.url const includesTables = nodeData.inputs?.includesTables const splittedIncludesTables = includesTables == '' ? undefined : includesTables?.split(',') - const ignoreTables = nodeData.inputs?.ignoreTables?.split(',') + const ignoreTables = nodeData.inputs?.ignoreTables const splittedIgnoreTables = ignoreTables == '' ? undefined : includesTables?.split(',') const sampleRowsInTableInfo = nodeData.inputs?.sampleRowsInTableInfo const topK = nodeData.inputs?.topK @@ -167,7 +167,7 @@ class SqlDatabaseChain_Chains implements INode { const url = nodeData.inputs?.url const includesTables = nodeData.inputs?.includesTables const splittedIncludesTables = includesTables == '' ? undefined : includesTables?.split(',') - const ignoreTables = nodeData.inputs?.ignoreTables?.split(',') + const ignoreTables = nodeData.inputs?.ignoreTables const splittedIgnoreTables = ignoreTables == '' ? undefined : includesTables?.split(',') const sampleRowsInTableInfo = nodeData.inputs?.sampleRowsInTableInfo const topK = nodeData.inputs?.topK From 8fcafe83bc14996a95a0655032f9a12b13f14562 Mon Sep 17 00:00:00 2001 From: Lorenzo Date: Mon, 11 Sep 2023 21:14:46 +0200 Subject: [PATCH 51/53] Removed another typo --- .../nodes/chains/SqlDatabaseChain/SqlDatabaseChain.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/components/nodes/chains/SqlDatabaseChain/SqlDatabaseChain.ts b/packages/components/nodes/chains/SqlDatabaseChain/SqlDatabaseChain.ts index 12081b66..a6e6ab24 100644 --- a/packages/components/nodes/chains/SqlDatabaseChain/SqlDatabaseChain.ts +++ b/packages/components/nodes/chains/SqlDatabaseChain/SqlDatabaseChain.ts @@ -143,7 +143,7 @@ class SqlDatabaseChain_Chains implements INode { const includesTables = nodeData.inputs?.includesTables const splittedIncludesTables = includesTables == '' ? undefined : includesTables?.split(',') const ignoreTables = nodeData.inputs?.ignoreTables - const splittedIgnoreTables = ignoreTables == '' ? undefined : includesTables?.split(',') + const splittedIgnoreTables = ignoreTables == '' ? undefined : ignoreTables?.split(',') const sampleRowsInTableInfo = nodeData.inputs?.sampleRowsInTableInfo const topK = nodeData.inputs?.topK const customPrompt = nodeData.inputs?.customPrompt @@ -168,7 +168,7 @@ class SqlDatabaseChain_Chains implements INode { const includesTables = nodeData.inputs?.includesTables const splittedIncludesTables = includesTables == '' ? undefined : includesTables?.split(',') const ignoreTables = nodeData.inputs?.ignoreTables - const splittedIgnoreTables = ignoreTables == '' ? undefined : includesTables?.split(',') + const splittedIgnoreTables = ignoreTables == '' ? undefined : ignoreTables?.split(',') const sampleRowsInTableInfo = nodeData.inputs?.sampleRowsInTableInfo const topK = nodeData.inputs?.topK const customPrompt = nodeData.inputs?.customPrompt From a969b0650746cfb93b95b439e2898685802eef0d Mon Sep 17 00:00:00 2001 From: Martin Andrews Date: Tue, 12 Sep 2023 15:54:31 +0000 Subject: [PATCH 52/53] Remove commented unused code - unlikely to interface productively with other langchain components, even if implemented --- .../ChatGooglePaLM/ChatGooglePaLM.ts | 27 ++----------------- 1 file changed, 2 insertions(+), 25 deletions(-) diff --git a/packages/components/nodes/chatmodels/ChatGooglePaLM/ChatGooglePaLM.ts b/packages/components/nodes/chatmodels/ChatGooglePaLM/ChatGooglePaLM.ts index 38cb1168..642ddb5e 100644 --- a/packages/components/nodes/chatmodels/ChatGooglePaLM/ChatGooglePaLM.ts +++ b/packages/components/nodes/chatmodels/ChatGooglePaLM/ChatGooglePaLM.ts @@ -86,18 +86,8 @@ class ChatGooglePaLM_ChatModels implements INode { 'while a top-k of 3 means that the next token is selected from ' + 'among the 3 most probable tokens (using temperature).' } - /* - { - label: 'Examples', - name: 'examplesObj', - type: 'json', - optional: true, - additionalParams: true - //default: { list:[] }, - //description: - // 'The "examples" field should contain a list of pairs of strings to use as prior turns for this conversation.' - } - */ + // 'The "examples" field should contain a list of pairs of strings to use as prior turns for this conversation.' + // NB: While 'examples:[]' exists in langchain.ts backend, it is unlikely to be actually used there, since ChatOpenAI doesn't support it ] } @@ -106,7 +96,6 @@ class ChatGooglePaLM_ChatModels implements INode { const temperature = nodeData.inputs?.temperature as string const topP = nodeData.inputs?.topP as string const topK = nodeData.inputs?.topK as string - //const examplesObj = nodeData.inputs?.examplesObj const credentialData = await getCredentialData(nodeData.credential ?? '', options) const googleMakerSuiteKey = getCredentialParam('googleMakerSuiteKey', credentialData, nodeData) @@ -120,18 +109,6 @@ class ChatGooglePaLM_ChatModels implements INode { if (topP) obj.topP = parseFloat(topP) if (topK) obj.topK = parseFloat(topK) - /* - let parsedExamples: any | undefined = undefined - if (examplesObj) { - try { - parsedExamples = typeof examplseObj === 'object' ? examplseObj : JSON.parse(examplseObj) - obj.examples = parsedExamples.examples || [] - } catch (exception) { - throw new Error("Invalid JSON in the GooglePaLM's examplseObj: " + exception) - } - } - */ - const model = new ChatGooglePaLM(obj) return model } From 35ddb30489d086ef73f047c3145b4f20596202d7 Mon Sep 17 00:00:00 2001 From: Henry Heng Date: Tue, 12 Sep 2023 17:38:13 +0100 Subject: [PATCH 53/53] Update SqlDatabaseChain.ts update types --- .../chains/SqlDatabaseChain/SqlDatabaseChain.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/components/nodes/chains/SqlDatabaseChain/SqlDatabaseChain.ts b/packages/components/nodes/chains/SqlDatabaseChain/SqlDatabaseChain.ts index a6e6ab24..f5fd0ccc 100644 --- a/packages/components/nodes/chains/SqlDatabaseChain/SqlDatabaseChain.ts +++ b/packages/components/nodes/chains/SqlDatabaseChain/SqlDatabaseChain.ts @@ -139,14 +139,14 @@ class SqlDatabaseChain_Chains implements INode { async init(nodeData: INodeData): Promise { const databaseType = nodeData.inputs?.database as DatabaseType const model = nodeData.inputs?.model as BaseLanguageModel - const url = nodeData.inputs?.url + const url = nodeData.inputs?.url as string const includesTables = nodeData.inputs?.includesTables const splittedIncludesTables = includesTables == '' ? undefined : includesTables?.split(',') const ignoreTables = nodeData.inputs?.ignoreTables const splittedIgnoreTables = ignoreTables == '' ? undefined : ignoreTables?.split(',') - const sampleRowsInTableInfo = nodeData.inputs?.sampleRowsInTableInfo - const topK = nodeData.inputs?.topK - const customPrompt = nodeData.inputs?.customPrompt + const sampleRowsInTableInfo = nodeData.inputs?.sampleRowsInTableInfo as number + const topK = nodeData.inputs?.topK as number + const customPrompt = nodeData.inputs?.customPrompt as string const chain = await getSQLDBChain( databaseType, @@ -164,14 +164,14 @@ class SqlDatabaseChain_Chains implements INode { async run(nodeData: INodeData, input: string, options: ICommonObject): Promise { const databaseType = nodeData.inputs?.database as DatabaseType const model = nodeData.inputs?.model as BaseLanguageModel - const url = nodeData.inputs?.url + const url = nodeData.inputs?.url as string const includesTables = nodeData.inputs?.includesTables const splittedIncludesTables = includesTables == '' ? undefined : includesTables?.split(',') const ignoreTables = nodeData.inputs?.ignoreTables const splittedIgnoreTables = ignoreTables == '' ? undefined : ignoreTables?.split(',') - const sampleRowsInTableInfo = nodeData.inputs?.sampleRowsInTableInfo - const topK = nodeData.inputs?.topK - const customPrompt = nodeData.inputs?.customPrompt + const sampleRowsInTableInfo = nodeData.inputs?.sampleRowsInTableInfo as number + const topK = nodeData.inputs?.topK as number + const customPrompt = nodeData.inputs?.customPrompt as string const chain = await getSQLDBChain( databaseType,