mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 19:00:59 +03:00
Merge branch 'FlowiseAI:main' into vectara-upload-files
This commit is contained in:
@@ -2,9 +2,9 @@
|
||||
|
||||
# 流式组件
|
||||
|
||||
[English](<./README.md>) | 中文
|
||||
[English](./README.md) | 中文
|
||||
|
||||
Flowise的应用集成。包含节点和凭据。
|
||||
Flowise 的应用集成。包含节点和凭据。
|
||||
|
||||

|
||||
|
||||
@@ -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)下提供。
|
||||
|
||||
@@ -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).
|
||||
|
||||
@@ -12,7 +12,7 @@ class ConfluenceApi implements INodeCredential {
|
||||
this.name = 'confluenceApi'
|
||||
this.version = 1.0
|
||||
this.description =
|
||||
'Refer to <a target="_blank" href="https://support.atlassian.com/confluence-cloud/docs/manage-oauth-access-tokens/">official guide</a> on how to get accessToken on Confluence'
|
||||
'Refer to <a target="_blank" href="https://support.atlassian.com/confluence-cloud/docs/manage-oauth-access-tokens/">official guide</a> on how to get Access Token or <a target="_blank" href="https://id.atlassian.com/manage-profile/security/api-tokens">API Token</a> on Confluence'
|
||||
this.inputs = [
|
||||
{
|
||||
label: 'Access Token',
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import { INodeParams, INodeCredential } from '../src/Interface'
|
||||
|
||||
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 <a target="_blank" href="https://makersuite.google.com/app/apikey">Google MakerSuite API credential site</a> to get this key.'
|
||||
this.inputs = [
|
||||
{
|
||||
label: 'MakerSuite API Key',
|
||||
name: 'googleMakerSuiteKey',
|
||||
type: 'password'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { credClass: GoogleMakerSuite }
|
||||
@@ -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',
|
||||
@@ -104,20 +139,50 @@ class SqlDatabaseChain_Chains implements INode {
|
||||
async init(nodeData: INodeData): Promise<any> {
|
||||
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 as number
|
||||
const topK = nodeData.inputs?.topK as number
|
||||
const customPrompt = nodeData.inputs?.customPrompt as string
|
||||
|
||||
const chain = await getSQLDBChain(databaseType, url, model, customPrompt)
|
||||
const chain = await getSQLDBChain(
|
||||
databaseType,
|
||||
url,
|
||||
model,
|
||||
splittedIncludesTables,
|
||||
splittedIgnoreTables,
|
||||
sampleRowsInTableInfo,
|
||||
topK,
|
||||
customPrompt
|
||||
)
|
||||
return chain
|
||||
}
|
||||
|
||||
async run(nodeData: INodeData, input: string, options: ICommonObject): Promise<string> {
|
||||
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 as number
|
||||
const topK = nodeData.inputs?.topK as number
|
||||
const customPrompt = nodeData.inputs?.customPrompt as string
|
||||
|
||||
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) {
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
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).'
|
||||
}
|
||||
// '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
|
||||
]
|
||||
}
|
||||
|
||||
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
|
||||
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 credentialData = await getCredentialData(nodeData.credential ?? '', options)
|
||||
const googleMakerSuiteKey = getCredentialParam('googleMakerSuiteKey', credentialData, nodeData)
|
||||
|
||||
const obj: Partial<GooglePaLMChatInput> = {
|
||||
modelName: modelName,
|
||||
temperature: parseFloat(temperature),
|
||||
apiKey: googleMakerSuiteKey
|
||||
}
|
||||
|
||||
if (topP) obj.topP = parseFloat(topP)
|
||||
if (topK) obj.topK = parseFloat(topK)
|
||||
|
||||
const model = new ChatGooglePaLM(obj)
|
||||
return model
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { nodeClass: ChatGooglePaLM_ChatModels }
|
||||
@@ -0,0 +1,67 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Generator: Adobe Illustrator 27.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
<svg version="1.1" id="Standard_product_icon__x28_1:1_x29_"
|
||||
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="192px" height="192px"
|
||||
viewBox="0 0 192 192" enable-background="new 0 0 192 192" xml:space="preserve">
|
||||
<symbol id="material_x5F_product_x5F_standard_x5F_icon_x5F_keylines_00000077318920148093339210000006245950728745084294_" viewBox="-96 -96 192 192">
|
||||
<g opacity="0.4">
|
||||
<defs>
|
||||
<path id="SVGID_1_" opacity="0.4" d="M-96,96V-96H96V96H-96z"/>
|
||||
</defs>
|
||||
<clipPath id="SVGID_00000071517564283228984050000017848131202901217410_">
|
||||
<use xlink:href="#SVGID_1_" overflow="visible"/>
|
||||
</clipPath>
|
||||
<g clip-path="url(#SVGID_00000071517564283228984050000017848131202901217410_)">
|
||||
<g>
|
||||
<path d="M95.75,95.75v-191.5h-191.5v191.5H95.75 M96,96H-96V-96H96V96L96,96z"/>
|
||||
</g>
|
||||
<circle fill="none" stroke="#000000" stroke-width="0.25" stroke-miterlimit="10" cx="0" cy="0" r="64"/>
|
||||
</g>
|
||||
|
||||
<circle clip-path="url(#SVGID_00000071517564283228984050000017848131202901217410_)" fill="none" stroke="#000000" stroke-width="0.25" stroke-miterlimit="10" cx="0" cy="0" r="88"/>
|
||||
|
||||
<path clip-path="url(#SVGID_00000071517564283228984050000017848131202901217410_)" fill="none" stroke="#000000" stroke-width="0.25" stroke-miterlimit="10" d="
|
||||
M64,76H-64c-6.6,0-12-5.4-12-12V-64c0-6.6,5.4-12,12-12H64c6.6,0,12,5.4,12,12V64C76,70.6,70.6,76,64,76z"/>
|
||||
|
||||
<path clip-path="url(#SVGID_00000071517564283228984050000017848131202901217410_)" fill="none" stroke="#000000" stroke-width="0.25" stroke-miterlimit="10" d="
|
||||
M52,88H-52c-6.6,0-12-5.4-12-12V-76c0-6.6,5.4-12,12-12H52c6.6,0,12,5.4,12,12V76C64,82.6,58.6,88,52,88z"/>
|
||||
|
||||
<path clip-path="url(#SVGID_00000071517564283228984050000017848131202901217410_)" fill="none" stroke="#000000" stroke-width="0.25" stroke-miterlimit="10" d="
|
||||
M76,64H-76c-6.6,0-12-5.4-12-12V-52c0-6.6,5.4-12,12-12H76c6.6,0,12,5.4,12,12V52C88,58.6,82.6,64,76,64z"/>
|
||||
</g>
|
||||
</symbol>
|
||||
<rect id="bounding_box_1_" display="none" fill="none" width="192" height="192"/>
|
||||
<g id="art_layer">
|
||||
<g>
|
||||
<path fill="#F9AB00" d="M96,181.92L96,181.92c6.63,0,12-5.37,12-12v-104H84v104C84,176.55,89.37,181.92,96,181.92z"/>
|
||||
<g>
|
||||
<path fill="#5BB974" d="M143.81,103.87C130.87,90.94,111.54,88.32,96,96l51.37,51.37c2.12,2.12,5.77,1.28,6.67-1.57
|
||||
C158.56,131.49,155.15,115.22,143.81,103.87z"/>
|
||||
</g>
|
||||
<g>
|
||||
<path fill="#129EAF" d="M48.19,103.87C61.13,90.94,80.46,88.32,96,96l-51.37,51.37c-2.12,2.12-5.77,1.28-6.67-1.57
|
||||
C33.44,131.49,36.85,115.22,48.19,103.87z"/>
|
||||
</g>
|
||||
<g>
|
||||
<path fill="#AF5CF7" d="M140,64c-20.44,0-37.79,13.4-44,32h81.24c3.33,0,5.55-3.52,4.04-6.49C173.56,74.36,157.98,64,140,64z"/>
|
||||
</g>
|
||||
<g>
|
||||
<path fill="#FF8BCB" d="M104.49,42.26C90.03,56.72,87.24,78.45,96,96l57.45-57.45c2.36-2.36,1.44-6.42-1.73-7.45
|
||||
C135.54,25.85,117.2,29.55,104.49,42.26z"/>
|
||||
</g>
|
||||
<g>
|
||||
<path fill="#FA7B17" d="M87.51,42.26C101.97,56.72,104.76,78.45,96,96L38.55,38.55c-2.36-2.36-1.44-6.42,1.73-7.45
|
||||
C56.46,25.85,74.8,29.55,87.51,42.26z"/>
|
||||
</g>
|
||||
<g>
|
||||
<g>
|
||||
<path fill="#4285F4" d="M52,64c20.44,0,37.79,13.4,44,32H14.76c-3.33,0-5.55-3.52-4.04-6.49C18.44,74.36,34.02,64,52,64z"/>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
<g id="keylines" display="none">
|
||||
|
||||
<use xlink:href="#material_x5F_product_x5F_standard_x5F_icon_x5F_keylines_00000077318920148093339210000006245950728745084294_" width="192" height="192" id="material_x5F_product_x5F_standard_x5F_icon_x5F_keylines" x="-96" y="-96" transform="matrix(1 0 0 -1 96 96)" display="inline" overflow="visible"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 3.6 KiB |
@@ -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',
|
||||
|
||||
+44
-9
@@ -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 <a target="_blank" href="https://apify.com/apify/website-content-crawler/input-schema">documentation</a>.',
|
||||
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<any> {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<any> {
|
||||
const modelName = nodeData.inputs?.modelName as string
|
||||
|
||||
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
|
||||
const googleMakerSuiteKey = getCredentialParam('googleMakerSuiteKey', credentialData, nodeData)
|
||||
|
||||
const obj: Partial<GooglePaLMEmbeddingsParams> = {
|
||||
modelName: modelName,
|
||||
apiKey: googleMakerSuiteKey
|
||||
}
|
||||
|
||||
const model = new GooglePaLMEmbeddings(obj)
|
||||
return model
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { nodeClass: GooglePaLMEmbedding_Embeddings }
|
||||
@@ -0,0 +1,67 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Generator: Adobe Illustrator 27.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
<svg version="1.1" id="Standard_product_icon__x28_1:1_x29_"
|
||||
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="192px" height="192px"
|
||||
viewBox="0 0 192 192" enable-background="new 0 0 192 192" xml:space="preserve">
|
||||
<symbol id="material_x5F_product_x5F_standard_x5F_icon_x5F_keylines_00000077318920148093339210000006245950728745084294_" viewBox="-96 -96 192 192">
|
||||
<g opacity="0.4">
|
||||
<defs>
|
||||
<path id="SVGID_1_" opacity="0.4" d="M-96,96V-96H96V96H-96z"/>
|
||||
</defs>
|
||||
<clipPath id="SVGID_00000071517564283228984050000017848131202901217410_">
|
||||
<use xlink:href="#SVGID_1_" overflow="visible"/>
|
||||
</clipPath>
|
||||
<g clip-path="url(#SVGID_00000071517564283228984050000017848131202901217410_)">
|
||||
<g>
|
||||
<path d="M95.75,95.75v-191.5h-191.5v191.5H95.75 M96,96H-96V-96H96V96L96,96z"/>
|
||||
</g>
|
||||
<circle fill="none" stroke="#000000" stroke-width="0.25" stroke-miterlimit="10" cx="0" cy="0" r="64"/>
|
||||
</g>
|
||||
|
||||
<circle clip-path="url(#SVGID_00000071517564283228984050000017848131202901217410_)" fill="none" stroke="#000000" stroke-width="0.25" stroke-miterlimit="10" cx="0" cy="0" r="88"/>
|
||||
|
||||
<path clip-path="url(#SVGID_00000071517564283228984050000017848131202901217410_)" fill="none" stroke="#000000" stroke-width="0.25" stroke-miterlimit="10" d="
|
||||
M64,76H-64c-6.6,0-12-5.4-12-12V-64c0-6.6,5.4-12,12-12H64c6.6,0,12,5.4,12,12V64C76,70.6,70.6,76,64,76z"/>
|
||||
|
||||
<path clip-path="url(#SVGID_00000071517564283228984050000017848131202901217410_)" fill="none" stroke="#000000" stroke-width="0.25" stroke-miterlimit="10" d="
|
||||
M52,88H-52c-6.6,0-12-5.4-12-12V-76c0-6.6,5.4-12,12-12H52c6.6,0,12,5.4,12,12V76C64,82.6,58.6,88,52,88z"/>
|
||||
|
||||
<path clip-path="url(#SVGID_00000071517564283228984050000017848131202901217410_)" fill="none" stroke="#000000" stroke-width="0.25" stroke-miterlimit="10" d="
|
||||
M76,64H-76c-6.6,0-12-5.4-12-12V-52c0-6.6,5.4-12,12-12H76c6.6,0,12,5.4,12,12V52C88,58.6,82.6,64,76,64z"/>
|
||||
</g>
|
||||
</symbol>
|
||||
<rect id="bounding_box_1_" display="none" fill="none" width="192" height="192"/>
|
||||
<g id="art_layer">
|
||||
<g>
|
||||
<path fill="#F9AB00" d="M96,181.92L96,181.92c6.63,0,12-5.37,12-12v-104H84v104C84,176.55,89.37,181.92,96,181.92z"/>
|
||||
<g>
|
||||
<path fill="#5BB974" d="M143.81,103.87C130.87,90.94,111.54,88.32,96,96l51.37,51.37c2.12,2.12,5.77,1.28,6.67-1.57
|
||||
C158.56,131.49,155.15,115.22,143.81,103.87z"/>
|
||||
</g>
|
||||
<g>
|
||||
<path fill="#129EAF" d="M48.19,103.87C61.13,90.94,80.46,88.32,96,96l-51.37,51.37c-2.12,2.12-5.77,1.28-6.67-1.57
|
||||
C33.44,131.49,36.85,115.22,48.19,103.87z"/>
|
||||
</g>
|
||||
<g>
|
||||
<path fill="#AF5CF7" d="M140,64c-20.44,0-37.79,13.4-44,32h81.24c3.33,0,5.55-3.52,4.04-6.49C173.56,74.36,157.98,64,140,64z"/>
|
||||
</g>
|
||||
<g>
|
||||
<path fill="#FF8BCB" d="M104.49,42.26C90.03,56.72,87.24,78.45,96,96l57.45-57.45c2.36-2.36,1.44-6.42-1.73-7.45
|
||||
C135.54,25.85,117.2,29.55,104.49,42.26z"/>
|
||||
</g>
|
||||
<g>
|
||||
<path fill="#FA7B17" d="M87.51,42.26C101.97,56.72,104.76,78.45,96,96L38.55,38.55c-2.36-2.36-1.44-6.42,1.73-7.45
|
||||
C56.46,25.85,74.8,29.55,87.51,42.26z"/>
|
||||
</g>
|
||||
<g>
|
||||
<g>
|
||||
<path fill="#4285F4" d="M52,64c20.44,0,37.79,13.4,44,32H14.76c-3.33,0-5.55-3.52-4.04-6.49C18.44,74.36,34.02,64,52,64z"/>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
<g id="keylines" display="none">
|
||||
|
||||
<use xlink:href="#material_x5F_product_x5F_standard_x5F_icon_x5F_keylines_00000077318920148093339210000006245950728745084294_" width="192" height="192" id="material_x5F_product_x5F_standard_x5F_icon_x5F_keylines" x="-96" y="-96" transform="matrix(1 0 0 -1 96 96)" display="inline" overflow="visible"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 3.6 KiB |
+25
-1
@@ -33,11 +33,34 @@ 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
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
|
||||
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
|
||||
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)
|
||||
@@ -59,6 +82,7 @@ class GoogleVertexAIEmbedding_Embeddings implements INode {
|
||||
if (projectID) authOptions.projectId = projectID
|
||||
}
|
||||
const obj: GoogleVertexAIEmbeddingsParams = {}
|
||||
if (modelName) obj.model = modelName
|
||||
if (Object.keys(authOptions).length !== 0) obj.authOptions = authOptions
|
||||
|
||||
const model = new GoogleVertexAIEmbeddings(obj)
|
||||
|
||||
@@ -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']
|
||||
}
|
||||
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 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<any> {
|
||||
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<GooglePaLMTextInput> = {
|
||||
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 }
|
||||
@@ -0,0 +1,67 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Generator: Adobe Illustrator 27.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
<svg version="1.1" id="Standard_product_icon__x28_1:1_x29_"
|
||||
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="192px" height="192px"
|
||||
viewBox="0 0 192 192" enable-background="new 0 0 192 192" xml:space="preserve">
|
||||
<symbol id="material_x5F_product_x5F_standard_x5F_icon_x5F_keylines_00000077318920148093339210000006245950728745084294_" viewBox="-96 -96 192 192">
|
||||
<g opacity="0.4">
|
||||
<defs>
|
||||
<path id="SVGID_1_" opacity="0.4" d="M-96,96V-96H96V96H-96z"/>
|
||||
</defs>
|
||||
<clipPath id="SVGID_00000071517564283228984050000017848131202901217410_">
|
||||
<use xlink:href="#SVGID_1_" overflow="visible"/>
|
||||
</clipPath>
|
||||
<g clip-path="url(#SVGID_00000071517564283228984050000017848131202901217410_)">
|
||||
<g>
|
||||
<path d="M95.75,95.75v-191.5h-191.5v191.5H95.75 M96,96H-96V-96H96V96L96,96z"/>
|
||||
</g>
|
||||
<circle fill="none" stroke="#000000" stroke-width="0.25" stroke-miterlimit="10" cx="0" cy="0" r="64"/>
|
||||
</g>
|
||||
|
||||
<circle clip-path="url(#SVGID_00000071517564283228984050000017848131202901217410_)" fill="none" stroke="#000000" stroke-width="0.25" stroke-miterlimit="10" cx="0" cy="0" r="88"/>
|
||||
|
||||
<path clip-path="url(#SVGID_00000071517564283228984050000017848131202901217410_)" fill="none" stroke="#000000" stroke-width="0.25" stroke-miterlimit="10" d="
|
||||
M64,76H-64c-6.6,0-12-5.4-12-12V-64c0-6.6,5.4-12,12-12H64c6.6,0,12,5.4,12,12V64C76,70.6,70.6,76,64,76z"/>
|
||||
|
||||
<path clip-path="url(#SVGID_00000071517564283228984050000017848131202901217410_)" fill="none" stroke="#000000" stroke-width="0.25" stroke-miterlimit="10" d="
|
||||
M52,88H-52c-6.6,0-12-5.4-12-12V-76c0-6.6,5.4-12,12-12H52c6.6,0,12,5.4,12,12V76C64,82.6,58.6,88,52,88z"/>
|
||||
|
||||
<path clip-path="url(#SVGID_00000071517564283228984050000017848131202901217410_)" fill="none" stroke="#000000" stroke-width="0.25" stroke-miterlimit="10" d="
|
||||
M76,64H-76c-6.6,0-12-5.4-12-12V-52c0-6.6,5.4-12,12-12H76c6.6,0,12,5.4,12,12V52C88,58.6,82.6,64,76,64z"/>
|
||||
</g>
|
||||
</symbol>
|
||||
<rect id="bounding_box_1_" display="none" fill="none" width="192" height="192"/>
|
||||
<g id="art_layer">
|
||||
<g>
|
||||
<path fill="#F9AB00" d="M96,181.92L96,181.92c6.63,0,12-5.37,12-12v-104H84v104C84,176.55,89.37,181.92,96,181.92z"/>
|
||||
<g>
|
||||
<path fill="#5BB974" d="M143.81,103.87C130.87,90.94,111.54,88.32,96,96l51.37,51.37c2.12,2.12,5.77,1.28,6.67-1.57
|
||||
C158.56,131.49,155.15,115.22,143.81,103.87z"/>
|
||||
</g>
|
||||
<g>
|
||||
<path fill="#129EAF" d="M48.19,103.87C61.13,90.94,80.46,88.32,96,96l-51.37,51.37c-2.12,2.12-5.77,1.28-6.67-1.57
|
||||
C33.44,131.49,36.85,115.22,48.19,103.87z"/>
|
||||
</g>
|
||||
<g>
|
||||
<path fill="#AF5CF7" d="M140,64c-20.44,0-37.79,13.4-44,32h81.24c3.33,0,5.55-3.52,4.04-6.49C173.56,74.36,157.98,64,140,64z"/>
|
||||
</g>
|
||||
<g>
|
||||
<path fill="#FF8BCB" d="M104.49,42.26C90.03,56.72,87.24,78.45,96,96l57.45-57.45c2.36-2.36,1.44-6.42-1.73-7.45
|
||||
C135.54,25.85,117.2,29.55,104.49,42.26z"/>
|
||||
</g>
|
||||
<g>
|
||||
<path fill="#FA7B17" d="M87.51,42.26C101.97,56.72,104.76,78.45,96,96L38.55,38.55c-2.36-2.36-1.44-6.42,1.73-7.45
|
||||
C56.46,25.85,74.8,29.55,87.51,42.26z"/>
|
||||
</g>
|
||||
<g>
|
||||
<g>
|
||||
<path fill="#4285F4" d="M52,64c20.44,0,37.79,13.4,44,32H14.76c-3.33,0-5.55-3.52-4.04-6.49C18.44,74.36,34.02,64,52,64z"/>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
<g id="keylines" display="none">
|
||||
|
||||
<use xlink:href="#material_x5F_product_x5F_standard_x5F_icon_x5F_keylines_00000077318920148093339210000006245950728745084294_" width="192" height="192" id="material_x5F_product_x5F_standard_x5F_icon_x5F_keylines" x="-96" y="-96" transform="matrix(1 0 0 -1 96 96)" display="inline" overflow="visible"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 3.6 KiB |
@@ -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'
|
||||
|
||||
@@ -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,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 obj: {
|
||||
collectionName: string
|
||||
url?: string
|
||||
chromaApiKey?: string
|
||||
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
|
||||
}
|
||||
|
||||
const vectorStore = await ChromaExtended.fromExistingCollection(embeddings, obj)
|
||||
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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=""
|
||||
|
||||
@@ -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)下提供。
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
# Flowise - Low-Code LLM apps builder
|
||||
|
||||
English | [中文](<./README-ZH.md>)
|
||||
English | [中文](./README-ZH.md)
|
||||
|
||||

|
||||
|
||||
@@ -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).
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
@@ -46,12 +46,14 @@
|
||||
"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",
|
||||
"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",
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
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 { sqliteMigrations } from './database/migrations/sqlite'
|
||||
import { mysqlMigrations } from './database/migrations/mysql'
|
||||
import { postgresMigrations } from './database/migrations/postgres'
|
||||
|
||||
let appDataSource: DataSource
|
||||
|
||||
export const init = async (): Promise<void> => {
|
||||
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: sqliteMigrations
|
||||
})
|
||||
break
|
||||
case 'mysql':
|
||||
@@ -32,9 +32,10 @@ export const init = async (): Promise<void> => {
|
||||
password: process.env.DATABASE_PASSWORD,
|
||||
database: process.env.DATABASE_NAME,
|
||||
charset: 'utf8mb4',
|
||||
synchronize,
|
||||
entities: [ChatFlow, ChatMessage, Tool, Credential],
|
||||
migrations: []
|
||||
synchronize: false,
|
||||
migrationsRun: false,
|
||||
entities: Object.values(entities),
|
||||
migrations: mysqlMigrations
|
||||
})
|
||||
break
|
||||
case 'postgres':
|
||||
@@ -45,9 +46,10 @@ export const init = async (): Promise<void> => {
|
||||
username: process.env.DATABASE_USER,
|
||||
password: process.env.DATABASE_PASSWORD,
|
||||
database: process.env.DATABASE_NAME,
|
||||
synchronize,
|
||||
entities: [ChatFlow, ChatMessage, Tool, Credential],
|
||||
migrations: []
|
||||
synchronize: false,
|
||||
migrationsRun: false,
|
||||
entities: Object.values(entities),
|
||||
migrations: postgresMigrations
|
||||
})
|
||||
break
|
||||
default:
|
||||
@@ -55,9 +57,10 @@ export const init = async (): Promise<void> => {
|
||||
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: sqliteMigrations
|
||||
})
|
||||
break
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ export interface IChatFlow {
|
||||
isPublic?: boolean
|
||||
apikeyid?: string
|
||||
chatbotConfig?: string
|
||||
apiConfig?: any
|
||||
}
|
||||
|
||||
export interface IChatMessage {
|
||||
|
||||
+5
-2
@@ -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 {
|
||||
@@ -22,9 +22,12 @@ export class ChatFlow implements IChatFlow {
|
||||
@Column({ nullable: true })
|
||||
apikeyid?: string
|
||||
|
||||
@Column({ nullable: true })
|
||||
@Column({ nullable: true, type: 'text' })
|
||||
chatbotConfig?: string
|
||||
|
||||
@Column({ nullable: true, type: 'text' })
|
||||
apiConfig?: string
|
||||
|
||||
@CreateDateColumn()
|
||||
createdDate: Date
|
||||
|
||||
+2
-2
@@ -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 {
|
||||
@@ -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()
|
||||
+2
-2
@@ -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 {
|
||||
@@ -13,7 +13,7 @@ export class Credential implements ICredential {
|
||||
@Column()
|
||||
credentialName: string
|
||||
|
||||
@Column()
|
||||
@Column({ type: 'text' })
|
||||
encryptedData: string
|
||||
|
||||
@CreateDateColumn()
|
||||
@@ -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 {
|
||||
@@ -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()
|
||||
@@ -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
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm'
|
||||
|
||||
export class Init1693840429259 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`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\` 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 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\` 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 IF NOT EXISTS \`credential\` (
|
||||
\`id\` varchar(36) NOT NULL,
|
||||
\`name\` varchar(255) NOT NULL,
|
||||
\`credentialName\` varchar(255) 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 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\` 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\`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;`
|
||||
)
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
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`)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm'
|
||||
|
||||
export class ModifyChatFlow1693997791471 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`chat_flow\` MODIFY \`chatbotConfig\` TEXT;`)
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`chat_flow\` MODIFY \`chatbotConfig\` VARCHAR;`)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm'
|
||||
|
||||
export class ModifyChatMessage1693999022236 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`chat_message\` MODIFY \`sourceDocuments\` TEXT;`)
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`chat_message\` MODIFY \`sourceDocuments\` VARCHAR;`)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm'
|
||||
|
||||
export class ModifyCredential1693999261583 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`credential\` MODIFY \`encryptedData\` TEXT NOT NULL;`)
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`credential\` MODIFY \`encryptedData\` VARCHAR NOT NULL;`)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm'
|
||||
|
||||
export class ModifyTool1694001465232 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`tool\` MODIFY \`schema\` TEXT, MODIFY \`func\` TEXT;`)
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`tool\` MODIFY \`schema\` VARCHAR, MODIFY \`func\` VARCHAR;`)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm'
|
||||
|
||||
export class AddApiConfig1694099200729 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`chat_flow\` ADD COLUMN \`apiConfig\` TEXT;`)
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`chat_flow\` DROP COLUMN \`apiConfig\`;`)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
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'
|
||||
import { AddApiConfig1694099200729 } from './1694099200729-AddApiConfig'
|
||||
|
||||
export const mysqlMigrations = [
|
||||
Init1693840429259,
|
||||
ModifyChatFlow1693997791471,
|
||||
ModifyChatMessage1693999022236,
|
||||
ModifyCredential1693999261583,
|
||||
ModifyTool1694001465232,
|
||||
AddApiConfig1694099200729
|
||||
]
|
||||
@@ -0,0 +1,64 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm'
|
||||
|
||||
export class Init1693891895163 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`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" 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 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" varchar NULL,
|
||||
"createdDate" timestamp NOT NULL DEFAULT now(),
|
||||
CONSTRAINT "PK_3cc0d85193aade457d3077dd06b" PRIMARY KEY (id)
|
||||
);`
|
||||
)
|
||||
await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_e574527322272fd838f4f0f3d3" ON chat_message USING btree (chatflowid);`)
|
||||
await queryRunner.query(
|
||||
`CREATE TABLE IF NOT EXISTS credential (
|
||||
id uuid NOT NULL DEFAULT uuid_generate_v4(),
|
||||
"name" varchar NOT NULL,
|
||||
"credentialName" varchar 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 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" varchar NULL,
|
||||
func varchar 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<void> {
|
||||
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`)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm'
|
||||
|
||||
export class ModifyChatFlow1693995626941 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE "chat_flow" ALTER COLUMN "chatbotConfig" TYPE TEXT;`)
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE "chat_flow" ALTER COLUMN "chatbotConfig" TYPE VARCHAR;`)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm'
|
||||
|
||||
export class ModifyChatMessage1693996694528 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE "chat_message" ALTER COLUMN "sourceDocuments" TYPE TEXT;`)
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE "chat_message" ALTER COLUMN "sourceDocuments" TYPE VARCHAR;`)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm'
|
||||
|
||||
export class ModifyCredential1693997070000 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE "credential" ALTER COLUMN "encryptedData" TYPE TEXT;`)
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE "credential" ALTER COLUMN "encryptedData" TYPE VARCHAR;`)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm'
|
||||
|
||||
export class ModifyTool1693997339912 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE "tool" ALTER COLUMN "schema" TYPE TEXT, ALTER COLUMN "func" TYPE TEXT;`)
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE "tool" ALTER COLUMN "schema" TYPE VARCHAR, ALTER COLUMN "func" TYPE VARCHAR;`)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm'
|
||||
|
||||
export class AddApiConfig1694099183389 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE "chat_flow" ADD COLUMN "apiConfig" TEXT;`)
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE "chat_flow" DROP COLUMN "apiConfig";`)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
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'
|
||||
import { AddApiConfig1694099183389 } from './1694099183389-AddApiConfig'
|
||||
|
||||
export const postgresMigrations = [
|
||||
Init1693891895163,
|
||||
ModifyChatFlow1693995626941,
|
||||
ModifyChatMessage1693996694528,
|
||||
ModifyCredential1693997070000,
|
||||
ModifyTool1693997339912,
|
||||
AddApiConfig1694099183389
|
||||
]
|
||||
@@ -0,0 +1,26 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm'
|
||||
|
||||
export class Init1693835579790 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`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 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 IF NOT EXISTS "IDX_e574527322272fd838f4f0f3d3" ON "chat_message" ("chatflowid") ;`)
|
||||
await queryRunner.query(
|
||||
`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 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')));`
|
||||
)
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
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`)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm'
|
||||
|
||||
export class ModifyChatFlow1693920824108 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
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<void> {
|
||||
await queryRunner.query(`DROP TABLE temp_chat_flow`)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm'
|
||||
|
||||
export class ModifyChatMessage1693921865247 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
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;`)
|
||||
await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_e574527322272fd838f4f0f3d3" ON "chat_message" ("chatflowid") ;`)
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`DROP TABLE temp_chat_message`)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm'
|
||||
|
||||
export class ModifyCredential1693923551694 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
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<void> {
|
||||
await queryRunner.query(`DROP TABLE temp_credential`)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm'
|
||||
|
||||
export class ModifyTool1693924207475 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
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<void> {
|
||||
await queryRunner.query(`DROP TABLE temp_tool`)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm'
|
||||
|
||||
export class AddApiConfig1694090982460 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE "chat_flow" ADD COLUMN "apiConfig" TEXT;`)
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE "chat_flow" DROP COLUMN "apiConfig";`)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
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'
|
||||
import { AddApiConfig1694090982460 } from './1694090982460-AddApiConfig'
|
||||
|
||||
export const sqliteMigrations = [
|
||||
Init1693835579790,
|
||||
ModifyChatFlow1693920824108,
|
||||
ModifyChatMessage1693921865247,
|
||||
ModifyCredential1693923551694,
|
||||
ModifyTool1693924207475,
|
||||
AddApiConfig1694090982460
|
||||
]
|
||||
@@ -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'
|
||||
@@ -48,12 +48,13 @@ 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'
|
||||
import { createRateLimiter, getRateLimiter, initializeRateLimiter } from './utils/rateLimit'
|
||||
|
||||
export class App {
|
||||
app: express.Application
|
||||
@@ -71,6 +72,9 @@ export class App {
|
||||
.then(async () => {
|
||||
logger.info('📦 [server]: Data Source has been initialized!')
|
||||
|
||||
// Run Migrations Scripts
|
||||
await this.AppDataSource.runMigrations({ transaction: 'each' })
|
||||
|
||||
// Initialize nodes pool
|
||||
this.nodesPool = new NodesPool()
|
||||
await this.nodesPool.initialize()
|
||||
@@ -83,6 +87,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)
|
||||
@@ -94,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())
|
||||
|
||||
@@ -113,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/')) {
|
||||
@@ -124,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
|
||||
// ----------------------------------------
|
||||
@@ -245,7 +267,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)
|
||||
})
|
||||
|
||||
@@ -314,6 +336,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)
|
||||
|
||||
@@ -655,9 +680,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) => {
|
||||
@@ -996,6 +1026,10 @@ export async function getChatId(chatflowid: string) {
|
||||
|
||||
let serverApp: App | undefined
|
||||
|
||||
export async function getAllChatFlow(): Promise<IChatFlow[]> {
|
||||
return await getDataSource().getRepository(ChatFlow).find()
|
||||
}
|
||||
|
||||
export async function start(): Promise<void> {
|
||||
serverApp = new App()
|
||||
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
import { NextFunction, Request, Response } from 'express'
|
||||
import { rateLimit, RateLimitRequestHandler } from 'express-rate-limit'
|
||||
import { IChatFlow } from '../Interface'
|
||||
import { Mutex } from 'async-mutex'
|
||||
|
||||
let rateLimiters: Record<string, RateLimitRequestHandler> = {}
|
||||
const rateLimiterMutex = new Mutex()
|
||||
|
||||
async function addRateLimiter(id: string, duration: number, limit: number, message: string) {
|
||||
const release = await rateLimiterMutex.acquire()
|
||||
try {
|
||||
rateLimiters[id] = rateLimit({
|
||||
windowMs: duration * 1000,
|
||||
max: limit,
|
||||
handler: (req, res) => {
|
||||
res.status(429).send(message)
|
||||
}
|
||||
})
|
||||
} finally {
|
||||
release()
|
||||
}
|
||||
}
|
||||
|
||||
export function getRateLimiter(req: Request, res: Response, next: NextFunction) {
|
||||
const id = req.params.id
|
||||
|
||||
if (!rateLimiters[id]) return next()
|
||||
|
||||
const idRateLimiter = rateLimiters[id]
|
||||
|
||||
return idRateLimiter(req, res, next)
|
||||
}
|
||||
|
||||
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)
|
||||
})
|
||||
}
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
# 流程界面
|
||||
|
||||
[English](<./README.md>) | 中文
|
||||
[English](./README.md) | 中文
|
||||
|
||||
Flowise的React前端界面。
|
||||
Flowise 的 React 前端界面。
|
||||
|
||||

