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 useConfig from './use-config'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { useInstalledPluginList } from '@/service/use-plugins' 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 AgentNode: FC<NodeProps<AgentNodeType>> = (props) => {
const { inputs, currentStrategy } = useConfig(props.id, props.data) const { inputs, currentStrategy } = useConfig(props.id, props.data)
@ -16,11 +17,28 @@ const AgentNode: FC<NodeProps<AgentNodeType>> = (props) => {
const pluginList = useInstalledPluginList() const pluginList = useInstalledPluginList()
// TODO: Implement models // TODO: Implement models
const models = useMemo(() => { 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 selected, show in node
// if required and not selected, show empty selector // if required and not selected, show empty selector
// if not required and not selected, show nothing // if not required and not selected, show nothing
}, [currentStrategy, inputs.agent_parameters]) }, [currentStrategy, inputs])
const tools = useMemo(() => { const tools = useMemo(() => {
const tools: Array<ToolIconProps> = [] const tools: Array<ToolIconProps> = []
@ -49,24 +67,20 @@ const AgentNode: FC<NodeProps<AgentNodeType>> = (props) => {
{inputs.agent_strategy_label} {inputs.agent_strategy_label}
</SettingItem> </SettingItem>
: <SettingItem label={t('workflow.nodes.agent.strategyNotSet')} />} : <SettingItem label={t('workflow.nodes.agent.strategyNotSet')} />}
<Group {models.length && <Group
label={<GroupLabel className='mt-1'> label={<GroupLabel className='mt-1'>
{t('workflow.nodes.agent.model')} {t('workflow.nodes.agent.model')}
</GroupLabel>} </GroupLabel>}
> >
<ModelSelector {models.map((model) => {
modelList={[]} return <ModelSelector
readonly // TODO: ugly
/> key={model?.param || Math.random()}
<ModelSelector modelList={[]}
modelList={[]} defaultModel={model || undefined}
readonly />
/> })}
<ModelSelector </Group>}
modelList={[]}
readonly
/>
</Group>
<Group label={<GroupLabel className='mt-1'> <Group label={<GroupLabel className='mt-1'>
{t('workflow.nodes.agent.toolbox')} {t('workflow.nodes.agent.toolbox')}
</GroupLabel>}> </GroupLabel>}>

View File

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