Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/Upsert files override #3569

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/server/src/Interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,5 +288,21 @@ export interface ICustomTemplate {
usecases?: string
}

export interface INodeOverrides {
[key: string]: {
label: string
name: string
type: string
enabled: boolean
}[]
}

export interface IVariableOverride {
id: string
name: string
type: 'static' | 'runtime'
enabled: boolean
}

// DocumentStore related
export * from './Interface.DocumentStore'
23 changes: 14 additions & 9 deletions packages/server/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ import {
INodeData,
INodeDependencies,
INodeDirectedGraph,
INodeOverrides,
INodeQueue,
IOverrideConfig,
IReactFlowEdge,
IReactFlowNode,
IVariableDict,
IVariableOverride,
IncomingInput
} from '../Interface'
import { cloneDeep, get, isEqual } from 'lodash'
Expand Down Expand Up @@ -436,8 +438,8 @@ type BuildFlowParams = {
appDataSource: DataSource
overrideConfig?: ICommonObject
apiOverrideStatus?: boolean
nodeOverrides?: ICommonObject
variableOverrides?: ICommonObject[]
nodeOverrides?: INodeOverrides
variableOverrides?: IVariableOverride[]
cachePool?: CachePool
isUpsert?: boolean
stopNodeId?: string
Expand Down Expand Up @@ -1000,15 +1002,15 @@ export const resolveVariables = async (
* Loop through each inputs and replace their value with override config values
* @param {INodeData} flowNodeData
* @param {ICommonObject} overrideConfig
* @param {ICommonObject} nodeOverrides
* @param {ICommonObject[]} variableOverrides
* @param {INodeOverrides} nodeOverrides
* @param {IVariableOverride[]} variableOverrides
* @returns {INodeData}
*/
export const replaceInputsWithConfig = (
flowNodeData: INodeData,
overrideConfig: ICommonObject,
nodeOverrides: ICommonObject,
variableOverrides: ICommonObject[]
nodeOverrides: INodeOverrides,
variableOverrides: IVariableOverride[]
) => {
const types = 'inputs'

Expand Down Expand Up @@ -1676,9 +1678,12 @@ export const aMonthAgo = () => {
export const getAPIOverrideConfig = (chatflow: IChatFlow) => {
try {
const apiConfig = chatflow.apiConfig ? JSON.parse(chatflow.apiConfig) : {}
const nodeOverrides = apiConfig.overrideConfig && apiConfig.overrideConfig.nodes ? apiConfig.overrideConfig.nodes : {}
const variableOverrides = apiConfig.overrideConfig && apiConfig.overrideConfig.variables ? apiConfig.overrideConfig.variables : []
const apiOverrideStatus = apiConfig.overrideConfig && apiConfig.overrideConfig.status ? apiConfig.overrideConfig.status : false
const nodeOverrides: INodeOverrides =
apiConfig.overrideConfig && apiConfig.overrideConfig.nodes ? apiConfig.overrideConfig.nodes : {}
const variableOverrides: IVariableOverride[] =
apiConfig.overrideConfig && apiConfig.overrideConfig.variables ? apiConfig.overrideConfig.variables : []
const apiOverrideStatus: boolean =
apiConfig.overrideConfig && apiConfig.overrideConfig.status ? apiConfig.overrideConfig.status : false

return { nodeOverrides, variableOverrides, apiOverrideStatus }
} catch (error) {
Expand Down
13 changes: 13 additions & 0 deletions packages/server/src/utils/upsertVector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,19 @@ export const upsertVector = async (req: Request, isInternal: boolean = false) =>
/*** Get API Config ***/
const { nodeOverrides, variableOverrides, apiOverrideStatus } = getAPIOverrideConfig(chatflow)

// For "files" input, add a new node override with the actual input name such as pdfFile, txtFile, etc.
for (const nodeLabel in nodeOverrides) {
const params = nodeOverrides[nodeLabel]
const enabledFileParam = params.find((param) => param.enabled && param.name === 'files')
if (enabledFileParam) {
const fileInputFieldFromExt = mapExtToInputField(enabledFileParam.type)
nodeOverrides[nodeLabel].push({
...enabledFileParam,
name: fileInputFieldFromExt
})
}
}

const upsertedResult = await buildFlow({
startingNodeIds,
reactFlowNodes: nodes,
Expand Down