您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

index.tsx 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import React from 'react'
  2. import { useTranslation } from 'react-i18next'
  3. import { RiCloseLine, RiInformation2Fill } from '@remixicon/react'
  4. import DialogWrapper from '@/app/components/base/features/new-feature-panel/dialog-wrapper'
  5. import { useDefaultModel } from '@/app/components/header/account-setting/model-provider-page/hooks'
  6. import { ModelTypeEnum } from '@/app/components/header/account-setting/model-provider-page/declarations'
  7. import type { OnFeaturesChange } from '@/app/components/base/features/types'
  8. import MoreLikeThis from '@/app/components/base/features/new-feature-panel/more-like-this'
  9. import ConversationOpener from '@/app/components/base/features/new-feature-panel/conversation-opener'
  10. import FollowUp from '@/app/components/base/features/new-feature-panel/follow-up'
  11. import SpeechToText from '@/app/components/base/features/new-feature-panel/speech-to-text'
  12. import TextToSpeech from '@/app/components/base/features/new-feature-panel/text-to-speech'
  13. import FileUpload from '@/app/components/base/features/new-feature-panel/file-upload'
  14. import Citation from '@/app/components/base/features/new-feature-panel/citation'
  15. import ImageUpload from '@/app/components/base/features/new-feature-panel/image-upload'
  16. import Moderation from '@/app/components/base/features/new-feature-panel/moderation'
  17. import AnnotationReply from '@/app/components/base/features/new-feature-panel/annotation-reply'
  18. import type { PromptVariable } from '@/models/debug'
  19. import type { InputVar } from '@/app/components/workflow/types'
  20. import { useDocLink } from '@/context/i18n'
  21. type Props = {
  22. show: boolean
  23. isChatMode: boolean
  24. disabled: boolean
  25. onChange?: OnFeaturesChange
  26. onClose: () => void
  27. inWorkflow?: boolean
  28. showFileUpload?: boolean
  29. promptVariables?: PromptVariable[]
  30. workflowVariables?: InputVar[]
  31. onAutoAddPromptVariable?: (variable: PromptVariable[]) => void
  32. }
  33. const NewFeaturePanel = ({
  34. show,
  35. isChatMode,
  36. disabled,
  37. onChange,
  38. onClose,
  39. inWorkflow = true,
  40. showFileUpload = true,
  41. promptVariables,
  42. workflowVariables,
  43. onAutoAddPromptVariable,
  44. }: Props) => {
  45. const { t } = useTranslation()
  46. const docLink = useDocLink()
  47. const { data: speech2textDefaultModel } = useDefaultModel(ModelTypeEnum.speech2text)
  48. const { data: text2speechDefaultModel } = useDefaultModel(ModelTypeEnum.tts)
  49. return (
  50. <DialogWrapper
  51. show={show}
  52. onClose={onClose}
  53. inWorkflow={inWorkflow}
  54. >
  55. <div className='flex h-full grow flex-col'>
  56. {/* header */}
  57. <div className='flex shrink-0 justify-between p-4 pb-3'>
  58. <div>
  59. <div className='system-xl-semibold text-text-primary'>{t('workflow.common.features')}</div>
  60. <div className='body-xs-regular text-text-tertiary'>{t('workflow.common.featuresDescription')}</div>
  61. </div>
  62. <div className='h-8 w-8 cursor-pointer p-2' onClick={onClose}><RiCloseLine className='h-4 w-4 text-text-tertiary'/></div>
  63. </div>
  64. {/* list */}
  65. <div className='grow basis-0 overflow-y-auto px-4 pb-4'>
  66. {showFileUpload && (
  67. <div className='relative mb-1 rounded-xl border border-components-panel-border p-2 shadow-xs'>
  68. <div className='absolute left-0 top-0 h-full w-full rounded-xl opacity-40' style={{ background: 'linear-gradient(92deg, rgba(11, 165, 236, 0.25) 18.12%, rgba(255, 255, 255, 0.00) 167.31%)' }}></div>
  69. <div className='relative flex h-full w-full items-start'>
  70. <div className='mr-0.5 shrink-0 p-0.5'>
  71. <RiInformation2Fill className='h-5 w-5 text-text-accent' />
  72. </div>
  73. <div className='system-xs-medium p-1 text-text-primary'>
  74. <span>{isChatMode ? t('workflow.common.fileUploadTip') : t('workflow.common.ImageUploadLegacyTip')}</span>
  75. <a
  76. className='text-text-accent'
  77. href={docLink('/guides/workflow/bulletin')}
  78. target='_blank' rel='noopener noreferrer'
  79. >{t('workflow.common.featuresDocLink')}</a>
  80. </div>
  81. </div>
  82. </div>
  83. )}
  84. {!isChatMode && !inWorkflow && (
  85. <MoreLikeThis disabled={disabled} onChange={onChange} />
  86. )}
  87. {isChatMode && (
  88. <ConversationOpener
  89. disabled={disabled}
  90. onChange={onChange}
  91. promptVariables={promptVariables}
  92. workflowVariables={workflowVariables}
  93. onAutoAddPromptVariable={onAutoAddPromptVariable}
  94. />
  95. )}
  96. {isChatMode && (
  97. <FollowUp disabled={disabled} onChange={onChange} />
  98. )}
  99. {text2speechDefaultModel && (isChatMode || !inWorkflow) && (
  100. <TextToSpeech disabled={disabled} onChange={onChange} />
  101. )}
  102. {isChatMode && speech2textDefaultModel && (
  103. <SpeechToText disabled={disabled} onChange={onChange} />
  104. )}
  105. {showFileUpload && isChatMode && <FileUpload disabled={disabled} onChange={onChange} />}
  106. {showFileUpload && !isChatMode && <ImageUpload disabled={disabled} onChange={onChange} />}
  107. {isChatMode && (
  108. <Citation disabled={disabled} onChange={onChange} />
  109. )}
  110. {(isChatMode || !inWorkflow) && <Moderation disabled={disabled} onChange={onChange} />}
  111. {!inWorkflow && isChatMode && (
  112. <AnnotationReply disabled={disabled} onChange={onChange} />
  113. )}
  114. </div>
  115. </div>
  116. </DialogWrapper>
  117. )
  118. }
  119. export default NewFeaturePanel