reasoning-mode-picker.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React, { useCallback } from 'react'
  4. import { useTranslation } from 'react-i18next'
  5. import { ReasoningModeType } from '../types'
  6. import Field from '../../_base/components/field'
  7. import cn from '@/utils/classnames'
  8. const i18nPrefix = 'workflow.nodes.parameterExtractor'
  9. type ItemProps = {
  10. isChosen: boolean
  11. text: string
  12. onClick: () => void
  13. }
  14. const Item: FC<ItemProps> = ({
  15. isChosen,
  16. text,
  17. onClick,
  18. }) => {
  19. return (
  20. <div
  21. className={cn(isChosen ? 'border-[1.5px] border-primary-400 bg-white' : 'border border-gray-100 bg-gray-25', 'grow w-0 shrink-0 flex items-center h-8 justify-center rounded-lg cursor-pointer text-[13px] font-normal text-gray-900')}
  22. onClick={() => !isChosen ? onClick() : () => { }}
  23. >
  24. {text}
  25. </div>
  26. )
  27. }
  28. type Props = {
  29. type: ReasoningModeType
  30. onChange: (type: ReasoningModeType) => void
  31. }
  32. const ReasoningModePicker: FC<Props> = ({
  33. type,
  34. onChange,
  35. }) => {
  36. const { t } = useTranslation()
  37. const handleChange = useCallback((type: ReasoningModeType) => {
  38. return () => {
  39. onChange(type)
  40. }
  41. }, [onChange])
  42. return (
  43. <Field
  44. title={t(`${i18nPrefix}.reasoningMode`)}
  45. tooltip={t(`${i18nPrefix}.reasoningModeTip`)!}
  46. >
  47. <div className='flex space-x-1'>
  48. <Item
  49. isChosen={type === ReasoningModeType.functionCall}
  50. text='Function/Tool Calling'
  51. onClick={handleChange(ReasoningModeType.functionCall)}
  52. />
  53. <Item
  54. isChosen={type === ReasoningModeType.prompt}
  55. text='Prompt'
  56. onClick={handleChange(ReasoningModeType.prompt)}
  57. />
  58. </div>
  59. </Field>
  60. )
  61. }
  62. export default React.memo(ReasoningModePicker)