Skip to content

Commit

Permalink
Merge branch 'feat/workflow' into deploy/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
iamjoel committed Mar 18, 2024
2 parents f5a52eb + 7b9fbcc commit 1a78b91
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
2 changes: 1 addition & 1 deletion web/app/components/workflow/nodes/llm/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const nodeDefault: NodeDefault<LLMNodeType> = {
text: '',
}],
context: {
enabled: true,
enabled: false,
variable_selector: [],
},
vision: {
Expand Down
12 changes: 6 additions & 6 deletions web/app/components/workflow/nodes/llm/panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ const Panel: FC<NodePanelProps<LLMNodeType>> = ({
label: t(`${i18nPrefix}.context`)!,
inputs: [{
label: '',
variable: 'contexts',
variable: '#context#',
type: InputVarType.contexts,
required: false,
}],
values: { contexts },
onChange: keyValue => setContexts((keyValue as any).contexts),
values: { '#context#': contexts },
onChange: keyValue => setContexts((keyValue as any)['#context#']),
},
)
}
Expand All @@ -97,12 +97,12 @@ const Panel: FC<NodePanelProps<LLMNodeType>> = ({
label: t(`${i18nPrefix}.vision`)!,
inputs: [{
label: t(`${i18nPrefix}.files`)!,
variable: 'visionFiles',
variable: '#files#',
type: InputVarType.files,
required: false,
}],
values: { visionFiles },
onChange: keyValue => setVisionFiles((keyValue as any).visionFiles),
values: { '#files#': visionFiles },
onChange: keyValue => setVisionFiles((keyValue as any)['#files#']),
},
)
}
Expand Down
28 changes: 23 additions & 5 deletions web/app/components/workflow/nodes/llm/use-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ const useConfig = (id: string, payload: LLMNodeType) => {
const handleContextVarChange = useCallback((newVar: ValueSelector | string) => {
const newInputs = produce(inputs, (draft) => {
draft.context.variable_selector = newVar as ValueSelector
draft.context.enabled = !!(newVar && newVar.length > 0)
})
setInputs(newInputs)
}, [inputs, setInputs])
Expand Down Expand Up @@ -198,14 +199,31 @@ const useConfig = (id: string, payload: LLMNodeType) => {
data: inputs,
defaultRunInputData: {
'#context#': [RETRIEVAL_OUTPUT_STRUCT],
'#vision#': [],
'#files#': [],
},
})

// const handleRun = (submitData: Record<string, any>) => {
// console.log(submitData)
// const res = produce(submitData, (draft) => {
// debugger
// if (draft.contexts) {
// draft['#context#'] = draft.contexts
// delete draft.contexts
// }
// if (draft.visionFiles) {
// draft['#files#'] = draft.visionFiles
// delete draft.visionFiles
// }
// })

// doHandleRun(res)
// }

const inputVarValues = (() => {
const vars: Record<string, any> = {}
Object.keys(runInputData)
.filter(key => !['#context#', '#vision#'].includes(key))
.filter(key => !['#context#', '#files#'].includes(key))
.forEach((key) => {
vars[key] = runInputData[key]
})
Expand All @@ -216,7 +234,7 @@ const useConfig = (id: string, payload: LLMNodeType) => {
const newVars = {
...newPayload,
'#context#': runInputData['#context#'],
'#vision#': runInputData['#vision#'],
'#files#': runInputData['#files#'],
}
setRunInputData(newVars)
}, [runInputData, setRunInputData])
Expand All @@ -229,11 +247,11 @@ const useConfig = (id: string, payload: LLMNodeType) => {
})
}, [runInputData, setRunInputData])

const visionFiles = runInputData['#vision']
const visionFiles = runInputData['#files#']
const setVisionFiles = useCallback((newFiles: any[]) => {
setRunInputData({
...runInputData,
'#vision#': newFiles,
'#files#': newFiles,
})
}, [runInputData, setRunInputData])

Expand Down

0 comments on commit 1a78b91

Please sign in to comment.