({shapeId, modelData, modelOptions, disabled})
| 28 | * @returns {JSX.Element} 大模型节点模型表单的DOM。 |
| 29 | */ |
| 30 | const _ModelForm = ({shapeId, modelData, modelOptions, disabled}) => { |
| 31 | const shape = useShapeContext(); |
| 32 | const dispatch = useDispatch(); |
| 33 | const form = useFormContext(); |
| 34 | const {t} = useTranslation(); |
| 35 | const startNode = shape.page.sm.findShapeBy(s => s.type === 'startNodeStart'); |
| 36 | const maxMemoryRounds = modelData.maxMemoryRounds; |
| 37 | const maxMemoryRoundsValue = parseInt(maxMemoryRounds.value); |
| 38 | const [maxTurnsOfStartNode, setMaxTurnsOfStartNode] = useState(startNode.getConversationTurn()); |
| 39 | const [promptOpen, setPromptOpen] = useState(false); |
| 40 | const [systemPromptOpen, setSystemPromptOpen] = useState(false); |
| 41 | |
| 42 | // 实时记录轮次数,用于比较. |
| 43 | const maxMemoryRoundsValueRef = useRef(maxMemoryRoundsValue); |
| 44 | |
| 45 | const promptContent = (<div className={'jade-font-size'} style={{lineHeight: '1.2'}}> |
| 46 | <Trans i18nKey='promptPopover' components={{p: <p/>}}/> |
| 47 | </div>); |
| 48 | |
| 49 | // 当轮次改变时触发. |
| 50 | const onConversationTurnChange = (e) => { |
| 51 | dispatch({type: 'changeConfig', id: maxMemoryRounds.id, value: String(e)}); |
| 52 | maxMemoryRoundsValueRef.current = e; |
| 53 | }; |
| 54 | |
| 55 | // 监听开始节点中,对话轮数的修改. |
| 56 | useEffect(() => { |
| 57 | shape.observeTo('start_node_conversation_turn_count', startNode.id, 'start_node_conversation_turn_count', |
| 58 | (args) => { |
| 59 | if (args.value === null || args.value === undefined) { |
| 60 | return; |
| 61 | } |
| 62 | setMaxTurnsOfStartNode(args.value); |
| 63 | if (args.value < maxMemoryRoundsValueRef.current) { |
| 64 | dispatch({type: 'changeConfig', id: maxMemoryRounds.id, value: String(args.value)}); |
| 65 | maxMemoryRoundsValueRef.current = args.value; |
| 66 | } |
| 67 | }); |
| 68 | }, []); |
| 69 | |
| 70 | const systemPromptName = `system-prompt-${shapeId}`; |
| 71 | |
| 72 | const triggerAIGenerateEvent = (applyPrompt) => { |
| 73 | return () => { |
| 74 | shape.page.triggerEvent({ |
| 75 | type: 'GENERATE_AI_PROMPT', |
| 76 | value: { |
| 77 | model: DEFAULT_AP_PROMPT_MODEL_CONFIG.MODEL, |
| 78 | temperature: DEFAULT_AP_PROMPT_MODEL_CONFIG.TEMPERATURE, |
| 79 | type: 'system', |
| 80 | applyPrompt: (promptText) => { |
| 81 | applyPrompt(promptText); |
| 82 | }, |
| 83 | }, |
| 84 | }); |
| 85 | }; |
| 86 | }; |
| 87 |
nothing calls this directly
no test coverage detected