Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

page.tsx 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. "use client";
  2. import { useState, useEffect } from 'react'
  3. import PageTitle from '@/components/ui/PageTitle';
  4. import { Upload, Select, Switch, Form, Button, Tag, Layout, Typography, Input, Row, Col, Flex } from 'antd'
  5. import { UploadOutlined } from '@ant-design/icons';
  6. import InputList from '@/components/ui/InputList';
  7. import type { SelectProps } from 'antd';
  8. import TextArea from 'antd/es/input/TextArea';
  9. import { useQuery } from '@tanstack/react-query';
  10. import { getPersona } from '@/app/api/user/personaService';
  11. import AltLayout from '@/components/layout/AltLayout';
  12. const { Title, Text } = Typography;
  13. const CreatePersona: React.FC = () => {
  14. const [name, setName] = useState<string | undefined>("")
  15. const [isPremium, setIsPremium] = useState<boolean>(true)
  16. const [options, setOptions] = useState<SelectProps[] | undefined>()
  17. const [enabled, setEnabled] = useState({
  18. isWebSearch: false,
  19. isEcommerceShop: false,
  20. isCanvas: false,
  21. isDalleImageGeneration: false,
  22. isCodeInterpreter: false
  23. });
  24. const { data: personas } = useQuery({
  25. queryKey: ["getPersona"],
  26. queryFn: () => getPersona()
  27. })
  28. const uploadProps = {
  29. beforeUpload: (file: File) => {
  30. console.log('File uploaded:', file);
  31. return false; // Prevent automatic upload
  32. },
  33. };
  34. useEffect(() => {
  35. const latestData: SelectProps[] | undefined = personas?.map(persona => {
  36. return {
  37. label: persona.name,
  38. value: persona.id
  39. }
  40. })
  41. setOptions(latestData)
  42. }, [personas])
  43. return (
  44. <AltLayout header={<PageTitle backButton={true}>ADD KNOWLEDGE SOURCE</PageTitle>}>
  45. <Row>
  46. <Col span={24} className='!px-4'>
  47. <Form layout="vertical">
  48. <Row>
  49. <Col span={24}>
  50. <Form.Item label={<p className='font-bold'>Name</p>}>
  51. <Input />
  52. </Form.Item>
  53. <Form.Item label={<p className='font-bold'>Select Persona</p>}>
  54. <Select
  55. allowClear
  56. style={{ width: '100%' }}
  57. placeholder="Select from list ..."
  58. options={options}
  59. />
  60. </Form.Item>
  61. <Form.Item label={<p className='font-bold'>Description</p>}>
  62. <TextArea
  63. placeholder='Add a short description about what Persona does'
  64. style={{ padding: 10 }}
  65. rows={2}
  66. value={name}
  67. onChange={(e) => setName(e.target.value)}
  68. />
  69. </Form.Item>
  70. <Form.Item label={<p className='font-bold'>Instruction</p>}>
  71. <TextArea
  72. placeholder='What does this Persona do?, How does it behave?, What should it avoid doing? '
  73. style={{ padding: 10 }}
  74. rows={4}
  75. value={name}
  76. onChange={(e) => setName(e.target.value)}
  77. />
  78. </Form.Item>
  79. </Col>
  80. <Col span={24} className={`${isPremium ? '!visible' : '!hidden'}`}>
  81. <Form.Item
  82. label={
  83. <Title className='font-bold !text-sm'>
  84. Capabilities
  85. <Tag color="blue" className="!ms-2 font-semibold text-xs px-2 py-[2px] !rounded-full">
  86. Premium
  87. </Tag>
  88. </Title>
  89. }
  90. >
  91. <Row gutter={[5, 5]}>
  92. {/* Web Search */}
  93. <Col span={24}>
  94. <Flex gap={8}>
  95. <Switch
  96. checked={enabled.isWebSearch}
  97. onChange={(checked) =>
  98. setEnabled({ ...enabled, isWebSearch: checked })
  99. }
  100. />
  101. <Text className='font-bold'>Web Search</Text>
  102. </Flex>
  103. {enabled.isWebSearch && <InputList />}
  104. </Col>
  105. {/* Commerce & Shop */}
  106. <Col span={24}>
  107. <Flex gap={8}>
  108. <Switch
  109. checked={enabled.isEcommerceShop}
  110. onChange={(checked) =>
  111. setEnabled({ ...enabled, isEcommerceShop: checked })
  112. }
  113. />
  114. <Text className='font-bold'>Commerce & Shop</Text>
  115. </Flex>
  116. {enabled.isEcommerceShop && (
  117. <Upload {...uploadProps} className='!mt-2 block'>
  118. <Button icon={<UploadOutlined />}>Upload Shop Catalog</Button>
  119. </Upload>
  120. )}
  121. </Col>
  122. {/* Canvas */}
  123. <Col span={24}>
  124. <Flex gap={8}>
  125. <Switch
  126. checked={enabled.isCanvas}
  127. onChange={(checked) =>
  128. setEnabled({ ...enabled, isCanvas: checked })
  129. }
  130. />
  131. <Text className='font-bold'>Canvas</Text>
  132. </Flex>
  133. {enabled.isCanvas && (
  134. <Upload {...uploadProps} className='!mt-2 block'>
  135. <Button icon={<UploadOutlined />}>Upload Canvas File</Button>
  136. </Upload>
  137. )}
  138. </Col>
  139. {/* DALL·E Image Generation */}
  140. <Col span={24}>
  141. <Flex gap={8}>
  142. <Switch
  143. checked={enabled.isDalleImageGeneration}
  144. onChange={(checked) =>
  145. setEnabled({ ...enabled, isDalleImageGeneration: checked })
  146. }
  147. />
  148. <Text className='font-bold'>DALL-E Image Generation</Text>
  149. </Flex>
  150. {enabled.isDalleImageGeneration && (
  151. <Upload {...uploadProps} className='!mt-2 block'>
  152. <Button icon={<UploadOutlined />}>Upload Prompt CSV</Button>
  153. </Upload>
  154. )}
  155. </Col>
  156. {/* Code Interpreter */}
  157. <Col span={24}>
  158. <Flex gap={8}>
  159. <Switch
  160. checked={enabled.isCodeInterpreter}
  161. onChange={(checked) =>
  162. setEnabled({ ...enabled, isCodeInterpreter: checked })
  163. }
  164. />
  165. <Text className='font-bold'>Code Interpreter & Data Analysis</Text>
  166. </Flex>
  167. {enabled.isCodeInterpreter && (
  168. <Upload {...uploadProps} className='!mt-2 block'>
  169. <Button icon={<UploadOutlined />}>Upload Data File</Button>
  170. </Upload>
  171. )}
  172. </Col>
  173. </Row>
  174. </Form.Item>
  175. </Col>
  176. <Col span={24} className='!text-center'>
  177. <Flex justify='center'>
  178. <Button type="primary" className='!w-fit !py-3 !text-xs !font-bold !px-10'>SUBMIT</Button>
  179. </Flex>
  180. </Col>
  181. </Row>
  182. </Form>
  183. </Col>
  184. </Row>
  185. </AltLayout>
  186. )
  187. }
  188. export default CreatePersona;