|
||||
|
||||
@@ -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)下提供。
|
||||
|
||||
@@ -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).
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-settings" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
|
||||
<path d="M10.325 4.317c.426 -1.756 2.924 -1.756 3.35 0a1.724 1.724 0 0 0 2.573 1.066c1.543 -.94 3.31 .826 2.37 2.37a1.724 1.724 0 0 0 1.065 2.572c1.756 .426 1.756 2.924 0 3.35a1.724 1.724 0 0 0 -1.066 2.573c.94 1.543 -.826 3.31 -2.37 2.37a1.724 1.724 0 0 0 -2.572 1.065c-.426 1.756 -2.924 1.756 -3.35 0a1.724 1.724 0 0 0 -2.573 -1.066c-1.543 .94 -3.31 -.826 -2.37 -2.37a1.724 1.724 0 0 0 -1.065 -2.572c-1.756 -.426 -1.756 -2.924 0 -3.35a1.724 1.724 0 0 0 1.066 -2.573c-.94 -1.543 .826 -3.31 2.37 -2.37c1 .608 2.296 .07 2.572 -1.065z"></path>
|
||||
<path d="M9 12a3 3 0 1 0 6 0a3 3 0 0 0 -6 0"></path>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 896 B |
@@ -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 && <EmbedChat chatflowid={dialogProps.chatflowid} />}
|
||||
{codeLang !== 'Embed' && codeLang !== 'Share Chatbot' && (
|
||||
{codeLang !== 'Embed' && codeLang !== 'Share Chatbot' && codeLang !== 'Configuration' && (
|
||||
<>
|
||||
<CopyBlock
|
||||
theme={atomOneDark}
|
||||
@@ -770,6 +774,7 @@ formData.append("openAIApiKey[openAIEmbeddings_0]", "sk-my-openai-2nd-key")`
|
||||
{codeLang === 'Share Chatbot' && !chatflowApiKeyId && (
|
||||
<ShareChatbot isSessionMemory={dialogProps.isSessionMemory} />
|
||||
)}
|
||||
{codeLang === 'Configuration' && <Configuration />}
|
||||
</TabPanel>
|
||||
))}
|
||||
</DialogContent>
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
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 ?? '')
|
||||
const [limitDuration, setLimitDuration] = useState(apiConfig?.rateLimit?.limitDuration ?? '')
|
||||
const [limitMsg, setLimitMsg] = useState(apiConfig?.rateLimit?.limitMsg ?? '')
|
||||
|
||||
const formatObj = () => {
|
||||
const obj = {
|
||||
rateLimit: {}
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
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) => (
|
||||
<Button style={{ color: 'white' }} onClick={() => closeSnackbar(key)}>
|
||||
<IconX />
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
})
|
||||
dispatch({ type: SET_CHATFLOW, chatflow: saveResp.data })
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
const errorData = error.response
|
||||
? error.response.data || `${error.response.status}: ${error.response.statusText}`
|
||||
: error.message
|
||||
enqueueSnackbar({
|
||||
message: `Failed to save API Configuration: ${errorData}`,
|
||||
options: {
|
||||
key: new Date().getTime() + Math.random(),
|
||||
variant: 'error',
|
||||
persist: true,
|
||||
action: (key) => (
|
||||
<Button style={{ color: 'white' }} onClick={() => closeSnackbar(key)}>
|
||||
<IconX />
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
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 (
|
||||
<Box sx={{ pt: 2, pb: 2 }}>
|
||||
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'flex-start' }}>
|
||||
<Typography sx={{ mb: 1 }}>{fieldLabel}</Typography>
|
||||
<OutlinedInput
|
||||
id={fieldName}
|
||||
type={fieldType}
|
||||
fullWidth
|
||||
value={message}
|
||||
placeholder={placeholder}
|
||||
name={fieldName}
|
||||
onChange={(e) => {
|
||||
onTextChanged(e.target.value, fieldName)
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
{/*Rate Limit*/}
|
||||
<Typography variant='h4' sx={{ mb: 1, mt: 2 }}>
|
||||
Rate Limit
|
||||
</Typography>
|
||||
{textField(limitMax, 'limitMax', 'Message Limit per Duration', 'number')}
|
||||
{textField(limitDuration, 'limitDuration', 'Duration in Second', 'number')}
|
||||
{textField(limitMsg, 'limitMsg', 'Limit Message', 'string')}
|
||||
|
||||
<StyledButton style={{ marginBottom: 10, marginTop: 10 }} variant='contained' onClick={() => onSave()}>
|
||||
Save Changes
|
||||
</StyledButton>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
Configuration.propTypes = {
|
||||
isSessionMemory: PropTypes.bool
|
||||
}
|
||||
|
||||
export default Configuration
|
||||
Reference in New Issue
Block a user