feat: add plugin instruction config (#2579)

* feat: add plugin instruction config

* fix build
This commit is contained in:
heheer
2024-08-30 17:12:57 +08:00
committed by GitHub
parent 2ef98c24be
commit 903f39fe17
20 changed files with 278 additions and 12 deletions

View File

@@ -96,6 +96,9 @@ export type AppChatConfigType = {
scheduledTriggerConfig?: AppScheduledTriggerConfigType;
chatInputGuide?: ChatInputGuideConfigType;
fileSelectConfig?: AppFileSelectConfigType;
// plugin
instruction?: string;
};
export type SettingAIDataType = {
model: string;

View File

@@ -52,6 +52,9 @@ export enum NodeInputKeyEnum {
scheduleTrigger = 'scheduleTrigger',
chatInputGuide = 'chatInputGuide',
// plugin config
instruction = 'instruction',
// entry
userChatInput = 'userChatInput',
inputFiles = 'inputFiles',

View File

@@ -94,6 +94,7 @@ export enum FlowNodeOutputTypeEnum {
export enum FlowNodeTypeEnum {
emptyNode = 'emptyNode',
systemConfig = 'userGuide',
pluginConfig = 'pluginConfig',
globalVariable = 'globalVariable',
workflowStart = 'workflowStart',
chatNode = 'chatNode',

View File

@@ -1,4 +1,5 @@
import { SystemConfigNode } from './system/systemConfig';
import { PluginConfigNode } from './system/pluginConfig';
import { EmptyNode } from './system/emptyNode';
import { WorkflowStart } from './system/workflowStart';
import { AiChatModule } from './system/aiChat';
@@ -57,6 +58,7 @@ export const appSystemModuleTemplates: FlowNodeTemplateType[] = [
];
/* plugin flow module templates */
export const pluginSystemModuleTemplates: FlowNodeTemplateType[] = [
PluginConfigNode,
PluginInputModule,
PluginOutputModule,
...systemNodes

View File

@@ -0,0 +1,21 @@
import { FlowNodeTypeEnum } from '../../node/constant';
import { FlowNodeTemplateType } from '../../type/node.d';
import { FlowNodeTemplateTypeEnum } from '../../constants';
import { getHandleConfig } from '../utils';
import { i18nT } from '../../../../../web/i18n/utils';
export const PluginConfigNode: FlowNodeTemplateType = {
id: FlowNodeTypeEnum.pluginConfig,
templateType: FlowNodeTemplateTypeEnum.systemInput,
flowNodeType: FlowNodeTypeEnum.pluginConfig,
sourceHandle: getHandleConfig(false, false, false, false),
targetHandle: getHandleConfig(false, false, false, false),
avatar: 'core/workflow/template/systemConfig',
name: i18nT('workflow:template.system_config'),
intro: '',
unique: true,
forbidDelete: true,
version: '4811',
inputs: [],
outputs: []
};

View File

@@ -79,6 +79,10 @@ export const splitGuideModule = (guideModules?: StoreNodeItemType) => {
guideModules?.inputs?.find((item) => item.key === NodeInputKeyEnum.chatInputGuide)?.value ||
defaultChatInputGuideConfig;
// plugin
const instruction: string =
guideModules?.inputs?.find((item) => item.key === NodeInputKeyEnum.instruction)?.value || '';
return {
welcomeText,
variables,
@@ -86,7 +90,8 @@ export const splitGuideModule = (guideModules?: StoreNodeItemType) => {
ttsConfig,
whisperConfig,
scheduledTriggerConfig,
chatInputGuide
chatInputGuide,
instruction
};
};
@@ -111,7 +116,8 @@ export const getAppChatConfig = ({
ttsConfig,
whisperConfig,
scheduledTriggerConfig,
chatInputGuide
chatInputGuide,
instruction
} = splitGuideModule(systemConfigNode);
const config: AppChatConfigType = {
@@ -120,6 +126,7 @@ export const getAppChatConfig = ({
whisperConfig,
scheduledTriggerConfig,
chatInputGuide,
instruction,
...chatConfig,
variables: storeVariables ?? chatConfig?.variables ?? variables,
welcomeText: storeWelcomeText ?? chatConfig?.welcomeText ?? welcomeText

View File

@@ -18,7 +18,8 @@ export const chatConfigType = {
whisperConfig: Object,
scheduledTriggerConfig: Object,
chatInputGuide: Object,
fileSelectConfig: Object
fileSelectConfig: Object,
instruction: String
};
// schema

View File

@@ -93,6 +93,7 @@ const callbackMap: Record<FlowNodeTypeEnum, Function> = {
// none
[FlowNodeTypeEnum.systemConfig]: dispatchSystemConfig,
[FlowNodeTypeEnum.pluginConfig]: () => Promise.resolve(),
[FlowNodeTypeEnum.emptyNode]: () => Promise.resolve(),
[FlowNodeTypeEnum.globalVariable]: () => Promise.resolve()
};

View File

@@ -97,6 +97,10 @@
"optional_value_type_tip": "One or more data types can be specified, and users can only select the configured type when adding fields in winter",
"other_questions": "Other questions",
"pass_returned_object_as_output_to_next_nodes": "Use the object returned in the code as output and pass it to subsequent nodes. \nThe variable name needs to correspond to the key of return",
"plugin": {
"Instruction_Tip": "You can configure a description to explain the purpose of this plugin. This description will be displayed each time before using the plugin. Standard Markdown syntax is supported.",
"Instructions": "Instructions"
},
"plugin_input": "Plug-in input",
"question_classification": "Problem classification",
"question_optimization": "Problem optimization",

View File

@@ -97,6 +97,10 @@
"optional_value_type_tip": "可以指定 1 个或多个数据类型,用户在动态添加字段时,仅可选择配置的类型",
"other_questions": "其他问题",
"pass_returned_object_as_output_to_next_nodes": "将代码中 return 的对象作为输出,传递给后续的节点。变量名需要对应 return 的 key",
"plugin": {
"Instruction_Tip": "可以配置一段说明,以解释该插件的用途。每次使用插件前,会显示该段说明。支持标准 Markdown 语法。",
"Instructions": "使用说明"
},
"plugin_input": "插件输入",
"question_classification": "问题分类",
"question_optimization": "问题优化",

View File

@@ -0,0 +1,4 @@
<svg width="36" height="36" viewBox="0 0 36 36" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect width="36" height="36" rx="6" fill="#F0F4FF"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M17.9998 9.83521C13.4905 9.83521 9.83496 13.4907 9.83496 18C9.83496 22.5093 13.4905 26.1648 17.9998 26.1648C22.5091 26.1648 26.1646 22.5093 26.1646 18C26.1646 13.4907 22.5091 9.83521 17.9998 9.83521ZM7.83496 18C7.83496 12.3861 12.3859 7.83521 17.9998 7.83521C23.6136 7.83521 28.1646 12.3861 28.1646 18C28.1646 23.6139 23.6136 28.1648 17.9998 28.1648C12.3859 28.1648 7.83496 23.6139 7.83496 18ZM18.2222 14.4387C17.815 14.3688 17.3962 14.4454 17.04 14.6547C16.6838 14.864 16.4132 15.1927 16.2761 15.5824C16.0929 16.1034 15.522 16.3772 15.001 16.1939C14.48 16.0106 14.2062 15.4397 14.3895 14.9187C14.6833 14.0834 15.2633 13.3791 16.0267 12.9304C16.7901 12.4818 17.6876 12.3178 18.5603 12.4675C19.433 12.6172 20.2246 13.0709 20.7949 13.7483C21.365 14.4256 21.6771 15.2827 21.6759 16.168C21.6754 17.6148 20.6035 18.5628 19.8559 19.0612C19.4516 19.3307 19.0544 19.5286 18.7622 19.6585C18.6147 19.724 18.4904 19.7738 18.4006 19.808C18.3556 19.8251 18.3191 19.8385 18.2923 19.848L18.2597 19.8594L18.2492 19.863L18.2454 19.8643L18.2439 19.8648C18.2436 19.8649 18.2427 19.8652 17.9264 18.9165L18.2427 19.8652C17.7187 20.0398 17.1524 19.7567 16.9778 19.2327C16.8032 18.7089 17.0861 18.1428 17.6097 17.968L17.6223 17.9635C17.6359 17.9587 17.6584 17.9505 17.6886 17.939C17.7492 17.916 17.8397 17.8798 17.9499 17.8308C18.1733 17.7316 18.4634 17.5858 18.7465 17.3971C19.3734 16.9791 19.6759 16.5527 19.6759 16.167L19.6759 16.1656C19.6765 15.7524 19.5309 15.3524 19.2648 15.0363C18.9987 14.7202 18.6294 14.5085 18.2222 14.4387ZM16.9998 22.5824C16.9998 22.0301 17.4475 21.5824 17.9998 21.5824H18.0089C18.5612 21.5824 19.0089 22.0301 19.0089 22.5824C19.0089 23.1347 18.5612 23.5824 18.0089 23.5824H17.9998C17.4475 23.5824 16.9998 23.1347 16.9998 22.5824Z" fill="#3370FF"/>
</svg>

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@@ -0,0 +1,75 @@
<svg width="422" height="271" viewBox="0 0 422 271" fill="none" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_9985_51151)">
<rect x="1" y="1" width="420" height="269" rx="7.875" fill="#F0F1F6"/>
<g filter="url(#filter0_dd_9985_51151)">
<path d="M43 39C43 35.134 46.134 32 50 32H400C403.866 32 407 35.134 407 39V248C407 251.866 403.866 255 400 255H50C46.134 255 43 251.866 43 248V39Z" fill="white"/>
<g filter="url(#filter1_dd_9985_51151)">
<rect x="104" y="39" width="152" height="81" rx="4.12169" fill="white" shape-rendering="crispEdges"/>
<rect x="104.5" y="39.5" width="151" height="80" rx="3.62169" stroke="#3370FF" shape-rendering="crispEdges"/>
<path d="M117.42 52.74H119.93V51.8H120.88V52.74H123.57V53.65H120.88V54.44H123.19V57.41H120.84C120.76 58.23 120.61 58.88 120.38 59.35C121.34 59.84 122.43 60.11 123.65 60.17L123.42 61.08C122.06 60.99 120.87 60.66 119.84 60.08C119.3 60.59 118.46 60.92 117.32 61.08L116.91 60.22C117.85 60.14 118.55 59.91 119 59.54C118.45 59.13 117.96 58.65 117.52 58.11L118.25 57.61C118.63 58.08 119.06 58.49 119.54 58.83C119.7 58.45 119.82 57.98 119.88 57.41H117.7V54.44H119.93V53.65H117.42V52.74ZM122.3 56.56V55.28H120.88V56.56H122.3ZM119.93 56.56V55.28H118.59V56.56H119.93ZM115.46 55.79C115.19 56.13 114.9 56.47 114.6 56.8L114.29 55.78C115.27 54.62 115.99 53.27 116.45 51.72L117.35 52.14C117.11 52.9 116.8 53.62 116.42 54.32V61.05H115.46V55.79ZM126.312 55.43V56.96H128.612V55.43H126.312ZM126.262 57.84C126.142 59.1 125.772 60.14 125.152 60.96L124.422 60.31C125.022 59.45 125.332 58.36 125.352 57.04V52.14H133.022V59.67C133.022 60.42 132.632 60.8 131.872 60.8H130.722L130.472 59.87C130.862 59.9 131.222 59.92 131.562 59.92C131.882 59.92 132.052 59.72 132.052 59.33V57.84H129.572V60.69H128.612V57.84H126.262ZM132.052 56.96V55.43H129.572V56.96H132.052ZM132.052 54.56V53.06H129.572V54.56H132.052ZM128.612 53.06H126.312V54.56H128.612V53.06ZM137.993 53.87H140.803C141.203 53.2 141.543 52.48 141.843 51.71L142.753 52.03C142.463 52.71 142.133 53.33 141.773 53.87H143.103V57.2H141.773V59.71C141.773 59.91 141.863 60.02 142.043 60.02H142.543C142.663 60.02 142.763 59.95 142.823 59.82C142.903 59.68 142.953 59.27 142.973 58.58L143.823 58.84C143.753 59.82 143.633 60.41 143.463 60.6C143.293 60.78 143.043 60.87 142.703 60.87H141.783C141.173 60.87 140.873 60.54 140.873 59.9V57.2H140.083C139.943 58.96 139.183 60.24 137.793 61.04L137.273 60.23C138.443 59.63 139.093 58.62 139.223 57.2H137.993V53.87ZM142.223 56.34V54.73H138.883V56.34H142.223ZM139.103 51.75C139.453 52.23 139.783 52.76 140.103 53.34L139.303 53.74C138.983 53.15 138.633 52.62 138.263 52.15L139.103 51.75ZM135.843 51.88C136.483 52.37 137.023 52.86 137.473 53.35L136.823 54.01C136.433 53.55 135.883 53.05 135.173 52.53L135.843 51.88ZM134.483 54.78H136.793V58.99C137.073 58.74 137.363 58.46 137.673 58.15L137.923 59.15C137.323 59.74 136.673 60.27 135.993 60.73L135.633 59.88C135.793 59.72 135.883 59.53 135.883 59.31V55.69H134.483V54.78ZM148.075 52.29V59.39H145.855V60.14H144.905V52.29H148.075ZM145.855 58.46H147.155V56.23H145.855V58.46ZM145.855 55.31H147.155V53.22H145.855V55.31ZM149.965 55.39V56.9H152.315V55.39H149.965ZM152.315 54.5V52.98H149.965V54.5H152.315ZM149.905 57.79C149.765 59.12 149.345 60.23 148.665 61.11L147.915 60.41C148.625 59.49 148.985 58.32 149.005 56.9V52.07H153.285V59.91C153.285 60.59 152.935 60.94 152.245 60.94H150.965L150.705 60.01C151.145 60.03 151.555 60.05 151.935 60.05C152.185 60.05 152.315 59.89 152.315 59.57V57.79H149.905Z" fill="#111824"/>
<rect x="114" y="70" width="132" height="6" rx="3" fill="#E8EBF0"/>
<rect x="114" y="84" width="132" height="6" rx="3" fill="#E8EBF0"/>
<rect x="114" y="98" width="57" height="6" rx="3" fill="#E8EBF0"/>
</g>
<rect x="48" y="41" width="12.1004" height="12.1004" rx="2.52022" fill="url(#paint0_linear_9985_51151)"/>
<rect x="50.9004" y="43.8997" width="6.30054" height="6.30054" rx="1.26011" fill="white" fill-opacity="0.7"/>
<rect x="63.3018" y="44.5066" width="21.1964" height="5.08714" rx="2.54357" fill="#F0F1F6"/>
<rect x="104" y="137.5" width="108.779" height="6" rx="3" fill="#F0F1F6"/>
<rect x="104" y="155.465" width="78.3717" height="6" rx="3" fill="#F0F1F6"/>
<rect x="275.502" y="49.0444" width="34.1455" height="6" rx="3" fill="#F0F1F6"/>
<rect x="276" y="67" width="117" height="53" rx="2" fill="#F4F4F7"/>
<rect x="276" y="132" width="117" height="103" rx="2" fill="#F4F4F7"/>
</g>
<mask id="path-18-inside-1_9985_51151" fill="white">
<path d="M0.290039 11.3545C0.290039 5.5555 4.99105 0.854492 10.79 0.854492H412.133C417.932 0.854492 422.633 5.5555 422.633 11.3545V20.7646H0.290039V11.3545Z"/>
</mask>
<path d="M0.290039 11.3545C0.290039 5.5555 4.99105 0.854492 10.79 0.854492H412.133C417.932 0.854492 422.633 5.5555 422.633 11.3545V20.7646H0.290039V11.3545Z" fill="#F0F1F6"/>
<path d="M0.290039 0.854492H422.633H0.290039ZM422.633 21.4208H0.290039V20.1083H422.633V21.4208ZM0.290039 20.7646V0.854492V20.7646ZM422.633 0.854492V20.7646V0.854492Z" fill="#DFE2EA" mask="url(#path-18-inside-1_9985_51151)"/>
<circle cx="17.4031" cy="11.6514" r="3.64527" fill="#C4CBD7"/>
<circle cx="31.9841" cy="11.6514" r="3.64527" fill="#C4CBD7"/>
<circle cx="46.5652" cy="11.6514" r="3.64527" fill="#C4CBD7"/>
<line x1="97.5" y1="32" x2="97.5" y2="255" stroke="#E8EBF0"/>
<line x1="262.5" y1="32" x2="262.5" y2="255" stroke="#E8EBF0"/>
<rect x="6.80469" y="39.728" width="28.4873" height="5.08714" rx="2.54357" fill="#DFE2EA"/>
<rect x="6.80469" y="54.3721" width="13.9062" height="5.08714" rx="2.54357" fill="#DFE2EA"/>
</g>
<rect x="0.5" y="0.5" width="421" height="270" rx="8.375" stroke="#E8EBF0"/>
<defs>
<filter id="filter0_dd_9985_51151" x="39" y="31" width="372" height="232" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
<feFlood flood-opacity="0" result="BackgroundImageFix"/>
<feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0" result="hardAlpha"/>
<feOffset/>
<feGaussianBlur stdDeviation="0.5"/>
<feColorMatrix type="matrix" values="0 0 0 0 0.0745098 0 0 0 0 0.2 0 0 0 0 0.419608 0 0 0 0.08 0"/>
<feBlend mode="normal" in2="BackgroundImageFix" result="effect1_dropShadow_9985_51151"/>
<feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0" result="hardAlpha"/>
<feOffset dy="4"/>
<feGaussianBlur stdDeviation="2"/>
<feColorMatrix type="matrix" values="0 0 0 0 0.0745098 0 0 0 0 0.2 0 0 0 0 0.419608 0 0 0 0.05 0"/>
<feBlend mode="normal" in2="effect1_dropShadow_9985_51151" result="effect2_dropShadow_9985_51151"/>
<feBlend mode="normal" in="SourceGraphic" in2="effect2_dropShadow_9985_51151" result="shape"/>
</filter>
<filter id="filter1_dd_9985_51151" x="94" y="33" width="172" height="101" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
<feFlood flood-opacity="0" result="BackgroundImageFix"/>
<feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0" result="hardAlpha"/>
<feOffset/>
<feGaussianBlur stdDeviation="0.5"/>
<feComposite in2="hardAlpha" operator="out"/>
<feColorMatrix type="matrix" values="0 0 0 0 0.0745098 0 0 0 0 0.2 0 0 0 0 0.419608 0 0 0 0.08 0"/>
<feBlend mode="normal" in2="BackgroundImageFix" result="effect1_dropShadow_9985_51151"/>
<feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0" result="hardAlpha"/>
<feOffset dy="4"/>
<feGaussianBlur stdDeviation="5"/>
<feColorMatrix type="matrix" values="0 0 0 0 0.0745098 0 0 0 0 0.2 0 0 0 0 0.419608 0 0 0 0.08 0"/>
<feBlend mode="normal" in2="effect1_dropShadow_9985_51151" result="effect2_dropShadow_9985_51151"/>
<feBlend mode="normal" in="SourceGraphic" in2="effect2_dropShadow_9985_51151" result="shape"/>
</filter>
<linearGradient id="paint0_linear_9985_51151" x1="54.0502" y1="41" x2="49.8487" y2="52.0921" gradientUnits="userSpaceOnUse">
<stop stop-color="#61D2C4"/>
<stop offset="1" stop-color="#40CAA1"/>
</linearGradient>
<clipPath id="clip0_9985_51151">
<rect x="1" y="1" width="420" height="269" rx="7.875" fill="white"/>
</clipPath>
</defs>
</svg>

After

Width:  |  Height:  |  Size: 7.8 KiB

View File

@@ -11,18 +11,18 @@ enum FnTypeEnum {
variable = 'variable',
welcome = 'welcome',
file = 'file',
visionModel = 'visionModel'
visionModel = 'visionModel',
instruction = 'instruction'
}
const ChatFunctionTip = ({ type }: { type: `${FnTypeEnum}` }) => {
const { t } = useTranslation();
const { chatT } = useI18n();
const map = useRef({
[FnTypeEnum.inputGuide]: {
icon: '/imgs/app/inputGuide-icon.svg',
title: chatT('input_guide'),
desc: chatT('input_guide_tip'),
title: t('chat:input_guide'),
desc: t('chat:input_guide_tip'),
imgUrl: '/imgs/app/inputGuide.svg'
},
[FnTypeEnum.nextQuestion]: {
@@ -60,6 +60,12 @@ const ChatFunctionTip = ({ type }: { type: `${FnTypeEnum}` }) => {
title: t('app:vision_model_title'),
desc: t('app:llm_use_vision_tip'),
imgUrl: '/imgs/app/visionModel.png'
},
[FnTypeEnum.instruction]: {
icon: '/imgs/app/help.svg',
title: t('workflow:plugin.Instructions'),
desc: t('workflow:plugin.Instruction_Tip'),
imgUrl: '/imgs/app/instruction.svg'
}
});
const data = map.current[type];

View File

@@ -1,16 +1,26 @@
import React, { useEffect, useMemo } from 'react';
import { Controller } from 'react-hook-form';
import RenderPluginInput from './renderPluginInput';
import { Button, Flex } from '@chakra-ui/react';
import { Box, Button, Flex } from '@chakra-ui/react';
import { useTranslation } from 'next-i18next';
import { useContextSelector } from 'use-context-selector';
import { PluginRunContext } from '../context';
import { WorkflowIOValueTypeEnum } from '@fastgpt/global/core/workflow/constants';
import { isEqual } from 'lodash';
import { AppChatConfigType } from '@fastgpt/global/core/app/type';
import Markdown from '@/components/Markdown';
const RenderInput = () => {
const { pluginInputs, variablesForm, histories, onStartChat, onNewChat, onSubmit, isChatting } =
useContextSelector(PluginRunContext, (v) => v);
const {
pluginInputs,
variablesForm,
histories,
onStartChat,
onNewChat,
onSubmit,
isChatting,
chatConfig
} = useContextSelector(PluginRunContext, (v) => v);
const { t } = useTranslation();
const {
@@ -64,6 +74,20 @@ const RenderInput = () => {
return (
<>
{/* instruction */}
{chatConfig?.instruction && (
<Box
border={'1px solid'}
borderColor={'myGray.250'}
p={4}
rounded={'md'}
fontSize={'sm'}
color={'myGray.600'}
>
<Markdown source={chatConfig.instruction} />
</Box>
)}
{pluginInputs.map((input) => {
return (
<Controller

View File

@@ -19,4 +19,5 @@ export type PluginRunBoxProps = OutLinkChatAuthProps & {
chatId?: string;
tab: PluginRunBoxTabEnum;
setTab: React.Dispatch<React.SetStateAction<PluginRunBoxTabEnum>>;
chatConfig?: AppChatConfigType;
};

View File

@@ -28,6 +28,7 @@ const nodeTypes: Record<FlowNodeTypeEnum, any> = {
[FlowNodeTypeEnum.textEditor]: NodeSimple,
[FlowNodeTypeEnum.customFeedback]: NodeSimple,
[FlowNodeTypeEnum.systemConfig]: dynamic(() => import('./nodes/NodeSystemConfig')),
[FlowNodeTypeEnum.pluginConfig]: dynamic(() => import('./nodes/NodePluginIO/NodePluginConfig')),
[FlowNodeTypeEnum.workflowStart]: dynamic(() => import('./nodes/NodeWorkflowStart')),
[FlowNodeTypeEnum.chatNode]: NodeSimple,
[FlowNodeTypeEnum.readFiles]: NodeSimple,

View File

@@ -0,0 +1,103 @@
import React, { Dispatch, useMemo, useState } from 'react';
import { NodeProps } from 'reactflow';
import NodeCard from '../render/NodeCard';
import { FlowNodeItemType } from '@fastgpt/global/core/workflow/type/node.d';
import { Box, Flex } from '@chakra-ui/react';
import Container from '../../components/Container';
import { useTranslation } from 'next-i18next';
import { useContextSelector } from 'use-context-selector';
import MyTextarea from '@/components/common/Textarea/MyTextarea';
import { AppContext } from '../../../../context';
import { AppChatConfigType, AppDetailType } from '@fastgpt/global/core/app/type';
import { getAppChatConfig } from '@fastgpt/global/core/workflow/utils';
import { useCreation } from 'ahooks';
import ChatFunctionTip from '@/components/core/app/Tip';
import FormLabel from '@fastgpt/web/components/common/MyBox/FormLabel';
type ComponentProps = {
chatConfig: AppChatConfigType;
setAppDetail: Dispatch<React.SetStateAction<AppDetailType>>;
};
const NodePluginConfig = ({ data, selected }: NodeProps<FlowNodeItemType>) => {
const { appDetail, setAppDetail } = useContextSelector(AppContext, (v) => v);
const chatConfig = useMemo<AppChatConfigType>(() => {
return getAppChatConfig({
chatConfig: appDetail.chatConfig,
systemConfigNode: data,
isPublicFetch: true
});
}, [data, appDetail]);
useCreation(() => {
setAppDetail((state) => ({
...state,
chatConfig: {
...state.chatConfig,
...chatConfig
}
}));
}, []);
const componentsProps = useMemo(
() => ({
chatConfig,
setAppDetail
}),
[chatConfig, setAppDetail]
);
return (
<NodeCard
selected={selected}
menuForbid={{
debug: true,
rename: true,
copy: true,
delete: true
}}
{...data}
>
<Container w={'360px'}>
<Instruction {...componentsProps} />
</Container>
</NodeCard>
);
};
export default React.memo(NodePluginConfig);
function Instruction({ chatConfig: { instruction }, setAppDetail }: ComponentProps) {
const { t } = useTranslation();
return (
<>
<Flex>
<FormLabel color={'myGray.600'} fontWeight={'medium'} fontSize={'14px'}>
{t('workflow:plugin.Instructions')}
</FormLabel>
<ChatFunctionTip type={'instruction'} />
</Flex>
<MyTextarea
iconSrc={'core/app/simpleMode/chat'}
title={t('workflow:plugin.Instructions')}
mt={2}
rows={6}
fontSize={'14px'}
bg={'white'}
resize={'both'}
placeholder={t('workflow:plugin.Instruction_Tip')}
value={instruction}
onChange={(e) => {
setAppDetail((state) => ({
...state,
chatConfig: {
...state.chatConfig,
instruction: e.target.value
}
}));
}}
/>
</>
);
}

View File

@@ -77,6 +77,7 @@ export const useChatTest = ({
histories={chatRecords}
setHistories={setChatRecords}
appId={appDetail._id}
chatConfig={appDetail.chatConfig}
tab={pluginRunTab}
setTab={setPluginRunTab}
onNewChat={clearChatRecords}

View File

@@ -240,6 +240,7 @@ const Chat = ({
histories={chatRecords}
setHistories={setChatRecords}
appId={chatData.appId}
chatConfig={chatData.app.chatConfig}
tab={pluginRunTab}
setTab={setPluginRunTab}
onNewChat={() => onChangeChatId(getNanoid())}

View File

@@ -260,6 +260,7 @@ export const checkWorkflowNodeAndConnection = ({
if (
data.flowNodeType === FlowNodeTypeEnum.systemConfig ||
data.flowNodeType === FlowNodeTypeEnum.pluginConfig ||
data.flowNodeType === FlowNodeTypeEnum.pluginInput ||
data.flowNodeType === FlowNodeTypeEnum.workflowStart
) {
@@ -554,7 +555,8 @@ export const compareSnapshot = (
whisperConfig: clone1.chatConfig?.whisperConfig || undefined,
scheduledTriggerConfig: clone1.chatConfig?.scheduledTriggerConfig || undefined,
chatInputGuide: clone1.chatConfig?.chatInputGuide || undefined,
fileSelectConfig: clone1.chatConfig?.fileSelectConfig || undefined
fileSelectConfig: clone1.chatConfig?.fileSelectConfig || undefined,
instruction: clone1.chatConfig?.instruction || ''
},
{
welcomeText: clone2.chatConfig?.welcomeText || '',
@@ -564,7 +566,8 @@ export const compareSnapshot = (
whisperConfig: clone2.chatConfig?.whisperConfig || undefined,
scheduledTriggerConfig: clone2.chatConfig?.scheduledTriggerConfig || undefined,
chatInputGuide: clone2.chatConfig?.chatInputGuide || undefined,
fileSelectConfig: clone2.chatConfig?.fileSelectConfig || undefined
fileSelectConfig: clone2.chatConfig?.fileSelectConfig || undefined,
instruction: clone2.chatConfig?.instruction || ''
}
)
) {