Просмотр исходного кода

Set LIMIT_LEARNABLE_PAGE_COUNT as environment variable

Shun Miyazawa 1 год назад
Родитель
Сommit
cfe6be0bdd

+ 3 - 3
apps/app/src/features/openai/client/components/AiAssistant/AiAssistantManagementModal/AiAssistantManagementHome.tsx

@@ -7,11 +7,10 @@ import {
 
 
 import { AiAssistantShareScope, AiAssistantAccessScope } from '~/features/openai/interfaces/ai-assistant';
 import { AiAssistantShareScope, AiAssistantAccessScope } from '~/features/openai/interfaces/ai-assistant';
 import type { PopulatedGrantedGroup } from '~/interfaces/page-grant';
 import type { PopulatedGrantedGroup } from '~/interfaces/page-grant';
-import { useCurrentUser } from '~/stores-universal/context';
+import { useCurrentUser, useLimitLearnablePageCount } from '~/stores-universal/context';
 
 
 import type { SelectedPage } from '../../../../interfaces/selected-page';
 import type { SelectedPage } from '../../../../interfaces/selected-page';
 import { determineShareScope } from '../../../../utils/determine-share-scope';
 import { determineShareScope } from '../../../../utils/determine-share-scope';
-import { isLearnablePageLimitExceeded } from '../../../../utils/is-learnable-page-limit-exceeded';
 import { useAiAssistantManagementModal, AiAssistantManagementModalPageMode } from '../../../stores/ai-assistant';
 import { useAiAssistantManagementModal, AiAssistantManagementModalPageMode } from '../../../stores/ai-assistant';
 
 
 import { ShareScopeWarningModal } from './ShareScopeWarningModal';
 import { ShareScopeWarningModal } from './ShareScopeWarningModal';
@@ -49,6 +48,7 @@ export const AiAssistantManagementHome = (props: Props): JSX.Element => {
 
 
   const { t } = useTranslation();
   const { t } = useTranslation();
   const { data: currentUser } = useCurrentUser();
   const { data: currentUser } = useCurrentUser();
+  const { data: limitLearnablePageCount } = useLimitLearnablePageCount();
   const { close: closeAiAssistantManagementModal, changePageMode } = useAiAssistantManagementModal();
   const { close: closeAiAssistantManagementModal, changePageMode } = useAiAssistantManagementModal();
 
 
   const [isShareScopeWarningModalOpen, setIsShareScopeWarningModalOpen] = useState(false);
   const [isShareScopeWarningModalOpen, setIsShareScopeWarningModalOpen] = useState(false);
@@ -70,7 +70,7 @@ export const AiAssistantManagementHome = (props: Props): JSX.Element => {
       : t(baseLabel);
       : t(baseLabel);
   }, [currentUser?.username, t]);
   }, [currentUser?.username, t]);
 
 
