panel.tsx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. import type { FC } from 'react'
  2. import React from 'react'
  3. import { useTranslation } from 'react-i18next'
  4. import VarReferencePicker from '../_base/components/variable/var-reference-picker'
  5. import ConfigVision from '../_base/components/config-vision'
  6. import useConfig from './use-config'
  7. import ClassList from './components/class-list'
  8. import AdvancedSetting from './components/advanced-setting'
  9. import type { QuestionClassifierNodeType } from './types'
  10. import Field from '@/app/components/workflow/nodes/_base/components/field'
  11. import ModelParameterModal from '@/app/components/header/account-setting/model-provider-page/model-parameter-modal'
  12. import { InputVarType, type NodePanelProps } from '@/app/components/workflow/types'
  13. import BeforeRunForm from '@/app/components/workflow/nodes/_base/components/before-run-form'
  14. import ResultPanel from '@/app/components/workflow/run/result-panel'
  15. import Split from '@/app/components/workflow/nodes/_base/components/split'
  16. import OutputVars, { VarItem } from '@/app/components/workflow/nodes/_base/components/output-vars'
  17. const i18nPrefix = 'workflow.nodes.questionClassifiers'
  18. const Panel: FC<NodePanelProps<QuestionClassifierNodeType>> = ({
  19. id,
  20. data,
  21. }) => {
  22. const { t } = useTranslation()
  23. const {
  24. readOnly,
  25. inputs,
  26. handleModelChanged,
  27. isChatMode,
  28. isChatModel,
  29. handleCompletionParamsChange,
  30. handleQueryVarChange,
  31. handleTopicsChange,
  32. hasSetBlockStatus,
  33. availableVars,
  34. availableNodesWithParent,
  35. handleInstructionChange,
  36. inputVarValues,
  37. varInputs,
  38. setInputVarValues,
  39. handleMemoryChange,
  40. isVisionModel,
  41. handleVisionResolutionChange,
  42. handleVisionResolutionEnabledChange,
  43. isShowSingleRun,
  44. hideSingleRun,
  45. runningStatus,
  46. handleRun,
  47. handleStop,
  48. runResult,
  49. filterVar,
  50. } = useConfig(id, data)
  51. const model = inputs.model
  52. return (
  53. <div className='mt-2'>
  54. <div className='px-4 pb-4 space-y-4'>
  55. <Field
  56. title={t(`${i18nPrefix}.model`)}
  57. >
  58. <ModelParameterModal
  59. popupClassName='!w-[387px]'
  60. isInWorkflow
  61. isAdvancedMode={true}
  62. mode={model?.mode}
  63. provider={model?.provider}
  64. completionParams={model.completion_params}
  65. modelId={model.name}
  66. setModel={handleModelChanged}
  67. onCompletionParamsChange={handleCompletionParamsChange}
  68. hideDebugWithMultipleModel
  69. debugWithMultipleModel={false}
  70. readonly={readOnly}
  71. />
  72. </Field>
  73. <Field
  74. title={t(`${i18nPrefix}.inputVars`)}
  75. >
  76. <VarReferencePicker
  77. readonly={readOnly}
  78. isShowNodeName
  79. nodeId={id}
  80. value={inputs.query_variable_selector}
  81. onChange={handleQueryVarChange}
  82. filterVar={filterVar}
  83. />
  84. </Field>
  85. <Split />
  86. <ConfigVision
  87. nodeId={id}
  88. readOnly={readOnly}
  89. isVisionModel={isVisionModel}
  90. enabled={inputs.vision?.enabled}
  91. onEnabledChange={handleVisionResolutionEnabledChange}
  92. config={inputs.vision?.configs}
  93. onConfigChange={handleVisionResolutionChange}
  94. />
  95. <Field
  96. title={t(`${i18nPrefix}.class`)}
  97. >
  98. <ClassList
  99. id={id}
  100. list={inputs.classes}
  101. onChange={handleTopicsChange}
  102. readonly={readOnly}
  103. />
  104. </Field>
  105. <Field
  106. title={t(`${i18nPrefix}.advancedSetting`)}
  107. supportFold
  108. >
  109. <AdvancedSetting
  110. hideMemorySetting={!isChatMode}
  111. instruction={inputs.instruction}
  112. onInstructionChange={handleInstructionChange}
  113. memory={inputs.memory}
  114. onMemoryChange={handleMemoryChange}
  115. readonly={readOnly}
  116. isChatApp={isChatMode}
  117. isChatModel={isChatModel}
  118. hasSetBlockStatus={hasSetBlockStatus}
  119. nodesOutputVars={availableVars}
  120. availableNodes={availableNodesWithParent}
  121. />
  122. </Field>
  123. </div>
  124. <Split />
  125. <div className='px-4 pt-4 pb-2'>
  126. <OutputVars>
  127. <>
  128. <VarItem
  129. name='class_name'
  130. type='string'
  131. description={t(`${i18nPrefix}.outputVars.className`)}
  132. />
  133. </>
  134. </OutputVars>
  135. </div>
  136. {isShowSingleRun && (
  137. <BeforeRunForm
  138. nodeName={inputs.title}
  139. onHide={hideSingleRun}
  140. forms={[
  141. {
  142. inputs: [{
  143. label: t(`${i18nPrefix}.inputVars`)!,
  144. variable: 'query',
  145. type: InputVarType.paragraph,
  146. required: true,
  147. }, ...varInputs],
  148. values: inputVarValues,
  149. onChange: setInputVarValues,
  150. },
  151. ]}
  152. runningStatus={runningStatus}
  153. onRun={handleRun}
  154. onStop={handleStop}
  155. result={<ResultPanel {...runResult} showSteps={false} />}
  156. />
  157. )}
  158. </div>
  159. )
  160. }
  161. export default React.memo(Panel)