-
Notifications
You must be signed in to change notification settings - Fork 220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: AiAssistantModel #9494
Merged
yuki-takei
merged 24 commits into
feat/growi-ai-next
from
feat/159152-ai-assistant-model
Dec 25, 2024
Merged
feat: AiAssistantModel #9494
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
821203c
impl AiAssistantModel
miya 26713ca
clean code
miya 9930e20
rm unnec opt
miya a8b3143
Add types (to be implemented in the future)
miya caf1db1
type -> types
miya b52554d
clean code
miya 6a505a4
Add field (isDeleted)
miya b143f57
add grantedGroups
miya 9167954
add creator
miya 3fc841c
fix types
miya df996cb
optional
miya c5c8529
change field name
miya 9081d95
Merge branch 'feat/growi-ai-next' into feat/159152-ai-assistant-model
miya c0c9bc0
not optional
miya 5f4ba68
Revert "Add field (isDeleted)"
miya eafecf9
Refactor AiAssistant model to use vectorStore reference and export Ve…
miya a6f79e0
Add grantedUsers field to AiAssistant model for user-specific sharing
miya d63af50
Merge branch 'feat/growi-ai-next' into feat/159152-ai-assistant-model
miya 815deee
Merge branch 'feat/growi-ai-next' into feat/159152-ai-assistant-model
miya 10c7773
Rename learningScope to ownerAccessScope in AiAssistant model for cla…
miya f661d11
Rename AiAssistantSharingScope to AiAssistantShareScope for consistency
miya 752768a
Update enum reference for shareScope to use AiAssistantShareScope
miya 0775170
Add pagePaths property to AiAssistant model for enhanced functionality
miya c5e73e7
pagePath -> pagePathPatterns
miya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
141 changes: 141 additions & 0 deletions
141
apps/app/src/features/openai/server/models/ai-assistant.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,141 @@ | ||||||||||||||||||||||||||||||||||||||||||||||
import { | ||||||||||||||||||||||||||||||||||||||||||||||
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 | ||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||
const AiAssistantType = { | ||||||||||||||||||||||||||||||||||||||||||||||
KNOWLEDGE: 'knowledge', | ||||||||||||||||||||||||||||||||||||||||||||||
// EDITOR: 'editor', | ||||||||||||||||||||||||||||||||||||||||||||||
// LEARNING: 'learning', | ||||||||||||||||||||||||||||||||||||||||||||||
} as const; | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
const AiAssistantShareScope = { | ||||||||||||||||||||||||||||||||||||||||||||||
PUBLIC: 'public', | ||||||||||||||||||||||||||||||||||||||||||||||
ONLY_ME: 'onlyMe', | ||||||||||||||||||||||||||||||||||||||||||||||
USER_GROUP: 'userGroup', | ||||||||||||||||||||||||||||||||||||||||||||||
} as const; | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
const AiAssistantOwnerAccessScope = { | ||||||||||||||||||||||||||||||||||||||||||||||
PUBLIC: 'public', | ||||||||||||||||||||||||||||||||||||||||||||||
ONLY_ME: 'onlyMe', | ||||||||||||||||||||||||||||||||||||||||||||||
USER_GROUP: 'userGroup', | ||||||||||||||||||||||||||||||||||||||||||||||
} as const; | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
/* | ||||||||||||||||||||||||||||||||||||||||||||||
* Interfaces | ||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||
type AiAssistantType = typeof AiAssistantType[keyof typeof AiAssistantType]; | ||||||||||||||||||||||||||||||||||||||||||||||
type AiAssistantShareScope = typeof AiAssistantShareScope[keyof typeof AiAssistantShareScope]; | ||||||||||||||||||||||||||||||||||||||||||||||
type AiAssistantOwnerAccessScope = typeof AiAssistantOwnerAccessScope[keyof typeof AiAssistantOwnerAccessScope]; | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
interface AiAssistant { | ||||||||||||||||||||||||||||||||||||||||||||||
name: string; | ||||||||||||||||||||||||||||||||||||||||||||||
description: string | ||||||||||||||||||||||||||||||||||||||||||||||
additionalInstruction: string | ||||||||||||||||||||||||||||||||||||||||||||||
pagePathPatterns: string[], | ||||||||||||||||||||||||||||||||||||||||||||||
vectorStore: Ref<VectorStore> | ||||||||||||||||||||||||||||||||||||||||||||||
types: AiAssistantType[] | ||||||||||||||||||||||||||||||||||||||||||||||
owner: Ref<IUser> | ||||||||||||||||||||||||||||||||||||||||||||||
grantedUsers?: IUser[] | ||||||||||||||||||||||||||||||||||||||||||||||
grantedGroups?: IGrantedGroup[] | ||||||||||||||||||||||||||||||||||||||||||||||
shareScope: AiAssistantShareScope | ||||||||||||||||||||||||||||||||||||||||||||||
ownerAccessScope: AiAssistantOwnerAccessScope | ||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
interface AiAssistantDocument extends AiAssistant, Document {} | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
type AiAssistantModel = Model<AiAssistantDocument> | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
/* | ||||||||||||||||||||||||||||||||||||||||||||||
* Schema Definition | ||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||
const schema = new Schema<AiAssistantDocument>( | ||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||
name: { | ||||||||||||||||||||||||||||||||||||||||||||||
type: String, | ||||||||||||||||||||||||||||||||||||||||||||||
required: true, | ||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||
description: { | ||||||||||||||||||||||||||||||||||||||||||||||
type: String, | ||||||||||||||||||||||||||||||||||||||||||||||
required: true, | ||||||||||||||||||||||||||||||||||||||||||||||
default: '', | ||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||
additionalInstruction: { | ||||||||||||||||||||||||||||||||||||||||||||||
type: String, | ||||||||||||||||||||||||||||||||||||||||||||||
required: true, | ||||||||||||||||||||||||||||||||||||||||||||||
default: '', | ||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||
pagePathPatterns: [{ | ||||||||||||||||||||||||||||||||||||||||||||||
type: String, | ||||||||||||||||||||||||||||||||||||||||||||||
required: true, | ||||||||||||||||||||||||||||||||||||||||||||||
}], | ||||||||||||||||||||||||||||||||||||||||||||||
vectorStore: { | ||||||||||||||||||||||||||||||||||||||||||||||
type: Schema.Types.ObjectId, | ||||||||||||||||||||||||||||||||||||||||||||||
ref: 'VectorStore', | ||||||||||||||||||||||||||||||||||||||||||||||
required: true, | ||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||
types: [{ | ||||||||||||||||||||||||||||||||||||||||||||||
type: String, | ||||||||||||||||||||||||||||||||||||||||||||||
enum: Object.values(AiAssistantType), | ||||||||||||||||||||||||||||||||||||||||||||||
required: true, | ||||||||||||||||||||||||||||||||||||||||||||||
}], | ||||||||||||||||||||||||||||||||||||||||||||||
owner: { | ||||||||||||||||||||||||||||||||||||||||||||||
type: Schema.Types.ObjectId, | ||||||||||||||||||||||||||||||||||||||||||||||
ref: 'User', | ||||||||||||||||||||||||||||||||||||||||||||||
required: true, | ||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||
grantedUsers: [ | ||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||
type: Schema.Types.ObjectId, | ||||||||||||||||||||||||||||||||||||||||||||||
ref: 'User', | ||||||||||||||||||||||||||||||||||||||||||||||
required: true, | ||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||
], | ||||||||||||||||||||||||||||||||||||||||||||||
grantedGroups: { | ||||||||||||||||||||||||||||||||||||||||||||||
type: [{ | ||||||||||||||||||||||||||||||||||||||||||||||
type: { | ||||||||||||||||||||||||||||||||||||||||||||||
type: String, | ||||||||||||||||||||||||||||||||||||||||||||||
enum: Object.values(GroupType), | ||||||||||||||||||||||||||||||||||||||||||||||
required: true, | ||||||||||||||||||||||||||||||||||||||||||||||
default: 'UserGroup', | ||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||
item: { | ||||||||||||||||||||||||||||||||||||||||||||||
type: Schema.Types.ObjectId, | ||||||||||||||||||||||||||||||||||||||||||||||
refPath: 'grantedGroups.type', | ||||||||||||||||||||||||||||||||||||||||||||||
required: true, | ||||||||||||||||||||||||||||||||||||||||||||||
index: true, | ||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||
}], | ||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Page model を踏襲 growi/apps/app/src/server/models/page.ts Lines 137 to 158 in df996cb
|
||||||||||||||||||||||||||||||||||||||||||||||
validate: [function(arr: IGrantedGroup[]): boolean { | ||||||||||||||||||||||||||||||||||||||||||||||
if (arr == null) return true; | ||||||||||||||||||||||||||||||||||||||||||||||
const uniqueItemValues = new Set(arr.map(e => e.item)); | ||||||||||||||||||||||||||||||||||||||||||||||
return arr.length === uniqueItemValues.size; | ||||||||||||||||||||||||||||||||||||||||||||||
}, 'grantedGroups contains non unique item'], | ||||||||||||||||||||||||||||||||||||||||||||||
default: [], | ||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||
shareScope: { | ||||||||||||||||||||||||||||||||||||||||||||||
type: String, | ||||||||||||||||||||||||||||||||||||||||||||||
enum: Object.values(AiAssistantShareScope), | ||||||||||||||||||||||||||||||||||||||||||||||
required: true, | ||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 共有範囲 |
||||||||||||||||||||||||||||||||||||||||||||||
ownerAccessScope: { | ||||||||||||||||||||||||||||||||||||||||||||||
type: String, | ||||||||||||||||||||||||||||||||||||||||||||||
enum: Object.values(AiAssistantOwnerAccessScope), | ||||||||||||||||||||||||||||||||||||||||||||||
required: true, | ||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||
timestamps: true, | ||||||||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
export default getOrCreateModel<AiAssistantDocument, AiAssistantModel>('AiAssistant', schema); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VectorStore に保存する page の path