You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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