|
@@ -66,14 +66,12 @@ const convertPathPatternsToRegExp = (pagePathPatterns: string[]): Array<string |
|
|
|
|
|
|
|
|
export interface IOpenaiService {
|
|
export interface IOpenaiService {
|
|
|
createThread(userId: string, aiAssistantId: string, initialUserMessage: string): Promise<ThreadRelationDocument>;
|
|
createThread(userId: string, aiAssistantId: string, initialUserMessage: string): Promise<ThreadRelationDocument>;
|
|
|
- getThreadsByAiAssistant(aiAssistantId: string): Promise<ThreadRelationDocument[]>
|
|
|
|
|
|
|
+ getThreadsByAiAssistantId(aiAssistantId: string): Promise<ThreadRelationDocument[]>
|
|
|
deleteThread(threadRelationId: string): Promise<ThreadRelationDocument>;
|
|
deleteThread(threadRelationId: string): Promise<ThreadRelationDocument>;
|
|
|
deleteExpiredThreads(limit: number, apiCallInterval: number): Promise<void>; // for CronJob
|
|
deleteExpiredThreads(limit: number, apiCallInterval: number): Promise<void>; // for CronJob
|
|
|
deleteObsolatedVectorStoreRelations(): Promise<void> // for CronJob
|
|
deleteObsolatedVectorStoreRelations(): Promise<void> // for CronJob
|
|
|
deleteVectorStore(vectorStoreRelationId: string): Promise<void>;
|
|
deleteVectorStore(vectorStoreRelationId: string): Promise<void>;
|
|
|
getMessageData(threadId: string, lang?: Lang, options?: MessageListParams): Promise<OpenAI.Beta.Threads.Messages.MessagesPage>;
|
|
getMessageData(threadId: string, lang?: Lang, options?: MessageListParams): Promise<OpenAI.Beta.Threads.Messages.MessagesPage>;
|
|
|
- getVectorStoreRelation(aiAssistantId: string): Promise<VectorStoreDocument>
|
|
|
|
|
- getVectorStoreRelationsByPageIds(pageId: Types.ObjectId[]): Promise<VectorStoreDocument[]>;
|
|
|
|
|
createVectorStoreFile(vectorStoreRelation: VectorStoreDocument, pages: PageDocument[]): Promise<void>;
|
|
createVectorStoreFile(vectorStoreRelation: VectorStoreDocument, pages: PageDocument[]): Promise<void>;
|
|
|
createVectorStoreFileOnPageCreate(pages: PageDocument[]): Promise<void>;
|
|
createVectorStoreFileOnPageCreate(pages: PageDocument[]): Promise<void>;
|
|
|
updateVectorStoreFileOnPageUpdate(page: HydratedDocument<PageDocument>): Promise<void>;
|
|
updateVectorStoreFileOnPageUpdate(page: HydratedDocument<PageDocument>): Promise<void>;
|
|
@@ -121,7 +119,7 @@ class OpenaiService implements IOpenaiService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async createThread(userId: string, aiAssistantId: string, initialUserMessage: string): Promise<ThreadRelationDocument> {
|
|
async createThread(userId: string, aiAssistantId: string, initialUserMessage: string): Promise<ThreadRelationDocument> {
|
|
|
- const vectorStoreRelation = await this.getVectorStoreRelation(aiAssistantId);
|
|
|
|
|
|
|
+ const vectorStoreRelation = await this.getVectorStoreRelationByAiAssistantId(aiAssistantId);
|
|
|
|
|
|
|
|
let threadTitle: string | null = null;
|
|
let threadTitle: string | null = null;
|
|
|
if (initialUserMessage != null) {
|
|
if (initialUserMessage != null) {
|
|
@@ -149,7 +147,7 @@ class OpenaiService implements IOpenaiService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async updateThreads(aiAssistantId: string, vectorStoreId: string): Promise<void> {
|
|
async updateThreads(aiAssistantId: string, vectorStoreId: string): Promise<void> {
|
|
|
- const threadRelations = await this.getThreadsByAiAssistant(aiAssistantId);
|
|
|
|
|
|
|
+ const threadRelations = await this.getThreadsByAiAssistantId(aiAssistantId);
|
|
|
for await (const threadRelation of threadRelations) {
|
|
for await (const threadRelation of threadRelations) {
|
|
|
try {
|
|
try {
|
|
|
const updatedThreadResponse = await this.client.updateThread(threadRelation.threadId, vectorStoreId);
|
|
const updatedThreadResponse = await this.client.updateThread(threadRelation.threadId, vectorStoreId);
|
|
@@ -161,7 +159,7 @@ class OpenaiService implements IOpenaiService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- async getThreadsByAiAssistant(aiAssistantId: string): Promise<ThreadRelationDocument[]> {
|
|
|
|
|
|
|
+ async getThreadsByAiAssistantId(aiAssistantId: string): Promise<ThreadRelationDocument[]> {
|
|
|
const threadRelations = await ThreadRelationModel.find({ aiAssistant: aiAssistantId });
|
|
const threadRelations = await ThreadRelationModel.find({ aiAssistant: aiAssistantId });
|
|
|
return threadRelations;
|
|
return threadRelations;
|
|
|
}
|
|
}
|
|
@@ -224,7 +222,7 @@ class OpenaiService implements IOpenaiService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- async getVectorStoreRelation(aiAssistantId: string): Promise<VectorStoreDocument> {
|
|
|
|
|
|
|
+ async getVectorStoreRelationByAiAssistantId(aiAssistantId: string): Promise<VectorStoreDocument> {
|
|
|
const aiAssistant = await AiAssistantModel.findById({ _id: aiAssistantId }).populate('vectorStore');
|
|
const aiAssistant = await AiAssistantModel.findById({ _id: aiAssistantId }).populate('vectorStore');
|
|
|
if (aiAssistant == null) {
|
|
if (aiAssistant == null) {
|
|
|
throw createError(404, 'AiAssistant document does not exist');
|
|
throw createError(404, 'AiAssistant document does not exist');
|