Shun Miyazawa 1 год назад
Родитель
Сommit
27cf3cd39e

+ 24 - 1
apps/app/src/features/openai/client/components/AiAssistant/AiAssistantManegementModal.tsx

@@ -5,17 +5,23 @@ import {
   Modal, ModalHeader, ModalBody, ModalFooter, Form, FormGroup, Label, Input,
 } from 'reactstrap';
 
+import { toastError, toastSuccess } from '~/client/util/toastr';
 import type { IPageForItem } from '~/interfaces/page';
 import { usePageSelectModal } from '~/stores/modal';
+import loggerFactory from '~/utils/logger';
 
 import type { SelectedPage } from '../../../interfaces/selected-page';
+import { createAiAssistant } from '../../services/ai-assistant';
 import { useAiAssistantManegementModal } from '../../stores/ai-assistant';
 import { SelectedPageList } from '../Common/SelectedPageList';
 
+
 import styles from './AiAssistantManegementModal.module.scss';
 
 const moduleClass = styles['grw-ai-assistant-manegement'] ?? '';
 
+const logger = loggerFactory('growi:openai:client:components:AiAssistantManegementModal');
+
 const AiAssistantManegementModalSubstance = (): JSX.Element => {
   const { open: openPageSelectModal } = usePageSelectModal();
   const [selectedPages, setSelectedPages] = useState<SelectedPage[]>([]);
@@ -36,6 +42,23 @@ const AiAssistantManegementModalSubstance = (): JSX.Element => {
     setSelectedPages(selectedPages.filter(selectedPage => selectedPage.page._id !== pageId));
   }, [selectedPages]);
 
+  const clickCreateAiAssistantHandler = useCallback(async() => {
+    try {
+      await createAiAssistant({
+        name: 'test',
+        description: 'test',
+        additionalInstruction: 'test',
+        pagePathPatterns: ['/Sandbox'],
+        shareScope: 'publicOnly',
+        accessScope: 'publicOnly',
+      });
+      toastSuccess('アシスタントを作成しました');
+    }
+    catch (err) {
+      toastError('アシスタントの作成に失敗しました');
+      logger.error(err);
+    }
+  }, []);
 
   return (
     <div className="px-4">
@@ -136,7 +159,7 @@ const AiAssistantManegementModalSubstance = (): JSX.Element => {
 
       <ModalFooter className="border-0 pt-0 mb-3">
         <button type="button" className="btn btn-outline-secondary" onClick={() => {}}>キャンセル</button>
-        <button type="button" className="btn btn-primary" onClick={() => {}}>作成</button>
+        <button type="button" className="btn btn-primary" onClick={clickCreateAiAssistantHandler}>作成</button>
       </ModalFooter>
     </div>
   );

+ 7 - 0
apps/app/src/features/openai/client/services/ai-assistant.ts

@@ -0,0 +1,7 @@
+import { apiv3Post } from '~/client/util/apiv3-client';
+
+import type { AiAssistant } from '../../interfaces/ai-assistant';
+
+export const createAiAssistant = async(body: Omit<AiAssistant, 'vectorStore' | 'owner'>): Promise<void> => {
+  await apiv3Post('/openai/ai-assistant', body);
+};