import type { FC } from 'react' import { memo, useMemo } from 'react' import { useTranslation } from 'react-i18next' import type { NodePanelProps } from '@/app/components/workflow/types' import Field from '@/app/components/workflow/nodes/_base/components/field' import Split from '@/app/components/workflow/nodes/_base/components/split' import VarReferencePicker from '@/app/components/workflow/nodes/_base/components/variable/var-reference-picker' import OutputVars, { VarItem } from '@/app/components/workflow/nodes/_base/components/output-vars' import ModelParameterModal from '@/app/components/header/account-setting/model-provider-page/model-parameter-modal' import { fetchAndMergeValidCompletionParams } from '@/utils/completion-params' import Toast from '@/app/components/base/toast' import AddButton2 from '@/app/components/base/button/add-button' import Editor from '@/app/components/workflow/nodes/_base/components/prompt/editor' import useAvailableVarList from '@/app/components/workflow/nodes/_base/hooks/use-available-var-list' import Input from '@/app/components/base/input' import type { JudgingLLMNodeType } from './types' import useNodeCrud from '@/app/components/workflow/nodes/_base/hooks/use-node-crud' import produce from 'immer' const Panel: FC> = ({ id, data }) => { const { t } = useTranslation() const { inputs, setInputs } = useNodeCrud(id, data) const filterVar = useMemo(() => (_: any) => true, []) const { availableVars, availableNodesWithParent } = useAvailableVarList(id, { onlyLeafNodeVar: false, filterVar }) return (
{ try { const { params } = await fetchAndMergeValidCompletionParams( model.provider, model.modelId, data.judge_model?.completion_params || {}, true, ) setInputs(produce(inputs, (draft) => { (draft as any).judge_model = { provider: model.provider, name: model.modelId, mode: model.mode || 'chat', completion_params: params, } })) } catch { Toast.notify({ type: 'error', message: t('common.error') }) setInputs(produce(inputs, (draft) => { (draft as any).judge_model = { provider: model.provider, name: model.modelId, mode: model.mode || 'chat', completion_params: {}, } })) } }} onCompletionParamsChange={newParams => setInputs(produce(inputs, (draft) => { (draft as any).judge_model.completion_params = newParams }))} hideDebugWithMultipleModel debugWithMultipleModel={false} readonly={false} />
system
} value={data.rubric_prompt_template || ''} onChange={v => setInputs(produce(inputs, (draft) => { (draft as any).rubric_prompt_template = v }))} readOnly={false} isShowContext={false} isChatApp isChatModel hasSetBlockStatus={{ history: false, query: false, context: false }} nodesOutputVars={availableVars} availableNodes={availableNodesWithParent} isSupportFileVar />
setInputs(produce(inputs, (draft) => { (draft as any).rubric_prompt_template = 'You are a strict evaluator. Given a goal and a model response, decide pass/fail, give a rating 0-10, and provide concise feedback.\\n\\nGoal:\\n{goal}\\n\\nResponse:\\n{response}\\n\\nReturn JSON: {"passed": boolean, "rating": number, "feedback": string}.' }))} />
Insert default rubric
setInputs(produce(inputs, (draft) => { (draft as any).pass_threshold = Number(e.target.value) }))} />
Goal
setInputs(produce(inputs, (draft) => { (draft as any).inputs = { ...(draft as any).inputs, goal: v } }))} />
Response
setInputs(produce(inputs, (draft) => { (draft as any).inputs = { ...(draft as any).inputs, response: v } }))} />
<>
) } export default memo(Panel)