index.tsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import type { FC } from 'react'
  2. import React from 'react'
  3. import { useTranslation } from 'react-i18next'
  4. import {
  5. PlayIcon,
  6. } from '@heroicons/react/24/solid'
  7. import Select from '@/app/components/base/select'
  8. import type { SiteInfo } from '@/models/share'
  9. import type { PromptConfig } from '@/models/debug'
  10. import Button from '@/app/components/base/button'
  11. import { DEFAULT_VALUE_MAX_LEN } from '@/config'
  12. export type IConfigSenceProps = {
  13. siteInfo: SiteInfo
  14. promptConfig: PromptConfig
  15. inputs: Record<string, any>
  16. onInputsChange: (inputs: Record<string, any>) => void
  17. query: string
  18. onQueryChange: (query: string) => void
  19. onSend: () => void
  20. }
  21. const ConfigSence: FC<IConfigSenceProps> = ({
  22. promptConfig,
  23. inputs,
  24. onInputsChange,
  25. query,
  26. onQueryChange,
  27. onSend,
  28. }) => {
  29. const { t } = useTranslation()
  30. return (
  31. <div className="">
  32. <section>
  33. {/* input form */}
  34. <form>
  35. {promptConfig.prompt_variables.map(item => (
  36. <div className='w-full mt-4' key={item.key}>
  37. <label className='text-gray-900 text-sm font-medium'>{item.name}</label>
  38. <div className='mt-2'>
  39. {item.type === 'select' ? (
  40. <Select
  41. className='w-full'
  42. defaultValue={inputs[item.key]}
  43. onSelect={(i) => { onInputsChange({ ...inputs, [item.key]: i.value }) }}
  44. items={(item.options || []).map(i => ({ name: i, value: i }))}
  45. allowSearch={false}
  46. bgClassName='bg-gray-50'
  47. />
  48. ) : (
  49. <input
  50. type="text"
  51. className="block w-full p-2 text-gray-900 border border-gray-300 rounded-lg bg-gray-50 sm:text-xs focus:ring-blue-500 focus:border-blue-500 "
  52. placeholder={`${item.name}${!item.required ? `(${t('appDebug.variableTable.optional')})` : ''}`}
  53. value={inputs[item.key]}
  54. onChange={(e) => { onInputsChange({ ...inputs, [item.key]: e.target.value }) }}
  55. maxLength={item.max_length || DEFAULT_VALUE_MAX_LEN}
  56. />
  57. )}
  58. </div>
  59. </div>
  60. ))}
  61. {promptConfig.prompt_variables.length > 0 && (
  62. <div className='mt-6 h-[1px] bg-gray-100'></div>
  63. )}
  64. <div className='w-full mt-5'>
  65. <label className='text-gray-900 text-sm font-medium'>{t('share.generation.queryTitle')}</label>
  66. <div className="mt-2 overflow-hidden rounded-lg bg-gray-50 ">
  67. <div className="px-4 py-2 bg-gray-50 rounded-t-lg">
  68. <textarea
  69. value={query}
  70. onChange={(e) => { onQueryChange(e.target.value) }}
  71. rows={4}
  72. className="w-full px-0 text-sm text-gray-900 border-0 bg-gray-50 focus:outline-none placeholder:bg-gray-50"
  73. placeholder={t('share.generation.queryPlaceholder') as string}
  74. required
  75. >
  76. </textarea>
  77. </div>
  78. <div className="flex items-center justify-between px-3 py-2">
  79. <div className="flex pl-0 space-x-1 sm:pl-2">
  80. <span className="bg-gray-100 text-gray-500 text-xs font-medium mr-2 px-2.5 py-0.5 rounded cursor-pointer">{query?.length}</span>
  81. </div>
  82. <Button
  83. type="primary"
  84. className='w-[80px] !h-8'
  85. onClick={onSend}
  86. disabled={!query || query === ''}
  87. >
  88. <PlayIcon className="shrink-0 w-4 h-4 mr-1" aria-hidden="true" />
  89. <span className='uppercase text-[13px]'>{t('share.generation.run')}</span>
  90. </Button>
  91. </div>
  92. </div>
  93. </div>
  94. </form>
  95. </section>
  96. </div>
  97. )
  98. }
  99. export default React.memo(ConfigSence)