|
|
@@ -35,7 +35,6 @@ import AiAssistantModel, { type AiAssistantDocument } from '../models/ai-assista
|
|
|
import { convertMarkdownToHtml } from '../utils/convert-markdown-to-html';
|
|
|
|
|
|
import { getClient } from './client-delegator';
|
|
|
-// import { splitMarkdownIntoChunks } from './markdown-splitter/markdown-token-splitter';
|
|
|
import { openaiApiErrorHandler } from './openai-api-error-handler';
|
|
|
import { replaceAnnotationWithPageLink } from './replace-annotation-with-page-link';
|
|
|
|
|
|
@@ -45,7 +44,6 @@ const BATCH_SIZE = 100;
|
|
|
|
|
|
const logger = loggerFactory('growi:service:openai');
|
|
|
|
|
|
-// const isVectorStoreForPublicScopeExist = false;
|
|
|
|
|
|
type VectorStoreFileRelationsMap = Map<string, VectorStoreFileRelation>
|
|
|
|
|
|
@@ -233,38 +231,6 @@ class OpenaiService implements IOpenaiService {
|
|
|
return messages;
|
|
|
}
|
|
|
|
|
|
- // TODO: https://redmine.weseek.co.jp/issues/160332
|
|
|
- // public async getOrCreateVectorStoreForPublicScope(): Promise<VectorStoreDocument> {
|
|
|
- // const vectorStoreDocument: VectorStoreDocument | null = await VectorStoreModel.findOne({ scopeType: VectorStoreScopeType.PUBLIC, isDeleted: false });
|
|
|
-
|
|
|
- // if (vectorStoreDocument != null && isVectorStoreForPublicScopeExist) {
|
|
|
- // return vectorStoreDocument;
|
|
|
- // }
|
|
|
-
|
|
|
- // if (vectorStoreDocument != null && !isVectorStoreForPublicScopeExist) {
|
|
|
- // try {
|
|
|
- // // Check if vector store entity exists
|
|
|
- // // If the vector store entity does not exist, the vector store document is deleted
|
|
|
- // await this.client.retrieveVectorStore(vectorStoreDocument.vectorStoreId);
|
|
|
- // isVectorStoreForPublicScopeExist = true;
|
|
|
- // return vectorStoreDocument;
|
|
|
- // }
|
|
|
- // catch (err) {
|
|
|
- // await oepnaiApiErrorHandler(err, { notFoundError: vectorStoreDocument.markAsDeleted });
|
|
|
- // throw new Error(err);
|
|
|
- // }
|
|
|
- // }
|
|
|
-
|
|
|
- // const newVectorStore = await this.client.createVectorStore(VectorStoreScopeType.PUBLIC);
|
|
|
- // const newVectorStoreDocument = await VectorStoreModel.create({
|
|
|
- // vectorStoreId: newVectorStore.id,
|
|
|
- // scopeType: VectorStoreScopeType.PUBLIC,
|
|
|
- // }) as VectorStoreDocument;
|
|
|
-
|
|
|
- // isVectorStoreForPublicScopeExist = true;
|
|
|
-
|
|
|
- // return newVectorStoreDocument;
|
|
|
- // }
|
|
|
|
|
|
async getVectorStoreRelation(aiAssistantId: string): Promise<VectorStoreDocument> {
|
|
|
const aiAssistant = await AiAssistantModel.findById({ _id: aiAssistantId }).populate('vectorStore');
|
|
|
@@ -344,22 +310,6 @@ class OpenaiService implements IOpenaiService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // TODO: https://redmine.weseek.co.jp/issues/160332
|
|
|
- // TODO: https://redmine.weseek.co.jp/issues/156643
|
|
|
- // private async uploadFileByChunks(pageId: Types.ObjectId, body: string, vectorStoreFileRelationsMap: VectorStoreFileRelationsMap) {
|
|
|
- // const chunks = await splitMarkdownIntoChunks(body, 'gpt-4o');
|
|
|
- // for await (const [index, chunk] of chunks.entries()) {
|
|
|
- // try {
|
|
|
- // const file = await toFile(Readable.from(chunk), `${pageId}-chunk-${index}.md`);
|
|
|
- // const uploadedFile = await this.client.uploadFile(file);
|
|
|
- // prepareVectorStoreFileRelations(pageId, uploadedFile.id, vectorStoreFileRelationsMap);
|
|
|
- // }
|
|
|
- // catch (err) {
|
|
|
- // logger.error(err);
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
-
|
|
|
private async uploadFile(pageId: Types.ObjectId, pagePath: string, revisionBody: string): Promise<OpenAI.Files.FileObject> {
|
|
|
const convertedHtml = await convertMarkdownToHtml({ pagePath, revisionBody });
|
|
|
const file = await toFile(Readable.from(convertedHtml), `${pageId}.html`);
|
|
|
@@ -542,28 +492,6 @@ class OpenaiService implements IOpenaiService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // TODO: https://redmine.weseek.co.jp/issues/160332
|
|
|
- // async rebuildVectorStoreAll() {
|
|
|
- // await this.deleteVectorStore(VectorStoreScopeType.PUBLIC);
|
|
|
-
|
|
|
- // // Create all public pages VectorStoreFile
|
|
|
- // const Page = mongoose.model<HydratedDocument<PageDocument>, PageModel>('Page');
|
|
|
- // const pagesStream = Page.find({ grant: PageGrant.GRANT_PUBLIC }).populate('revision').cursor({ batch_size: BATCH_SIZE });
|
|
|
- // const batchStrem = createBatchStream(BATCH_SIZE);
|
|
|
-
|
|
|
- // const createVectorStoreFile = this.createVectorStoreFile.bind(this);
|
|
|
- // const createVectorStoreFileStream = new Transform({
|
|
|
- // objectMode: true,
|
|
|
- // async transform(chunk: HydratedDocument<PageDocument>[], encoding, callback) {
|
|
|
- // await createVectorStoreFile(chunk);
|
|
|
- // this.push(chunk);
|
|
|
- // callback();
|
|
|
- // },
|
|
|
- // });
|
|
|
-
|
|
|
- // await pipeline(pagesStream, batchStrem, createVectorStoreFileStream);
|
|
|
- // }
|
|
|
-
|
|
|
async filterPagesByAccessScope(aiAssistant: AiAssistantDocument, pages: HydratedDocument<PageDocument>[]) {
|
|
|
const isPublicPage = (page :HydratedDocument<PageDocument>) => page.grant === PageGrant.GRANT_PUBLIC;
|
|
|
|