-  const canUpsert = name !== '' && selectedPages.length !== 0 && !isLearnablePageLimitExceeded(totalSelectedPageCount);
+  const canUpsert = name !== '' && selectedPages.length !== 0 && (limitLearnablePageCount ?? 3000) >= totalSelectedPageCount;
 
 
   const upsertAiAssistantHandler = useCallback(async() => {
   const upsertAiAssistantHandler = useCallback(async() => {
     const shouldWarning = () => {
     const shouldWarning = () => {

+ 0 - 3
apps/app/src/features/openai/interfaces/ai-assistant.ts

@@ -4,9 +4,6 @@ import type {
 
 
 import type { IVectorStore } from './vector-store';
 import type { IVectorStore } from './vector-store';
 
 
-
-export const LIMIT_LEARNABLE_PAGE_COUNT = 5;
-
 /*
 /*
 *  Objects
 *  Objects
 */
 */

+ 2 - 2
apps/app/src/features/openai/server/services/openai.ts

@@ -33,7 +33,6 @@ import {
   type AccessibleAiAssistants, type AiAssistant, AiAssistantAccessScope, AiAssistantShareScope,
   type AccessibleAiAssistants, type AiAssistant, AiAssistantAccessScope, AiAssistantShareScope,
 } from '../../interfaces/ai-assistant';
 } from '../../interfaces/ai-assistant';
 import type { MessageListParams } from '../../interfaces/message';
 import type { MessageListParams } from '../../interfaces/message';
-import { isLearnablePageLimitExceeded as _isLearnablePageLimitExceeded } from '../../utils/is-learnable-page-limit-exceeded';
 import { removeGlobPath } from '../../utils/remove-glob-path';
 import { removeGlobPath } from '../../utils/remove-glob-path';
 import AiAssistantModel, { type AiAssistantDocument } from '../models/ai-assistant';
 import AiAssistantModel, { type AiAssistantDocument } from '../models/ai-assistant';
 import { convertMarkdownToHtml } from '../utils/convert-markdown-to-html';
 import { convertMarkdownToHtml } from '../utils/convert-markdown-to-html';
@@ -984,7 +983,8 @@ class OpenaiService implements IOpenaiService {
 
 
     logger.debug('TotalPageCount: ', totalPageCount);
     logger.debug('TotalPageCount: ', totalPageCount);
 
 
-    return _isLearnablePageLimitExceeded(totalPageCount);
+    const limitLearnablePageCount = configManager.getConfig('openai:limitLearnablePageCount');
+    return totalPageCount > limitLearnablePageCount;
   }
   }
 
 
 }
 }

+ 0 - 5
apps/app/src/features/openai/utils/is-learnable-page-limit-exceeded.ts

@@ -1,5 +0,0 @@
-import { LIMIT_LEARNABLE_PAGE_COUNT } from '../interfaces/ai-assistant';
-
-export const isLearnablePageLimitExceeded = (totalPageCount: number): boolean => {
-  return totalPageCount > LIMIT_LEARNABLE_PAGE_COUNT;
-};

+ 4 - 1
apps/app/src/pages/[[...path]].page.tsx

@@ -46,7 +46,7 @@ import {
   useElasticsearchMaxBodyLengthToIndex,
   useElasticsearchMaxBodyLengthToIndex,
   useIsLocalAccountRegistrationEnabled,
   useIsLocalAccountRegistrationEnabled,
   useIsRomUserAllowedToComment,
   useIsRomUserAllowedToComment,
-  useIsAiEnabled,
+  useIsAiEnabled, useLimitLearnablePageCount,
 } from '~/stores-universal/context';
 } from '~/stores-universal/context';
 import { useEditingMarkdown } from '~/stores/editor';
 import { useEditingMarkdown } from '~/stores/editor';
 import {
 import {
@@ -195,6 +195,7 @@ type Props = CommonProps & {
   rendererConfig: RendererConfig,
   rendererConfig: RendererConfig,
 
 
   aiEnabled: boolean,
   aiEnabled: boolean,
+  limitLearnablePageCount: number,
 };
 };
 
 
 const Page: NextPageWithLayout<Props> = (props: Props) => {
 const Page: NextPageWithLayout<Props> = (props: Props) => {
@@ -248,6 +249,7 @@ const Page: NextPageWithLayout<Props> = (props: Props) => {
   useIsRomUserAllowedToComment(props.isRomUserAllowedToComment);
   useIsRomUserAllowedToComment(props.isRomUserAllowedToComment);
 
 
   useIsAiEnabled(props.aiEnabled);
   useIsAiEnabled(props.aiEnabled);
+  useLimitLearnablePageCount(props.limitLearnablePageCount);
 
 
   const { pageWithMeta } = props;
   const { pageWithMeta } = props;
 
 
@@ -566,6 +568,7 @@ function injectServerConfigurations(context: GetServerSidePropsContext, props: P
   } = crowi;
   } = crowi;
 
 
   props.aiEnabled = configManager.getConfig('app:aiEnabled');
   props.aiEnabled = configManager.getConfig('app:aiEnabled');
+  props.limitLearnablePageCount = configManager.getConfig('openai:limitLearnablePageCount');
 
 
   props.isSearchServiceConfigured = searchService.isConfigured;
   props.isSearchServiceConfigured = searchService.isConfigured;
   props.isSearchServiceReachable = searchService.isReachable;
   props.isSearchServiceReachable = searchService.isReachable;

+ 5 - 0
apps/app/src/server/service/config-manager/config-definition.ts

@@ -260,6 +260,7 @@ export const CONFIG_KEYS = [
   'openai:vectorStoreFileDeletionCronExpression',
   'openai:vectorStoreFileDeletionCronExpression',
   'openai:vectorStoreFileDeletionBarchSize',
   'openai:vectorStoreFileDeletionBarchSize',
   'openai:vectorStoreFileDeletionApiCallInterval',
   'openai:vectorStoreFileDeletionApiCallInterval',
+  'openai:limitLearnablePageCount',
 
 
   // OpenTelemetry Settings
   // OpenTelemetry Settings
   'otel:enabled',
   'otel:enabled',
@@ -1125,6 +1126,10 @@ Guideline as a RAG:
     envVarName: 'OPENAI_SEARCH_ASSISTANT_INSTRUCTIONS',
     envVarName: 'OPENAI_SEARCH_ASSISTANT_INSTRUCTIONS',
     defaultValue: '',
     defaultValue: '',
   }),
   }),
+  'openai:limitLearnablePageCount': defineConfig<number>({
+    envVarName: 'OPENAI_LIMIT_LEARNABLE_PAGE_COUNT',
+    defaultValue: 3000,
+  }),
 
 
   // OpenTelemetry Settings
   // OpenTelemetry Settings
   'otel:enabled': defineConfig<boolean>({
   'otel:enabled': defineConfig<boolean>({

+ 4 - 0
apps/app/src/stores-universal/context.tsx

@@ -208,6 +208,10 @@ export const useIsAiEnabled = (initialData?: boolean): SWRResponse<boolean, Erro
   return useContextSWR('isAiEnabled', initialData);
   return useContextSWR('isAiEnabled', initialData);
 };
 };
 
 
+export const useLimitLearnablePageCount = (initialData?: number): SWRResponse<number, Error> => {
+  return useContextSWR('limitLearnablePageCount', initialData);
+};
+
 /** **********************************************************
 /** **********************************************************
  *                     Computed contexts
  *                     Computed contexts
  *********************************************************** */
  *********************************************************** */