add additional params
This commit is contained in:
parent
0f6da4c44f
commit
e53651a415
|
|
@ -1,5 +1,5 @@
|
||||||
import { INode, INodeData, INodeParams } from '../../../src/Interface'
|
import { INode, INodeData, INodeParams } from '../../../src/Interface'
|
||||||
import { initializeAgentExecutorWithOptions, AgentExecutor } from 'langchain/agents'
|
import { initializeAgentExecutorWithOptions, AgentExecutor, InitializeAgentExecutorOptions } from 'langchain/agents'
|
||||||
import { Tool } from 'langchain/tools'
|
import { Tool } from 'langchain/tools'
|
||||||
import { BaseChatModel } from 'langchain/chat_models/base'
|
import { BaseChatModel } from 'langchain/chat_models/base'
|
||||||
import { BaseChatMemory } from 'langchain/memory'
|
import { BaseChatMemory } from 'langchain/memory'
|
||||||
|
|
@ -39,6 +39,22 @@ class ConversationalAgent_Agents implements INode {
|
||||||
label: 'Memory',
|
label: 'Memory',
|
||||||
name: 'memory',
|
name: 'memory',
|
||||||
type: 'BaseChatMemory'
|
type: 'BaseChatMemory'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'System Message',
|
||||||
|
name: 'systemMessage',
|
||||||
|
type: 'string',
|
||||||
|
rows: 4,
|
||||||
|
optional: true,
|
||||||
|
additionalParams: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Human Message',
|
||||||
|
name: 'humanMessage',
|
||||||
|
type: 'string',
|
||||||
|
rows: 4,
|
||||||
|
optional: true,
|
||||||
|
additionalParams: true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
@ -47,11 +63,25 @@ class ConversationalAgent_Agents implements INode {
|
||||||
const model = nodeData.inputs?.model as BaseChatModel
|
const model = nodeData.inputs?.model as BaseChatModel
|
||||||
const tools = nodeData.inputs?.tools as Tool[]
|
const tools = nodeData.inputs?.tools as Tool[]
|
||||||
const memory = nodeData.inputs?.memory as BaseChatMemory
|
const memory = nodeData.inputs?.memory as BaseChatMemory
|
||||||
|
const humanMessage = nodeData.inputs?.humanMessage as string
|
||||||
|
const systemMessage = nodeData.inputs?.systemMessage as string
|
||||||
|
|
||||||
const executor = await initializeAgentExecutorWithOptions(tools, model, {
|
const obj: InitializeAgentExecutorOptions = {
|
||||||
agentType: 'chat-conversational-react-description',
|
agentType: 'chat-conversational-react-description',
|
||||||
verbose: true
|
verbose: true
|
||||||
})
|
}
|
||||||
|
|
||||||
|
const agentArgs: any = {}
|
||||||
|
if (humanMessage) {
|
||||||
|
agentArgs.humanMessage = humanMessage
|
||||||
|
}
|
||||||
|
if (systemMessage) {
|
||||||
|
agentArgs.systemMessage = systemMessage
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Object.keys(agentArgs).length) obj.agentArgs = agentArgs
|
||||||
|
|
||||||
|
const executor = await initializeAgentExecutorWithOptions(tools, model, obj)
|
||||||
executor.memory = memory
|
executor.memory = memory
|
||||||
return executor
|
return executor
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,7 @@ export interface INodeParams {
|
||||||
acceptVariable?: boolean
|
acceptVariable?: boolean
|
||||||
placeholder?: string
|
placeholder?: string
|
||||||
fileType?: string
|
fileType?: string
|
||||||
|
additionalParams?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface INodeExecutionData {
|
export interface INodeExecutionData {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,64 @@
|
||||||
|
import { createPortal } from 'react-dom'
|
||||||
|
import { useState, useEffect } from 'react'
|
||||||
|
import PropTypes from 'prop-types'
|
||||||
|
import { Dialog, DialogContent } from '@mui/material'
|
||||||
|
import PerfectScrollbar from 'react-perfect-scrollbar'
|
||||||
|
import NodeInputHandler from 'views/canvas/NodeInputHandler'
|
||||||
|
|
||||||
|
const AdditionalParamsDialog = ({ show, dialogProps, onCancel }) => {
|
||||||
|
const portalElement = document.getElementById('portal')
|
||||||
|
|
||||||
|
const [inputParams, setInputParams] = useState([])
|
||||||
|
const [data, setData] = useState({})
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (dialogProps.inputParams) setInputParams(dialogProps.inputParams)
|
||||||
|
if (dialogProps.data) setData(dialogProps.data)
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
setInputParams([])
|
||||||
|
setData({})
|
||||||
|
}
|
||||||
|
}, [dialogProps])
|
||||||
|
|
||||||
|
const component = show ? (
|
||||||
|
<Dialog
|
||||||
|
onClose={onCancel}
|
||||||
|
open={show}
|
||||||
|
fullWidth
|
||||||
|
maxWidth='sm'
|
||||||
|
aria-labelledby='alert-dialog-title'
|
||||||
|
aria-describedby='alert-dialog-description'
|
||||||
|
>
|
||||||
|
<DialogContent>
|
||||||
|
<PerfectScrollbar
|
||||||
|
style={{
|
||||||
|
height: '100%',
|
||||||
|
maxHeight: 'calc(100vh - 220px)',
|
||||||
|
overflowX: 'hidden'
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{inputParams.map((inputParam, index) => (
|
||||||
|
<NodeInputHandler
|
||||||
|
disabled={dialogProps.disabled}
|
||||||
|
key={index}
|
||||||
|
inputParam={inputParam}
|
||||||
|
data={data}
|
||||||
|
isAdditionalParams={true}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</PerfectScrollbar>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
) : null
|
||||||
|
|
||||||
|
return createPortal(component, portalElement)
|
||||||
|
}
|
||||||
|
|
||||||
|
AdditionalParamsDialog.propTypes = {
|
||||||
|
show: PropTypes.bool,
|
||||||
|
dialogProps: PropTypes.object,
|
||||||
|
onCancel: PropTypes.func
|
||||||
|
}
|
||||||
|
|
||||||
|
export default AdditionalParamsDialog
|
||||||
|
|
@ -1,14 +1,15 @@
|
||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import { useContext } from 'react'
|
import { useContext, useState } from 'react'
|
||||||
|
|
||||||
// material-ui
|
// material-ui
|
||||||
import { styled, useTheme } from '@mui/material/styles'
|
import { styled, useTheme } from '@mui/material/styles'
|
||||||
import { IconButton, Box, Typography, Divider } from '@mui/material'
|
import { IconButton, Box, Typography, Divider, Button } from '@mui/material'
|
||||||
|
|
||||||
// project imports
|
// project imports
|
||||||
import MainCard from 'ui-component/cards/MainCard'
|
import MainCard from 'ui-component/cards/MainCard'
|
||||||
import NodeInputHandler from './NodeInputHandler'
|
import NodeInputHandler from './NodeInputHandler'
|
||||||
import NodeOutputHandler from './NodeOutputHandler'
|
import NodeOutputHandler from './NodeOutputHandler'
|
||||||
|
import AdditionalParamsDialog from 'ui-component/dialog/AdditionalParamsDialog'
|
||||||
|
|
||||||
// const
|
// const
|
||||||
import { baseURL } from 'store/constant'
|
import { baseURL } from 'store/constant'
|
||||||
|
|
@ -35,6 +36,20 @@ const CanvasNode = ({ data }) => {
|
||||||
const theme = useTheme()
|
const theme = useTheme()
|
||||||
const { deleteNode, duplicateNode } = useContext(flowContext)
|
const { deleteNode, duplicateNode } = useContext(flowContext)
|
||||||
|
|
||||||
|
const [showDialog, setShowDialog] = useState(false)
|
||||||
|
const [dialogProps, setDialogProps] = useState({})
|
||||||
|
|
||||||
|
const onDialogClicked = () => {
|
||||||
|
const dialogProps = {
|
||||||
|
data,
|
||||||
|
inputParams: data.inputParams.filter((param) => param.additionalParams),
|
||||||
|
confirmButtonName: 'Save',
|
||||||
|
cancelButtonName: 'Cancel'
|
||||||
|
}
|
||||||
|
setDialogProps(dialogProps)
|
||||||
|
setShowDialog(true)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<CardWrapper
|
<CardWrapper
|
||||||
|
|
@ -118,7 +133,13 @@ const CanvasNode = ({ data }) => {
|
||||||
{data.inputParams.map((inputParam, index) => (
|
{data.inputParams.map((inputParam, index) => (
|
||||||
<NodeInputHandler key={index} inputParam={inputParam} data={data} />
|
<NodeInputHandler key={index} inputParam={inputParam} data={data} />
|
||||||
))}
|
))}
|
||||||
|
{data.inputParams.find((param) => param.additionalParams) && (
|
||||||
|
<div style={{ textAlign: 'center' }}>
|
||||||
|
<Button sx={{ borderRadius: 25, width: '90%', mb: 2 }} variant='outlined' onClick={onDialogClicked}>
|
||||||
|
Additional Parameters
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
<Divider />
|
<Divider />
|
||||||
<Box sx={{ background: theme.palette.asyncSelect.main, p: 1 }}>
|
<Box sx={{ background: theme.palette.asyncSelect.main, p: 1 }}>
|
||||||
<Typography
|
<Typography
|
||||||
|
|
@ -137,6 +158,11 @@ const CanvasNode = ({ data }) => {
|
||||||
))}
|
))}
|
||||||
</Box>
|
</Box>
|
||||||
</CardWrapper>
|
</CardWrapper>
|
||||||
|
<AdditionalParamsDialog
|
||||||
|
show={showDialog}
|
||||||
|
dialogProps={dialogProps}
|
||||||
|
onCancel={() => setShowDialog(false)}
|
||||||
|
></AdditionalParamsDialog>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ const CustomWidthTooltip = styled(({ className, ...props }) => <Tooltip {...prop
|
||||||
|
|
||||||
// ===========================|| NodeInputHandler ||=========================== //
|
// ===========================|| NodeInputHandler ||=========================== //
|
||||||
|
|
||||||
const NodeInputHandler = ({ inputAnchor, inputParam, data, disabled = false }) => {
|
const NodeInputHandler = ({ inputAnchor, inputParam, data, disabled = false, isAdditionalParams = false }) => {
|
||||||
const theme = useTheme()
|
const theme = useTheme()
|
||||||
const ref = useRef(null)
|
const ref = useRef(null)
|
||||||
const { reactFlowInstance } = useContext(flowContext)
|
const { reactFlowInstance } = useContext(flowContext)
|
||||||
|
|
@ -96,7 +96,7 @@ const NodeInputHandler = ({ inputAnchor, inputParam, data, disabled = false }) =
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{inputParam && (
|
{((inputParam && !inputParam.additionalParams) || isAdditionalParams) && (
|
||||||
<>
|
<>
|
||||||
{inputParam.acceptVariable && (
|
{inputParam.acceptVariable && (
|
||||||
<CustomWidthTooltip placement='left' title={inputParam.type}>
|
<CustomWidthTooltip placement='left' title={inputParam.type}>
|
||||||
|
|
@ -186,7 +186,8 @@ NodeInputHandler.propTypes = {
|
||||||
inputAnchor: PropTypes.object,
|
inputAnchor: PropTypes.object,
|
||||||
inputParam: PropTypes.object,
|
inputParam: PropTypes.object,
|
||||||
data: PropTypes.object,
|
data: PropTypes.object,
|
||||||
disabled: PropTypes.bool
|
disabled: PropTypes.bool,
|
||||||
|
isAdditionalParams: PropTypes.bool
|
||||||
}
|
}
|
||||||
|
|
||||||
export default NodeInputHandler
|
export default NodeInputHandler
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,15 @@
|
||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
|
import { useState } from 'react'
|
||||||
|
|
||||||
// material-ui
|
// material-ui
|
||||||
import { styled, useTheme } from '@mui/material/styles'
|
import { styled, useTheme } from '@mui/material/styles'
|
||||||
import { Box, Typography, Divider } from '@mui/material'
|
import { Box, Typography, Divider, Button } from '@mui/material'
|
||||||
|
|
||||||
// project imports
|
// project imports
|
||||||
import MainCard from 'ui-component/cards/MainCard'
|
import MainCard from 'ui-component/cards/MainCard'
|
||||||
import NodeInputHandler from 'views/canvas/NodeInputHandler'
|
import NodeInputHandler from 'views/canvas/NodeInputHandler'
|
||||||
import NodeOutputHandler from 'views/canvas/NodeOutputHandler'
|
import NodeOutputHandler from 'views/canvas/NodeOutputHandler'
|
||||||
|
import AdditionalParamsDialog from 'ui-component/dialog/AdditionalParamsDialog'
|
||||||
|
|
||||||
// const
|
// const
|
||||||
import { baseURL } from 'store/constant'
|
import { baseURL } from 'store/constant'
|
||||||
|
|
@ -31,6 +33,21 @@ const CardWrapper = styled(MainCard)(({ theme }) => ({
|
||||||
const MarketplaceCanvasNode = ({ data }) => {
|
const MarketplaceCanvasNode = ({ data }) => {
|
||||||
const theme = useTheme()
|
const theme = useTheme()
|
||||||
|
|
||||||
|
const [showDialog, setShowDialog] = useState(false)
|
||||||
|
const [dialogProps, setDialogProps] = useState({})
|
||||||
|
|
||||||
|
const onDialogClicked = () => {
|
||||||
|
const dialogProps = {
|
||||||
|
data,
|
||||||
|
inputParams: data.inputParams.filter((param) => param.additionalParams),
|
||||||
|
disabled: true,
|
||||||
|
confirmButtonName: 'Save',
|
||||||
|
cancelButtonName: 'Cancel'
|
||||||
|
}
|
||||||
|
setDialogProps(dialogProps)
|
||||||
|
setShowDialog(true)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<CardWrapper
|
<CardWrapper
|
||||||
|
|
@ -93,7 +110,13 @@ const MarketplaceCanvasNode = ({ data }) => {
|
||||||
{data.inputParams.map((inputParam, index) => (
|
{data.inputParams.map((inputParam, index) => (
|
||||||
<NodeInputHandler disabled={true} key={index} inputParam={inputParam} data={data} />
|
<NodeInputHandler disabled={true} key={index} inputParam={inputParam} data={data} />
|
||||||
))}
|
))}
|
||||||
|
{data.inputParams.find((param) => param.additionalParams) && (
|
||||||
|
<div style={{ textAlign: 'center' }}>
|
||||||
|
<Button sx={{ borderRadius: 25, width: '90%', mb: 2 }} variant='outlined' onClick={onDialogClicked}>
|
||||||
|
Additional Parameters
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
<Divider />
|
<Divider />
|
||||||
<Box sx={{ background: theme.palette.asyncSelect.main, p: 1 }}>
|
<Box sx={{ background: theme.palette.asyncSelect.main, p: 1 }}>
|
||||||
<Typography
|
<Typography
|
||||||
|
|
@ -112,6 +135,11 @@ const MarketplaceCanvasNode = ({ data }) => {
|
||||||
))}
|
))}
|
||||||
</Box>
|
</Box>
|
||||||
</CardWrapper>
|
</CardWrapper>
|
||||||
|
<AdditionalParamsDialog
|
||||||
|
show={showDialog}
|
||||||
|
dialogProps={dialogProps}
|
||||||
|
onCancel={() => setShowDialog(false)}
|
||||||
|
></AdditionalParamsDialog>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue