Sfoglia il codice sorgente

Simplify singletonI export

Shun Miyazawa 1 anno fa
parent
commit
5f3b4eb068

+ 0 - 4
apps/app/src/server/crowi/index.js

@@ -14,7 +14,6 @@ import { KeycloakUserGroupSyncService } from '~/features/external-user-group/ser
 import { LdapUserGroupSyncService } from '~/features/external-user-group/server/service/ldap-user-group-sync';
 import QuestionnaireService from '~/features/questionnaire/server/service/questionnaire';
 import QuestionnaireCronService from '~/features/questionnaire/server/service/questionnaire-cron';
-import { initializeOpenaiService } from '~/server/service/openai/openai';
 import loggerFactory from '~/utils/logger';
 import { projectRoot } from '~/utils/project-dir-utils';
 
@@ -487,9 +486,6 @@ Crowi.prototype.start = async function() {
   // Execute this asynchronously after the express server is ready so it does not block the ongoing process
   this.asyncAfterExpressServerReady();
 
-  // initialize OpenAI service
-  initializeOpenaiService();
-
   return serverListening;
 };
 

+ 1 - 2
apps/app/src/server/routes/apiv3/openai/rebuild-vector-store.ts

@@ -4,7 +4,7 @@ import type { ValidationChain } from 'express-validator';
 
 import type Crowi from '~/server/crowi';
 import { certifyAiService } from '~/server/middlewares/certify-ai-service';
-import { getOpenaiService } from '~/server/service/openai/openai';
+import { openaiService } from '~/server/service/openai/openai';
 import loggerFactory from '~/utils/logger';
 
 import { apiV3FormValidator } from '../../../middlewares/apiv3-form-validator';
@@ -28,7 +28,6 @@ export const rebuildVectorStoreHandlersFactory: RebuildVectorStoreFactory = (cro
     async(req: Request, res: ApiV3Response) => {
 
       try {
-        const openaiService = getOpenaiService();
         await openaiService.rebuildVectorStore();
         return res.apiv3({});
 

+ 1 - 25
apps/app/src/server/service/openai/openai.ts

@@ -1,5 +1,3 @@
-import { configManager } from '~/server/service/config-manager';
-
 import OpenaiClient from './openai-client-delegator';
 
 export interface IOpenaiService {
@@ -30,26 +28,4 @@ class OpenaiService implements IOpenaiService {
 
 }
 
-let _instance: OpenaiService;
-
-export const initializeOpenaiService = (): void => {
-  const aiEnabled = configManager.getConfig('crowi', 'app:aiEnabled');
-
-  if (!aiEnabled) {
-    return;
-  }
-
-  if (_instance != null) {
-    throw new Error('OpenaiService is already initialized');
-  }
-
-  _instance = new OpenaiService();
-};
-
-export const getOpenaiService = (): OpenaiService => {
-  if (_instance == null) {
-    throw new Error('OpenaiService is not initialized yet');
-  }
-
-  return _instance;
-};
+export const openaiService = new OpenaiService();