-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
42 changed files
with
1,157 additions
and
469 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
7 changes: 3 additions & 4 deletions
7
apps/app/src/features/openai/server/models/thread-relation.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
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 |
---|---|---|
@@ -1,18 +1,36 @@ | ||
import { ErrorV3 } from '@growi/core/dist/models'; | ||
import express from 'express'; | ||
|
||
import { postMessageHandlersFactory } from './message'; | ||
import { rebuildVectorStoreHandlersFactory } from './rebuild-vector-store'; | ||
import { createThreadHandlersFactory } from './thread'; | ||
import type Crowi from '~/server/crowi'; | ||
import type { ApiV3Response } from '~/server/routes/apiv3/interfaces/apiv3-response'; | ||
|
||
import { isAiEnabled } from '../services'; | ||
|
||
const router = express.Router(); | ||
|
||
module.exports = (crowi) => { | ||
router.post('/rebuild-vector-store', rebuildVectorStoreHandlersFactory(crowi)); | ||
|
||
// create thread | ||
router.post('/thread', createThreadHandlersFactory(crowi)); | ||
// post message and return streaming with SSE | ||
router.post('/message', postMessageHandlersFactory(crowi)); | ||
export const factory = (crowi: Crowi): express.Router => { | ||
|
||
// disable all routes if AI is not enabled | ||
if (!isAiEnabled()) { | ||
router.all('*', (req, res: ApiV3Response) => { | ||
return res.apiv3Err(new ErrorV3('GROWI AI is not enabled'), 501); | ||
}); | ||
} | ||
// enabled | ||
else { | ||
import('./rebuild-vector-store').then(({ rebuildVectorStoreHandlersFactory }) => { | ||
router.post('/rebuild-vector-store', rebuildVectorStoreHandlersFactory(crowi)); | ||
}); | ||
|
||
import('./thread').then(({ createThreadHandlersFactory }) => { | ||
router.post('/thread', createThreadHandlersFactory(crowi)); | ||
}); | ||
|
||
import('./message').then(({ postMessageHandlersFactory }) => { | ||
router.post('/message', postMessageHandlersFactory(crowi)); | ||
}); | ||
} | ||
|
||
return router; | ||
}; |
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
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
20 changes: 20 additions & 0 deletions
20
apps/app/src/features/openai/server/services/cron/index.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,20 @@ | ||
import loggerFactory from '~/utils/logger'; | ||
|
||
import { isAiEnabled } from '../is-ai-enabled'; | ||
|
||
|
||
const logger = loggerFactory('growi:openai:service:cron'); | ||
|
||
export const startCronIfEnabled = async(): Promise<void> => { | ||
if (isAiEnabled()) { | ||
logger.info('Starting cron service for thread deletion'); | ||
const { ThreadDeletionCronService } = await import('./thread-deletion-cron'); | ||
const threadDeletionCronService = new ThreadDeletionCronService(); | ||
threadDeletionCronService.startCron(); | ||
|
||
logger.info('Starting cron service for vector store file deletion'); | ||
const { VectorStoreFileDeletionCronService } = await import('./vector-store-file-deletion-cron'); | ||
const vectorStoreFileDeletionCronService = new VectorStoreFileDeletionCronService(); | ||
vectorStoreFileDeletionCronService.startCron(); | ||
} | ||
}; |
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
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
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 |
---|---|---|
@@ -1,2 +1 @@ | ||
export * from './embeddings'; | ||
export * from './client'; | ||
export * from './is-ai-enabled'; |
3 changes: 3 additions & 0 deletions
3
apps/app/src/features/openai/server/services/is-ai-enabled.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,3 @@ | ||
import { configManager } from '~/server/service/config-manager'; | ||
|
||
export const isAiEnabled = (): boolean => configManager.getConfig('crowi', 'app:aiEnabled'); |
1 change: 1 addition & 0 deletions
1
apps/app/src/features/openai/server/services/normalize-data/index.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 @@ | ||
export * from './normalize-thread-relation-expired-at'; |
1 change: 1 addition & 0 deletions
1
...tures/openai/server/services/normalize-data/normalize-thread-relation-expired-at/index.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 @@ | ||
export * from './normalize-thread-relation-expired-at'; |
Oops, something went wrong.