index.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. ? (
  41. <Select
  42. className='w-full'
  43. defaultValue={inputs[item.key]}
  44. onSelect={(i) => { onInputsChange({ ...inputs, [item.key]: i.value }) }}
  45. items={(item.options || []).map(i => ({ name: i, value: i }))}
  46. allowSearch={false}
  47. bgClassName='bg-gray-50'
  48. />
  49. )
  50. : (
  51. <input
  52. type="text"
  53. 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 "
  54. placeholder={`${item.name}${!item.required ? `(${t('appDebug.variableTable.optional')})` : ''}`}
  55. value={inputs[item.key]}
  56. onChange={(e) => { onInputsChange({ ...inputs, [item.key]: e.target.value }) }}
  57. maxLength={item.max_length || DEFAULT_VALUE_MAX_LEN}
  58. />
  59. )}
  60. </div>
  61. </div>
  62. ))}
  63. {promptConfig.prompt_variables.length > 0 && (
  64. <div className='mt-6 h-[1px] bg-gray-100'></div>
  65. )}
  66. <div className='w-full mt-5'>
  67. <label className='text-gray-900 text-sm font-medium'>{t('share.generation.queryTitle')}</label>
  68. <div className="mt-2 overflow-hidden rounded-lg bg-gray-50 ">
  69. <div className="px-4 py-2 bg-gray-50 rounded-t-lg">
  70. <textarea
  71. value={query}
  72. onChange={(e) => { onQueryChange(e.target.value) }}
  73. rows={4}
  74. className="w-full px-0 text-sm text-gray-900 border-0 bg-gray-50 focus:outline-none placeholder:bg-gray-50"
  75. placeholder={t('share.generation.queryPlaceholder') as string}
  76. required
  77. >
  78. </textarea>
  79. </div>
  80. <div className="flex items-center justify-between px-3 py-2">
  81. <div className="flex pl-0 space-x-1 sm:pl-2">
  82. <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>
  83. </div>
  84. <Button
  85. type="primary"
  86. className='w-[80px] !h-8'
  87. onClick={onSend}
  88. disabled={!query || query === ''}
  89. >
  90. <PlayIcon className="shrink-0 w-4 h-4 mr-1" aria-hidden="true" />
  91. <span className='uppercase text-[13px]'>{t('share.generation.run')}</span>
  92. </Button>
  93. </div>
  94. </div>
  95. </div>
  96. </form>
  97. </section>
  98. </div>
  99. )
  100. }
  101. export default React.memo(ConfigSence)