feat: model list on agent node

This commit is contained in:
AkaraChen 2024-12-27 16:39:18 +08:00
parent 573c8f909c
commit 0108b28305
2 changed files with 31 additions and 17 deletions

View File

@ -9,6 +9,7 @@ import { ToolIcon } from './components/tool-icon'
import useConfig from './use-config'
import { useTranslation } from 'react-i18next'
import { useInstalledPluginList } from '@/service/use-plugins'
import { FormTypeEnum } from '@/app/components/header/account-setting/model-provider-page/declarations'
const AgentNode: FC<NodeProps<AgentNodeType>> = (props) => {
const { inputs, currentStrategy } = useConfig(props.id, props.data)
@ -16,11 +17,28 @@ const AgentNode: FC<NodeProps<AgentNodeType>> = (props) => {
const pluginList = useInstalledPluginList()
// TODO: Implement models
const models = useMemo(() => {
const models = []
if (!inputs) return []
const models = currentStrategy?.parameters
.filter(param => param.type === FormTypeEnum.modelSelector)
.flatMap((param) => {
const item = inputs.agent_parameters?.[param.name]
if (!item) {
if (param.required)
return null
else
return []
}
return {
provider: item.provider,
model: item.model,
param: param.name,
}
}) || []
return models
// if selected, show in node
// if required and not selected, show empty selector
// if not required and not selected, show nothing
}, [currentStrategy, inputs.agent_parameters])
}, [currentStrategy, inputs])
const tools = useMemo(() => {
const tools: Array<ToolIconProps> = []
@ -49,24 +67,20 @@ const AgentNode: FC<NodeProps<AgentNodeType>> = (props) => {
{inputs.agent_strategy_label}
</SettingItem>
: <SettingItem label={t('workflow.nodes.agent.strategyNotSet')} />}
<Group
{models.length && <Group
label={<GroupLabel className='mt-1'>
{t('workflow.nodes.agent.model')}
</GroupLabel>}
>
<ModelSelector
modelList={[]}
readonly
/>
<ModelSelector
modelList={[]}
readonly
/>
<ModelSelector
modelList={[]}
readonly
/>
</Group>
{models.map((model) => {
return <ModelSelector
// TODO: ugly
key={model?.param || Math.random()}
modelList={[]}
defaultModel={model || undefined}
/>
})}
</Group>}
<Group label={<GroupLabel className='mt-1'>
{t('workflow.nodes.agent.toolbox')}
</GroupLabel>}>

View File

@ -5,7 +5,7 @@ export type AgentNodeType = CommonNodeType & {
agent_strategy_provider_name?: string
agent_strategy_name?: string
agent_strategy_label?: string
agent_parameters?: ToolVarInputs,
agent_parameters?: Record<string, any>
agent_configurations?: Record<string, ToolVarInputs>
output_schema: Record<string, any>
}