You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.tsx 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React, { useState } from 'react'
  4. import { useTranslation } from 'react-i18next'
  5. import { RiCloseLine } from '@remixicon/react'
  6. import ItemPanel from './item-panel'
  7. import Button from '@/app/components/base/button'
  8. import { CuteRobote } from '@/app/components/base/icons/src/vender/solid/communication'
  9. import { Unblur } from '@/app/components/base/icons/src/vender/solid/education'
  10. import Slider from '@/app/components/base/slider'
  11. import type { AgentConfig } from '@/models/debug'
  12. import { DEFAULT_AGENT_PROMPT } from '@/config'
  13. type Props = {
  14. isChatModel: boolean
  15. payload: AgentConfig
  16. isFunctionCall: boolean
  17. onCancel: () => void
  18. onSave: (payload: any) => void
  19. }
  20. const maxIterationsMin = 1
  21. const maxIterationsMax = 5
  22. const AgentSetting: FC<Props> = ({
  23. isChatModel,
  24. payload,
  25. isFunctionCall,
  26. onCancel,
  27. onSave,
  28. }) => {
  29. const { t } = useTranslation()
  30. const [tempPayload, setTempPayload] = useState(payload)
  31. const handleSave = () => {
  32. onSave(tempPayload)
  33. }
  34. return (
  35. <div className='fixed z-[100] inset-0 overflow-hidden flex justify-end p-2'
  36. style={{
  37. backgroundColor: 'rgba(16, 24, 40, 0.20)',
  38. }}
  39. >
  40. <div
  41. className='w-[640px] flex flex-col h-full overflow-hidden bg-white border-[0.5px] border-gray-200 rounded-xl shadow-xl'
  42. >
  43. <div className='shrink-0 flex justify-between items-center pl-6 pr-5 h-14 border-b border-b-gray-100'>
  44. <div className='flex flex-col text-base font-semibold text-gray-900'>
  45. <div className='leading-6'>{t('appDebug.agent.setting.name')}</div>
  46. </div>
  47. <div className='flex items-center'>
  48. <div
  49. onClick={onCancel}
  50. className='flex justify-center items-center w-6 h-6 cursor-pointer'
  51. >
  52. <RiCloseLine className='w-4 h-4 text-gray-500' />
  53. </div>
  54. </div>
  55. </div>
  56. {/* Body */}
  57. <div className='grow p-6 pt-5 border-b overflow-y-auto pb-[68px]' style={{
  58. borderBottom: 'rgba(0, 0, 0, 0.05)',
  59. }}>
  60. {/* Agent Mode */}
  61. <ItemPanel
  62. className='mb-4'
  63. icon={
  64. <CuteRobote className='w-4 h-4 text-indigo-600' />
  65. }
  66. name={t('appDebug.agent.agentMode')}
  67. description={t('appDebug.agent.agentModeDes')}
  68. >
  69. <div className='leading-[18px] text-[13px] font-medium text-gray-900'>{isFunctionCall ? t('appDebug.agent.agentModeType.functionCall') : t('appDebug.agent.agentModeType.ReACT')}</div>
  70. </ItemPanel>
  71. <ItemPanel
  72. className='mb-4'
  73. icon={
  74. <Unblur className='w-4 h-4 text-[#FB6514]' />
  75. }
  76. name={t('appDebug.agent.setting.maximumIterations.name')}
  77. description={t('appDebug.agent.setting.maximumIterations.description')}
  78. >
  79. <div className='flex items-center'>
  80. <Slider
  81. className='mr-3 w-[156px]'
  82. min={maxIterationsMin}
  83. max={maxIterationsMax}
  84. value={tempPayload.max_iteration}
  85. onChange={(value) => {
  86. setTempPayload({
  87. ...tempPayload,
  88. max_iteration: value,
  89. })
  90. }}
  91. />
  92. <input
  93. type="number"
  94. min={maxIterationsMin}
  95. max={maxIterationsMax} step={1}
  96. className="block w-11 h-7 leading-7 rounded-lg border-0 pl-1 px-1.5 bg-gray-100 text-gray-900 placeholder:text-gray-400 focus:ring-1 focus:ring-inset focus:ring-primary-600"
  97. value={tempPayload.max_iteration}
  98. onChange={(e) => {
  99. let value = parseInt(e.target.value, 10)
  100. if (value < maxIterationsMin)
  101. value = maxIterationsMin
  102. if (value > maxIterationsMax)
  103. value = maxIterationsMax
  104. setTempPayload({
  105. ...tempPayload,
  106. max_iteration: value,
  107. })
  108. }} />
  109. </div>
  110. </ItemPanel>
  111. {!isFunctionCall && (
  112. <div className='py-2 bg-gray-50 rounded-xl shadow-xs'>
  113. <div className='flex items-center h-8 px-4 leading-6 text-sm font-semibold text-gray-700'>{t('tools.builtInPromptTitle')}</div>
  114. <div className='h-[396px] px-4 overflow-y-auto leading-5 text-sm font-normal text-gray-700 whitespace-pre-line'>
  115. {isChatModel ? DEFAULT_AGENT_PROMPT.chat : DEFAULT_AGENT_PROMPT.completion}
  116. </div>
  117. <div className='px-4'>
  118. <div className='inline-flex items-center h-5 px-1 rounded-md bg-gray-100 leading-[18px] text-xs font-medium text-gray-500'>{(isChatModel ? DEFAULT_AGENT_PROMPT.chat : DEFAULT_AGENT_PROMPT.completion).length}</div>
  119. </div>
  120. </div>
  121. )}
  122. </div>
  123. <div
  124. className='sticky z-[5] bottom-0 w-full flex justify-end py-4 px-6 border-t bg-white '
  125. style={{
  126. borderColor: 'rgba(0, 0, 0, 0.05)',
  127. }}
  128. >
  129. <Button
  130. onClick={onCancel}
  131. className='mr-2 text-sm font-medium'
  132. >
  133. {t('common.operation.cancel')}
  134. </Button>
  135. <Button
  136. variant='primary'
  137. className='text-sm font-medium'
  138. onClick={handleSave}
  139. >
  140. {t('common.operation.save')}
  141. </Button>
  142. </div>
  143. </div>
  144. </div>
  145. )
  146. }
  147. export default React.memo(AgentSetting)