From 86884b81f1f7f63ed98d7a5c67099c24a8ef9ae4 Mon Sep 17 00:00:00 2001 From: Taichiro Suzuki Date: Tue, 3 Dec 2024 12:53:32 +0900 Subject: [PATCH] fix --- .../useCaseBuilderRepository.ts | 4 +- packages/types/src/useCaseBuilder.d.ts | 1 + .../useCaseBuilder/UseCaseBuilderView.tsx | 30 +++++--- .../src/hooks/useCaseBuilder/useMyUseCases.ts | 3 + .../useCaseBuilder/UseCaseBuilderEditPage.tsx | 73 ++++++++++++++++++- .../UseCaseBuilderExecutePage.tsx | 1 + .../UseCaseBuilderMyUseCasePage.tsx | 2 +- 7 files changed, 99 insertions(+), 15 deletions(-) diff --git a/packages/cdk/lambda/useCaseBuilder/useCaseBuilderRepository.ts b/packages/cdk/lambda/useCaseBuilder/useCaseBuilderRepository.ts index 44d81d71..c3473d96 100644 --- a/packages/cdk/lambda/useCaseBuilder/useCaseBuilderRepository.ts +++ b/packages/cdk/lambda/useCaseBuilder/useCaseBuilderRepository.ts @@ -156,6 +156,7 @@ export const createUseCase = async ( description: content.description, promptTemplate: content.promptTemplate, inputExamples: content.inputExamples, + fixedModelId: content.fixedModelId, isShared: false, }; @@ -257,12 +258,13 @@ export const updateUseCase = async ( dataType: useCaseInTable.dataType, }, UpdateExpression: - 'set title = :title, promptTemplate = :promptTemplate, description = :description, inputExamples = :inputExamples', + 'set title = :title, promptTemplate = :promptTemplate, description = :description, inputExamples = :inputExamples, fixedModelId = :fixedModelId', ExpressionAttributeValues: { ':title': content.title, ':promptTemplate': content.promptTemplate, ':description': content.description ?? '', ':inputExamples': content.inputExamples ?? [], + ':fixedModelId': content.fixedModelId ?? '', }, }) ); diff --git a/packages/types/src/useCaseBuilder.d.ts b/packages/types/src/useCaseBuilder.d.ts index dfbe244b..e304f602 100644 --- a/packages/types/src/useCaseBuilder.d.ts +++ b/packages/types/src/useCaseBuilder.d.ts @@ -18,6 +18,7 @@ export type UseCaseContent = { description?: string; promptTemplate: string; inputExamples?: UseCaseInputExample[]; + fixedModelId?: string; }; // Table に記録されている内容 diff --git a/packages/web/src/components/useCaseBuilder/UseCaseBuilderView.tsx b/packages/web/src/components/useCaseBuilder/UseCaseBuilderView.tsx index 4803c994..cbbc1091 100644 --- a/packages/web/src/components/useCaseBuilder/UseCaseBuilderView.tsx +++ b/packages/web/src/components/useCaseBuilder/UseCaseBuilderView.tsx @@ -28,6 +28,7 @@ type Props = { promptTemplate: string; description?: string; inputExamples?: UseCaseInputExample[]; + fixedModelId: string; isLoading?: boolean; } & ( | { @@ -93,7 +94,13 @@ const UseCaseBuilderView: React.FC = (props) => { postChat, clear: clearChat, } = useChat(pathname); - const modelId = getModelId(); + const modelId = useMemo(() => { + if (props.fixedModelId !== '') { + return props.fixedModelId; + } else { + return getModelId(); + } + }, [getModelId, props.fixedModelId]); const { modelIds: availableModels } = MODELS; const { setTypingTextInput, typingTextOutput } = useTyping(loading); const { updateRecentUseUseCase } = useMyUseCases(); @@ -214,15 +221,18 @@ const UseCaseBuilderView: React.FC = (props) => {
{props.description}
)} -
- { + return { value: m, label: m }; + })} + /> +
+ )} + {props.isLoading && (
diff --git a/packages/web/src/hooks/useCaseBuilder/useMyUseCases.ts b/packages/web/src/hooks/useCaseBuilder/useMyUseCases.ts index 92341fed..85abec87 100644 --- a/packages/web/src/hooks/useCaseBuilder/useMyUseCases.ts +++ b/packages/web/src/hooks/useCaseBuilder/useMyUseCases.ts @@ -50,6 +50,7 @@ const useMyUseCases = () => { promptTemplate: string; description?: string; inputExamples?: UseCaseInputExample[]; + fixedModelId?: string; }) => { return createUseCase(params).finally(() => { mutateMyUseCases(); @@ -61,6 +62,7 @@ const useMyUseCases = () => { promptTemplate: string; description?: string; inputExamples?: UseCaseInputExample[]; + fixedModelId?: string; }) => { // 一覧の更新 const index = findIndex(params.useCaseId); @@ -80,6 +82,7 @@ const useMyUseCases = () => { promptTemplate: params.promptTemplate, description: params.description, inputExamples: params.inputExamples, + fixedModelId: params.fixedModelId, }).finally(() => { mutateMyUseCases(); mutateFavoriteUseCases(); diff --git a/packages/web/src/pages/useCaseBuilder/UseCaseBuilderEditPage.tsx b/packages/web/src/pages/useCaseBuilder/UseCaseBuilderEditPage.tsx index d13f8edb..1677afb9 100644 --- a/packages/web/src/pages/useCaseBuilder/UseCaseBuilderEditPage.tsx +++ b/packages/web/src/pages/useCaseBuilder/UseCaseBuilderEditPage.tsx @@ -23,6 +23,9 @@ import { getItemsFromPlaceholders, } from '../../utils/UseCaseBuilderUtils'; import usePageTitle from '../../hooks/usePageTitle'; +import Select from '../../components/Select'; +import Switch from '../../components/Switch'; +import { MODELS } from '../../hooks/useModel'; type StateType = { useCaseId: string | null; @@ -38,6 +41,8 @@ type StateType = { removeInputExample: (index: number) => void; setInputExample: (index: number, inputExample: UseCaseInputExample) => void; setInputExamples: (inputExamples: UseCaseInputExample[]) => void; + fixedModelId: string; + setFixedModelId: (m: string) => void; clear: () => void; }; @@ -47,6 +52,7 @@ const useUseCaseBuilderEditPageState = create((set, get) => { description: '', promptTemplate: '', inputExamples: [], + fixedModelId: '', }; return { ...INIT_STATE, @@ -97,6 +103,11 @@ const useUseCaseBuilderEditPageState = create((set, get) => { inputExamples: inputExamples, })); }, + setFixedModelId: (m: string) => { + set(() => ({ + fixedModelId: m, + })); + }, clear: () => { set(INIT_STATE); }, @@ -122,10 +133,13 @@ const UseCaseBuilderEditPage: React.FC = () => { setInputExample, setInputExamples, removeInputExample, + fixedModelId, + setFixedModelId, clear, } = useUseCaseBuilderEditPageState(); const { useCase, isLoading } = useUseCase(useCaseId ?? useCaseIdPathParam); + const { createUseCase, updateUseCase, @@ -135,14 +149,13 @@ const UseCaseBuilderEditPage: React.FC = () => { const { setPageTitle } = usePageTitle(); const [isDisabledUpdate, setIsDisabledUpdate] = useState(false); - const [isOpenDeleteDialog, setIsOpenDeleteDialog] = useState(false); const [isDeleting, setIsDeleting] = useState(false); - const [isPosting, setIsPosting] = useState(false); - const [isOpen, setIsOpen] = useState(false); + const { modelIds: availableModels } = MODELS; + useEffect(() => { // 初期表示時にIDを設定する setUseCaseId(useCaseIdPathParam ?? null); @@ -156,6 +169,7 @@ const UseCaseBuilderEditPage: React.FC = () => { setPromptTemplate(useCase?.promptTemplate ?? ''); setDescription(useCase?.description ?? ''); setInputExamples(useCase?.inputExamples ?? []); + setFixedModelId(useCase?.fixedModelId ?? ''); // サンプル集から遷移した場合(RouterのStateから設定) } else if (state) { @@ -163,6 +177,7 @@ const UseCaseBuilderEditPage: React.FC = () => { setPromptTemplate(state.promptTemplate ?? ''); setDescription(state.description ?? ''); setInputExamples(state.inputExamples ?? []); + setFixedModelId(state.fixedModelId ?? ''); } else { clear(); } @@ -216,6 +231,7 @@ const UseCaseBuilderEditPage: React.FC = () => { promptTemplate, description: description === '' ? undefined : description, inputExamples, + fixedModelId, }) .then(() => { // DB変更直後は更新ボタンをDisabledにする @@ -230,6 +246,7 @@ const UseCaseBuilderEditPage: React.FC = () => { promptTemplate, description: description === '' ? undefined : description, inputExamples, + fixedModelId, }) .then(async (res) => { setUseCaseId(res.useCaseId); @@ -256,6 +273,7 @@ const UseCaseBuilderEditPage: React.FC = () => { updateRecentUseUseCase, updateUseCase, useCaseId, + fixedModelId, ]); const onClickDelete = useCallback(() => { @@ -445,6 +463,54 @@ const UseCaseBuilderEditPage: React.FC = () => {
+ +
+ { + if (fixedModelId !== '') { + setFixedModelId(''); + } else { + setFixedModelId(availableModels[0]); + } + setIsDisabledUpdate(false); + }} + /> + + {fixedModelId !== '' && ( +