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

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

@@ -161,7 +161,7 @@ const AiAssistantSidebarSubstance: React.FC<AiAssistantSidebarSubstanceProps> =
     if (currentThreadId_ == null) {
       try {
         const res = await apiv3Post<IThreadRelationHasId>('/openai/thread', {
-          threadType: isEditorAssistant ? ThreadType.EDITOR : ThreadType.KNOWLEDGE,
+          type: isEditorAssistant ? ThreadType.EDITOR : ThreadType.KNOWLEDGE,
           aiAssistantId: isEditorAssistant ? selectedAiAssistant?._id : aiAssistantData?._id,
           initialUserMessage: isEditorAssistant ? undefined : newUserMessage.content,
         });

+ 1 - 1
apps/app/src/features/openai/interfaces/thread-relation.ts

@@ -14,7 +14,7 @@ export interface IThreadRelation {
   aiAssistant: Ref<AiAssistant>
   threadId: string;
   title?: string;
-  threadType: ThreadType;
+  type: ThreadType;
   expiredAt: Date;
 }
 

+ 1 - 1
apps/app/src/features/openai/server/models/thread-relation.ts

@@ -37,7 +37,7 @@ const schema = new Schema<ThreadRelationDocument, ThreadRelationModel>({
   title: {
     type: String,
   },
-  threadType: {
+  type: {
     type: String,
     enum: Object.values(ThreadType),
     required: true,

+ 4 - 4
apps/app/src/features/openai/server/routes/thread.ts

@@ -18,7 +18,7 @@ import { certifyAiService } from './middlewares/certify-ai-service';
 const logger = loggerFactory('growi:routes:apiv3:openai:thread');
 
 type ReqBody = {
-  threadType: ThreadType,
+  type: ThreadType,
   aiAssistantId?: string,
   initialUserMessage?: string,
 }
@@ -31,7 +31,7 @@ export const createThreadHandlersFactory: CreateThreadFactory = (crowi) => {
   const loginRequiredStrictly = require('~/server/middlewares/login-required')(crowi);
 
   const validator: ValidationChain[] = [
-    body('threadType').isIn(Object.values(ThreadType)).withMessage('threadType must be one of "editor" or "knowledge"'),
+    body('type').isIn(Object.values(ThreadType)).withMessage('type must be one of "editor" or "knowledge"'),
     body('aiAssistantId').optional().isMongoId().withMessage('aiAssistantId must be string'),
     body('initialUserMessage').optional().isString().withMessage('initialUserMessage must be string'),
   ];
@@ -46,8 +46,8 @@ export const createThreadHandlersFactory: CreateThreadFactory = (crowi) => {
       }
 
       try {
-        const { threadType, aiAssistantId, initialUserMessage } = req.body;
-        const thread = await openaiService.createThread(req.user._id, threadType, aiAssistantId, initialUserMessage);
+        const { type, aiAssistantId, initialUserMessage } = req.body;
+        const thread = await openaiService.createThread(req.user._id, type, aiAssistantId, initialUserMessage);
         return res.apiv3(thread);
       }
       catch (err) {

+ 3 - 3
apps/app/src/features/openai/server/services/normalize-data/normalize-thread-relation-expired-at/normalize-thread-relation-expired-at.integ.ts

@@ -19,7 +19,7 @@ describe('normalizeExpiredAtForThreadRelations', () => {
       threadId: 'test-thread',
       aiAssistant: new Types.ObjectId(),
       expiredAt: expiredDate,
-      threadType: ThreadType.KNOWLEDGE,
+      type: ThreadType.KNOWLEDGE,
     });
     await threadRelation.save();
 
@@ -42,7 +42,7 @@ describe('normalizeExpiredAtForThreadRelations', () => {
       threadId: 'test-thread-2',
       aiAssistant: new Types.ObjectId(),
       expiredAt: nonExpiredDate,
-      threadType: ThreadType.KNOWLEDGE,
+      type: ThreadType.KNOWLEDGE,
     });
     await threadRelation.save();
 
@@ -63,7 +63,7 @@ describe('normalizeExpiredAtForThreadRelations', () => {
       threadId: 'test-thread-3',
       aiAssistant: new Types.ObjectId(),
       expiredAt: nonExpiredDate,
-      threadType: ThreadType.KNOWLEDGE,
+      type: ThreadType.KNOWLEDGE,
     });
     await threadRelation.save();
 

+ 5 - 5
apps/app/src/features/openai/server/services/openai.ts

@@ -66,7 +66,7 @@ const convertPathPatternsToRegExp = (pagePathPatterns: string[]): Array<string |
 };
 
 export interface IOpenaiService {
-  createThread(userId: string, threadType: ThreadType, aiAssistantId?: string, initialUserMessage?: string): Promise<ThreadRelationDocument>;
+  createThread(userId: string, type: ThreadType, aiAssistantId?: string, initialUserMessage?: string): Promise<ThreadRelationDocument>;
   getThreadsByAiAssistantId(aiAssistantId: string): Promise<ThreadRelationDocument[]>
   deleteThread(threadRelationId: string): Promise<ThreadRelationDocument>;
   deleteExpiredThreads(limit: number, apiCallInterval: number): Promise<void>; // for CronJob
@@ -118,7 +118,7 @@ class OpenaiService implements IOpenaiService {
     return threadTitle;
   }
 
-  async createThread(userId: string, threadType: ThreadType, aiAssistantId?: string, initialUserMessage?: string): Promise<ThreadRelationDocument> {
+  async createThread(userId: string, type: ThreadType, aiAssistantId?: string, initialUserMessage?: string): Promise<ThreadRelationDocument> {
     let threadTitle: string | null = null;
     if (initialUserMessage != null) {
       try {
@@ -134,7 +134,7 @@ class OpenaiService implements IOpenaiService {
       const thread = await this.client.createThread(vectorStoreRelation?.vectorStoreId);
       const threadRelation = await ThreadRelationModel.create({
         userId,
-        threadType,
+        type,
         aiAssistant: aiAssistantId,
         threadId: thread.id,
         title: threadTitle,
@@ -159,8 +159,8 @@ class OpenaiService implements IOpenaiService {
     }
   }
 
-  async getThreadsByAiAssistantId(aiAssistantId: string, threadType: ThreadType = ThreadType.KNOWLEDGE): Promise<ThreadRelationDocument[]> {
-    const threadRelations = await ThreadRelationModel.find({ aiAssistant: aiAssistantId, threadType });
+  async getThreadsByAiAssistantId(aiAssistantId: string, type: ThreadType = ThreadType.KNOWLEDGE): Promise<ThreadRelationDocument[]> {
+    const threadRelations = await ThreadRelationModel.find({ aiAssistant: aiAssistantId, type });
     return threadRelations;
   }