| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- import type mongoose from 'mongoose';
- import { type Model, type Document, Schema } from 'mongoose';
- import { getOrCreateModel } from '~/server/util/mongoose-utils';
- /*
- * Objects
- */
- const AiAssistantType = {
- KNOWLEDGE: 'knowledge',
- // EDITOR: 'editor',
- // LEARNING: 'learning',
- } as const;
- const AiAssistantSharingScope = {
- PUBLIC: 'public',
- ONLY_ME: 'onlyMe',
- USER_GROUP: 'userGroup',
- } as const;
- const AiAssistantLearningScope = {
- PUBLIC: 'public',
- ONLY_ME: 'onlyMe',
- USER_GROUP: 'userGroup',
- } as const;
- /*
- * Interfaces
- */
- type AiAssistantType = typeof AiAssistantType[keyof typeof AiAssistantType];
- type AiAssistantSharingScope = typeof AiAssistantSharingScope[keyof typeof AiAssistantSharingScope];
- type AiAssistantLearningScope = typeof AiAssistantLearningScope[keyof typeof AiAssistantLearningScope];
- interface AiAssistant {
- name: string;
- description?: string
- instruction?: string
- vectorStoreId: string // VectorStoreId of OpenAI Specify (https://platform.openai.com/docs/api-reference/vector-stores/object)
- types: AiAssistantType[]
- pages: mongoose.Types.ObjectId[]
- sharingScope: AiAssistantSharingScope
- learningScope: AiAssistantLearningScope
- }
- interface AiAssistantDocument extends AiAssistant, Document {}
- type AiAssistantModel = Model<AiAssistantDocument>
- /*
- * Schema Definition
- */
- const schema = new Schema<AiAssistantDocument>(
- {
- name: {
- type: String,
- required: true,
- },
- description: {
- type: String,
- },
- instruction: {
- type: String,
- },
- vectorStoreId: {
- type: String,
- required: true,
- },
- types: [{
- type: String,
- enum: Object.values(AiAssistantType),
- required: true,
- }],
- pages: [{
- type: Schema.Types.ObjectId,
- ref: 'Page',
- required: true,
- }],
- sharingScope: {
- type: String,
- enum: Object.values(AiAssistantSharingScope),
- required: true,
- },
- learningScope: {
- type: String,
- enum: Object.values(AiAssistantLearningScope),
- required: true,
- },
- },
- {
- timestamps: true,
- },
- );
- export default getOrCreateModel<AiAssistantDocument, AiAssistantModel>('AiAssistant', schema);
|