-
Notifications
You must be signed in to change notification settings - Fork 3
Add AIassistant module #373
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
Open
sekulya
wants to merge
5
commits into
main
Choose a base branch
from
aiassistant-module
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a12933f
Add AIassistant module
sekulya 7d075f3
Describe your changes here
e72f933
Ignore __pycache__ and cleanup tracked cache files
sekulya 1feef9d
Ignore venv and pycache folders
sekulya 900e202
with .gitignore and multiple xsl and doc files input and answer
sekulya 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
31 changes: 31 additions & 0 deletions
31
backend/core-api/src/modules/AIassistant/db/definitions/generalSettings.ts
This file contains hidden or 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,31 @@ | ||
| import { Document, Model } from 'mongoose'; | ||
|
|
||
|
|
||
| export interface IGeneralSettings { | ||
| assistantName: string; | ||
| conversationStarter: string; | ||
| description: string; | ||
| promptSuggestions: string[]; | ||
| updatedAt?: Date; | ||
| } | ||
|
|
||
|
|
||
| export interface IGeneralSettingsDocument extends IGeneralSettings, Document { | ||
| userId: string; | ||
| createdAt: Date; | ||
| updatedAt: Date; | ||
| } | ||
|
|
||
|
|
||
| export interface IGeneralSettingsModel extends Model<IGeneralSettingsDocument> { | ||
| getSettings(): Promise<IGeneralSettingsDocument | null>; | ||
| updateSettings(doc: Partial<IGeneralSettings>): Promise<IGeneralSettingsDocument>; | ||
| } | ||
|
|
||
|
|
||
| export const generalSettingsFields = { | ||
| assistantName: { type: String, default: '' }, | ||
| conversationStarter: { type: String, default: '' }, | ||
| description: { type: String, default: '' }, | ||
| promptSuggestions: { type: [String], default: [] }, | ||
| }; |
34 changes: 34 additions & 0 deletions
34
backend/core-api/src/modules/AIassistant/db/definitions/ragInteractions.ts
This file contains hidden or 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,34 @@ | ||
| import { Document } from 'mongoose'; | ||
|
|
||
| export interface IRagInteraction { | ||
| question: string; | ||
| answer: string; | ||
| sourceDocuments?: string[]; | ||
| userId: string; | ||
| orgId: string; | ||
| createdAt: Date; | ||
| modelUsed?: string; | ||
| responseTime?: number; | ||
| tokensUsed?: number; | ||
| confidenceScore?: number; | ||
| status: 'success' | 'error' | 'pending'; | ||
| errorMessage?: string; | ||
| } | ||
|
|
||
| export interface IRagInteractionDocument extends IRagInteraction, Document {} | ||
|
|
||
| // Export the fields as a string | ||
| export const ragInteractionFields = ` | ||
| question: String | ||
| answer: String | ||
| sourceDocuments: [String] | ||
| userId: String | ||
| orgId: String | ||
| createdAt: Date | ||
| modelUsed: String | ||
| responseTime: Float | ||
| tokensUsed: Float | ||
| confidenceScore: Float | ||
| status: String | ||
| errorMessage: String | ||
| `; |
22 changes: 22 additions & 0 deletions
22
backend/core-api/src/modules/AIassistant/db/definitions/systemPrompt.ts
This file contains hidden or 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,22 @@ | ||
| import { Document, Model } from "mongoose"; | ||
|
|
||
| export interface ISystemPrompt { | ||
| prompt: string; | ||
| updatedAt?: Date; | ||
| } | ||
|
|
||
| export interface ISystemPromptDocument extends ISystemPrompt, Document { | ||
| userId: string; | ||
| createdAt: Date; | ||
| updatedAt: Date; | ||
| } | ||
|
|
||
| export interface ISystemPromptModel extends Model<ISystemPromptDocument> { | ||
| getPrompt(): Promise<ISystemPromptDocument | null>; | ||
| updatePrompt(prompt: string): Promise<ISystemPromptDocument>; | ||
| } | ||
|
|
||
| export const systemPromptFields = { | ||
| userId: { type: String, required: true }, | ||
| prompt: { type: String, default: "" }, | ||
| }; |
23 changes: 23 additions & 0 deletions
23
backend/core-api/src/modules/AIassistant/db/models/GeneralSettings.ts
This file contains hidden or 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,23 @@ | ||
| import { Schema, model, models, Model } from "mongoose"; | ||
| import { | ||
| IGeneralSettingsDocument, | ||
| IGeneralSettingsModel, | ||
| generalSettingsFields, | ||
| } from "~/modules/aiassistant/db/definitions/generalSettings"; | ||
|
|
||
| export const GeneralSettingsSchema = new Schema<IGeneralSettingsDocument>( | ||
| generalSettingsFields, | ||
| { | ||
| timestamps: true, | ||
| collection: "general_settings", | ||
| } | ||
| ); | ||
|
|
||
| const MODEL_NAME = "GeneralSettings"; | ||
|
|
||
| export const GeneralSettings = | ||
| (models[MODEL_NAME] as IGeneralSettingsModel) || | ||
| model<IGeneralSettingsDocument, IGeneralSettingsModel>( | ||
| MODEL_NAME, | ||
| GeneralSettingsSchema | ||
| ); |
69 changes: 69 additions & 0 deletions
69
backend/core-api/src/modules/AIassistant/db/models/RagInteractions.ts
This file contains hidden or 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,69 @@ | ||
| import { Schema, model, models, Document, Model } from 'mongoose'; | ||
| import { field, stringField, numberField, dateField } from '../../utils/schemaField'; | ||
| import { IRagInteraction } from '../definitions/ragInteractions'; | ||
|
|
||
| export interface IRagInteractionDocument extends IRagInteraction, Document {} | ||
|
|
||
| export interface IRagInteractionModel extends Model<IRagInteractionDocument> { | ||
| getRagInteraction(_id: string): Promise<IRagInteractionDocument>; | ||
| } | ||
|
|
||
| export const ragInteractionSchema = new Schema({ | ||
| question: stringField({ label: 'Question' }), | ||
| answer: stringField({ label: 'Answer' }), | ||
| sourceDocuments: field({ | ||
| type: [String], | ||
| label: 'Source Documents', | ||
| optional: true | ||
| }), | ||
| userId: stringField({ label: 'User ID' }), | ||
| orgId: stringField({ label: 'Organization ID' }), | ||
| createdAt: dateField({ | ||
| default: Date.now, | ||
| label: 'Created at', | ||
| immutable: true | ||
| }), | ||
| modelUsed: stringField({ | ||
| label: 'Model Used', | ||
| optional: true | ||
| }), | ||
| responseTime: numberField({ | ||
| label: 'Response Time (ms)', | ||
| optional: true, | ||
| min: 0 | ||
| }), | ||
| tokensUsed: numberField({ | ||
| label: 'Tokens Used', | ||
| optional: true, | ||
| min: 0 | ||
| }), | ||
| confidenceScore: numberField({ | ||
| label: 'Confidence Score', | ||
| optional: true, | ||
| min: 0, | ||
| max: 1 | ||
| }), | ||
| status: stringField({ | ||
| label: 'Status', | ||
| enum: ['success', 'error', 'pending'], | ||
| default: 'success' | ||
| }), | ||
| errorMessage: stringField({ | ||
| label: 'Error Message', | ||
| optional: true | ||
| }) | ||
| }, { | ||
| timestamps: true, | ||
| collection: 'rag_interactions' | ||
| }); | ||
|
|
||
| // Add indexes for better query performance | ||
| ragInteractionSchema.index({ userId: 1, createdAt: -1 }); | ||
| ragInteractionSchema.index({ orgId: 1 }); | ||
| ragInteractionSchema.index({ status: 1 }); | ||
|
|
||
| const MODEL_NAME = 'RagInteractions'; | ||
|
|
||
| export const RagInteractions = | ||
| (models[MODEL_NAME] as IRagInteractionModel) || | ||
| model<IRagInteractionDocument, IRagInteractionModel>(MODEL_NAME, ragInteractionSchema); |
39 changes: 39 additions & 0 deletions
39
backend/core-api/src/modules/AIassistant/db/models/SystemPrompt.ts
This file contains hidden or 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,39 @@ | ||
| import { Schema, model, Model } from "mongoose"; | ||
| import { | ||
| ISystemPromptDocument, | ||
| ISystemPromptModel, | ||
| systemPromptFields, | ||
| } from "../definitions/systemPrompt"; | ||
|
|
||
| export const SystemPromptSchema = new Schema<ISystemPromptDocument>( | ||
| systemPromptFields, | ||
| { | ||
| timestamps: true, | ||
| collection: 'system_prompts' | ||
| } | ||
| ); | ||
|
|
||
| SystemPromptSchema.statics.getPrompt = function () { | ||
| return this.findOne().exec(); | ||
| }; | ||
|
|
||
| SystemPromptSchema.statics.updatePrompt = async function (prompt: string) { | ||
| const updated = await this.findOneAndUpdate( | ||
| {}, | ||
| { | ||
| prompt, | ||
| updatedAt: new Date() | ||
| }, | ||
| { | ||
| new: true, | ||
| upsert: true | ||
| } | ||
| ).exec(); | ||
|
|
||
| return updated; | ||
| }; | ||
|
|
||
| export const SystemPromptModel = model<ISystemPromptDocument, ISystemPromptModel>( | ||
| "system_prompt", | ||
| SystemPromptSchema | ||
| ); |
23 changes: 23 additions & 0 deletions
23
backend/core-api/src/modules/AIassistant/db/models/loadGeneralSettingsClass.ts
This file contains hidden or 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,23 @@ | ||
| import { IModels } from '~/connectionResolvers'; | ||
| import { GeneralSettingsModel } from '~/modules/aiassistant/db/models/GeneralSettings'; | ||
| import { IGeneralSettingsDocument } from '~/modules/aiassistant/db/definitions/generalSettings'; | ||
|
|
||
|
|
||
| export const loadGeneralSettingsClass = (models: IModels) => { | ||
| class GeneralSettings { | ||
| // Example static method | ||
| public static async getSettings(): Promise<IGeneralSettingsDocument | null> { | ||
| return models.GeneralSettings.findOne({}); | ||
| } | ||
|
|
||
|
|
||
| // You can add more static methods here | ||
| } | ||
|
|
||
|
|
||
| // Attach class methods to the existing model's schema | ||
| GeneralSettingsModel.schema.loadClass(GeneralSettings); | ||
|
|
||
|
|
||
| return GeneralSettingsModel; | ||
| }; |
20 changes: 20 additions & 0 deletions
20
backend/core-api/src/modules/AIassistant/db/models/loadInteractionClass.ts
This file contains hidden or 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,20 @@ | ||
| import { IModels } from '~/connectionResolvers'; | ||
| import { ragInteractionSchema } from './RagInteractions'; | ||
| import { IRagInteractionDocument, IRagInteraction } from '../definitions/ragInteractions'; | ||
|
|
||
| export const loadRagInteractionClass = (models: IModels) => { | ||
| class RagInteraction { | ||
| public static async getRagInteraction(_id: string) { | ||
| const ragInteraction = await models.RagInteractions.findOne({ _id }); | ||
|
|
||
| if (!ragInteraction) { | ||
| throw new Error('RagInteraction not found'); | ||
| } | ||
|
|
||
| return ragInteraction; | ||
| } | ||
| } | ||
|
|
||
| ragInteractionSchema.loadClass(RagInteraction); | ||
| return ragInteractionSchema; | ||
| }; |
Oops, something went wrong.
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.
Fix the import path casing to match the filesystem.
The pipeline failure indicates a case sensitivity issue where the import path doesn't match the actual file's casing. The error shows both
aiassistantandAIassistantpaths exist, which will cause problems on case-sensitive filesystems.Verify the correct directory name and update the import accordingly:
🤖 Prompt for AI Agents