Просмотр исходного кода

Refactor AiAssistant model to use vectorStore reference and export VectorStore interface

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

+ 7 - 10
apps/app/src/features/openai/server/models/ai-assistant.ts

@@ -1,10 +1,12 @@
 import {
-  type IGrantedGroup, GroupType, type IPage, type IUser, type Ref,
+  type IGrantedGroup, GroupType, type IUser, type Ref,
 } from '@growi/core';
 import { type Model, type Document, Schema } from 'mongoose';
 
 import { getOrCreateModel } from '~/server/util/mongoose-utils';
 
+import type { VectorStore } from './vector-store';
+
 /*
 *  Objects
 */
@@ -38,11 +40,10 @@ interface AiAssistant {
   name: string;
   description: string
   additionalInstruction: string
-  vectorStoreId: string // VectorStoreId of OpenAI Specify (https://platform.openai.com/docs/api-reference/vector-stores/object)
+  vectorStore: Ref<VectorStore>
   types: AiAssistantType[]
   owner: Ref<IUser>
   grantedGroups?: IGrantedGroup[];
-  pages: Ref<IPage>[]
   sharingScope: AiAssistantSharingScope
   learningScope: AiAssistantLearningScope
 }
@@ -71,8 +72,9 @@ const schema = new Schema<AiAssistantDocument>(
       required: true,
       default: '',
     },
-    vectorStoreId: {
-      type: String,
+    vectorStore: {
+      type: Schema.Types.ObjectId,
+      ref: 'VectorStore',
       required: true,
     },
     types: [{
@@ -85,11 +87,6 @@ const schema = new Schema<AiAssistantDocument>(
       ref: 'User',
       required: true,
     },
-    pages: [{
-      type: Schema.Types.ObjectId,
-      ref: 'Page',
-      required: true,
-    }],
     grantedGroups: {
       type: [{
         type: {

+ 1 - 1
apps/app/src/features/openai/server/models/vector-store.ts

@@ -9,7 +9,7 @@ export const VectorStoreScopeType = {
 export type VectorStoreScopeType = typeof VectorStoreScopeType[keyof typeof VectorStoreScopeType];
 
 const VectorStoreScopeTypes = Object.values(VectorStoreScopeType);
-interface VectorStore {
+export interface VectorStore {
   vectorStoreId: string
   scopeType: VectorStoreScopeType
   isDeleted: boolean