prompt-generator-btn.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React, { useCallback } from 'react'
  4. import { useBoolean } from 'ahooks'
  5. import cn from 'classnames'
  6. import { Generator } from '@/app/components/base/icons/src/vender/other'
  7. import { ActionButton } from '@/app/components/base/action-button'
  8. import GetAutomaticResModal from '@/app/components/app/configuration/config/automatic/get-automatic-res'
  9. import { AppType } from '@/types/app'
  10. import type { AutomaticRes } from '@/service/debug'
  11. import type { ModelConfig } from '@/app/components/workflow/types'
  12. import type { Model } from '@/types/app'
  13. type Props = {
  14. className?: string
  15. onGenerated?: (prompt: string) => void
  16. modelConfig?: ModelConfig
  17. }
  18. const PromptGeneratorBtn: FC<Props> = ({
  19. className,
  20. onGenerated,
  21. modelConfig,
  22. }) => {
  23. const [showAutomatic, { setTrue: showAutomaticTrue, setFalse: showAutomaticFalse }] = useBoolean(false)
  24. const handleAutomaticRes = useCallback((res: AutomaticRes) => {
  25. onGenerated?.(res.prompt)
  26. showAutomaticFalse()
  27. }, [onGenerated, showAutomaticFalse])
  28. return (
  29. <div className={cn(className)}>
  30. <ActionButton
  31. className='hover:bg-[#155EFF]/8'
  32. onClick={showAutomaticTrue}>
  33. <Generator className='w-4 h-4 text-primary-600' />
  34. </ActionButton>
  35. {showAutomatic && (
  36. <GetAutomaticResModal
  37. mode={AppType.chat}
  38. isShow={showAutomatic}
  39. onClose={showAutomaticFalse}
  40. onFinished={handleAutomaticRes}
  41. model={modelConfig as Model}
  42. isInLLMNode
  43. />
  44. )}
  45. </div>
  46. )
  47. }
  48. export default React.memo(PromptGeneratorBtn)