-
Notifications
You must be signed in to change notification settings - Fork 220
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
feat: Implement api for rebuilding Vector Store #9133
Changes from 8 commits
125062a
08b9825
276e703
1adcc3e
db45ae6
c741e76
c9dbe92
c7ebe3c
bfba698
c8e545e
30dccbf
3b8f19b
3465b56
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { useCallback } from 'react'; | ||
|
||
import { useTranslation } from 'react-i18next'; | ||
|
||
import { apiv3Put } from '~/client/util/apiv3-client'; | ||
import { toastSuccess, toastError } from '~/client/util/toastr'; | ||
|
||
|
||
export const AiIntegration = (): JSX.Element => { | ||
const { t } = useTranslation('admin'); | ||
|
||
const clickRebuildVectorStoreButtonHandler = useCallback(async() => { | ||
try { | ||
await apiv3Put('/ai-integration/rebuild-vector-store'); | ||
toastSuccess(t('ai_integration.rebuild_vector_store_succeeded')); | ||
} | ||
catch { | ||
toastError(t('ai_integration.rebuild_vector_store_failed')); | ||
} | ||
}, [t]); | ||
|
||
return ( | ||
<div data-testid="admin-ai-integration"> | ||
<h2 className="admin-setting-header">{ t('ai_integration.ai_search_management') }</h2> | ||
|
||
<div className="row"> | ||
<label className="col-md-3 col-form-label text-start text-md-end">{ t('ai_integration.rebuild_vector_store_label') }</label> | ||
<div className="col-md-8"> | ||
{/* TODO: https://redmine.weseek.co.jp/issues/153978 */} | ||
<button | ||
type="submit" | ||
className="btn btn-primary" | ||
onClick={clickRebuildVectorStoreButtonHandler} | ||
> | ||
{t('ai_integration.rebuild_vector_store')} | ||
</button> | ||
|
||
<p className="form-text text-muted"> | ||
{t('ai_integration.rebuild_vector_store_explanation1')}<br /> | ||
{t('ai_integration.rebuild_vector_store_explanation2')}<br /> | ||
</p> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const AiServiceType = { | ||
OPEN_AI: 'openai', | ||
} as const; | ||
|
||
export const aiServiceTypes = Object.values(AiServiceType); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import type { NextFunction, Request, Response } from 'express'; | ||
|
||
import { aiServiceTypes } from '~/interfaces/ai'; | ||
import { configManager } from '~/server/service/config-manager'; | ||
import loggerFactory from '~/utils/logger'; | ||
|
||
const logger = loggerFactory('growi:middlewares:certify-ai-service'); | ||
|
||
export const certifyAiService = (req: Request, res: Response & { apiv3Err }, next: NextFunction): void => { | ||
const aiEnabled = configManager.getConfig('crowi', 'app:aiEnabled'); | ||
const aiServiceType = configManager.getConfig('crowi', 'app:aiServiceType'); | ||
|
||
if (!aiEnabled) { | ||
const message = 'AI_ENABLED is not true'; | ||
logger.error(message); | ||
return res.apiv3Err(message, 400); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 403 かなあ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 修正しました |
||
} | ||
|
||
if (aiServiceType == null || !aiServiceTypes.includes(aiServiceType)) { | ||
const message = 'AI_SERVICE_TYPE is missing or contains an invalid value'; | ||
logger.error(message); | ||
return res.apiv3Err(message, 400); | ||
} | ||
|
||
next(); | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AI 機能が利用可能かどうかを判断するための express middleware |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import express from 'express'; | ||
|
||
import { chatHandlersFactory } from './chat'; | ||
import { rebuildVectorStoreHandlersFactory } from './rebuild-vector-store'; | ||
|
||
const router = express.Router(); | ||
|
||
module.exports = (crowi) => { | ||
router.post('/chat', chatHandlersFactory(crowi)); | ||
router.put('/rebuild-vector-store', rebuildVectorStoreHandlersFactory(crowi)); | ||
return router; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { Request, RequestHandler } from 'express'; | ||
import type { ValidationChain } from 'express-validator'; | ||
|
||
import type Crowi from '~/server/crowi'; | ||
import { certifyAiService } from '~/server/middlewares/certify-ai-service'; | ||
import loggerFactory from '~/utils/logger'; | ||
|
||
import { apiV3FormValidator } from '../../../middlewares/apiv3-form-validator'; | ||
import type { ApiV3Response } from '../interfaces/apiv3-response'; | ||
|
||
const logger = loggerFactory('growi:routes:apiv3:ai-integration:rebuild-vector-store'); | ||
|
||
type RebuildVectorStoreFactory = (crowi: Crowi) => RequestHandler[]; | ||
|
||
export const rebuildVectorStoreHandlersFactory: RebuildVectorStoreFactory = (crowi) => { | ||
const accessTokenParser = require('~/server/middlewares/access-token-parser')(crowi); | ||
const loginRequiredStrictly = require('~/server/middlewares/login-required')(crowi); | ||
const adminRequired = require('~/server/middlewares/admin-required')(crowi); | ||
|
||
const validator: ValidationChain[] = [ | ||
// | ||
]; | ||
|
||
return [ | ||
accessTokenParser, loginRequiredStrictly, adminRequired, certifyAiService, validator, apiV3FormValidator, | ||
async(req: Request, res: ApiV3Response) => { | ||
return res.apiv3({}); | ||
}, | ||
]; | ||
}; |
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.
クリック時に表示するメッセージは成功可否ではなく「リビルドを受け付けた」という内容ではないか?
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.
修正しました