Skip to content
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

model 切り替え時に prompter に応じて systemContext を変更する #386

Merged
merged 3 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/web/src/hooks/useChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,11 @@ const useChat = (id: string, chatId?: string) => {
updateSystemContext: (systemContext: string) => {
updateSystemContext(id, systemContext);
},
updateSystemContextByModel: () => {
const modelId = getModelId(id);
const prompter = getPrompter(modelId);
updateSystemContext(id, prompter.systemContext(id));
},
getCurrentSystemContext: () => {
return getCurrentSystemContext(id);
},
Expand Down
10 changes: 10 additions & 0 deletions packages/web/src/pages/AgentChatPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { create } from 'zustand';
import { ReactComponent as BedrockIcon } from '../assets/bedrock.svg';
import { AgentPageQueryParams } from '../@types/navigate';
import { MODELS } from '../hooks/useModel';
import { getPrompter } from '../prompts';
import { v4 as uuidv4 } from 'uuid';
import queryString from 'query-string';

Expand Down Expand Up @@ -51,11 +52,20 @@ const AgentChatPage: React.FC = () => {
messages,
clear,
postChat,
updateSystemContextByModel,
} = useChat(pathname, chatId);
const { scrollToBottom, scrollToTop } = useScroll();
const { getConversationTitle } = useConversation();
const { agentNames: availableModels } = MODELS;
const modelId = getModelId();
const prompter = useMemo(() => {
return getPrompter(modelId);
}, [modelId]);

useEffect(() => {
updateSystemContextByModel();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [prompter]);

const title = useMemo(() => {
if (chatId) {
Expand Down
9 changes: 9 additions & 0 deletions packages/web/src/pages/ChatPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const ChatPage: React.FC = () => {
clear,
postChat,
updateSystemContext,
updateSystemContextByModel,
getCurrentSystemContext,
} = useChat(pathname, chatId);
const { createShareId, findShareId, deleteShareId } = useChatApi();
Expand All @@ -76,6 +77,14 @@ const ChatPage: React.FC = () => {
return getPrompter(modelId);
}, [modelId]);

useEffect(() => {
// 会話履歴のページではモデルを変更してもシステムコンテキストを変更しない
if (!chatId) {
updateSystemContextByModel();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [prompter]);

const title = useMemo(() => {
if (chatId) {
return getConversationTitle(chatId) || 'チャット';
Expand Down
6 changes: 6 additions & 0 deletions packages/web/src/pages/EditorialPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ const EditorialPage: React.FC = () => {
messages,
postChat,
clear: clearChat,
updateSystemContextByModel,
} = useChat(pathname);
const { modelIds: availableModels } = MODELS;
const modelId = getModelId();
Expand All @@ -97,6 +98,11 @@ const EditorialPage: React.FC = () => {
}, [modelId]);
const [auto, setAuto] = useState(true);

useEffect(() => {
updateSystemContextByModel();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [prompter]);

// Memo 変数
const filterComment = (
_comments: DocumentComment[],
Expand Down
12 changes: 11 additions & 1 deletion packages/web/src/pages/GenerateImagePage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useEffect, useState } from 'react';
import React, { useCallback, useEffect, useState, useMemo } from 'react';
import Card from '../components/Card';
import Button from '../components/Button';
import Textarea from '../components/Textarea';
Expand All @@ -20,6 +20,7 @@ import Base64Image from '../components/Base64Image';
import { AxiosError } from 'axios';
import { GenerateImagePageQueryParams } from '../@types/navigate';
import { MODELS } from '../hooks/useModel';
import { getPrompter } from '../prompts';
import queryString from 'query-string';

const MAX_SAMPLE = 7;
Expand Down Expand Up @@ -234,13 +235,22 @@ const GenerateImagePage: React.FC = () => {
setModelId,
loading: loadingChat,
clear: clearChat,
updateSystemContextByModel,
} = useChat(pathname);

const [generating, setGenerating] = useState(false);
const [isOpenSketch, setIsOpenSketch] = useState(false);
const [selectedImageIndex, setSelectedImageIndex] = useState(0);
const { modelIds, imageGenModelIds, imageGenModels } = MODELS;
const modelId = getModelId();
const prompter = useMemo(() => {
return getPrompter(modelId);
}, [modelId]);

useEffect(() => {
updateSystemContextByModel();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [prompter]);

// LandingPage のデモデータ設定
useEffect(() => {
Expand Down
6 changes: 6 additions & 0 deletions packages/web/src/pages/GenerateTextPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const GenerateTextPage: React.FC = () => {
messages,
postChat,
clear: clearChat,
updateSystemContextByModel,
} = useChat(pathname);
const { setTypingTextInput, typingTextOutput } = useTyping(loading);
const { modelIds: availableModels } = MODELS;
Expand All @@ -79,6 +80,11 @@ const GenerateTextPage: React.FC = () => {
return getPrompter(modelId);
}, [modelId]);

useEffect(() => {
updateSystemContextByModel();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [prompter]);

const disabledExec = useMemo(() => {
return information === '' || loading;
}, [information, loading]);
Expand Down
6 changes: 6 additions & 0 deletions packages/web/src/pages/SummarizePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const SummarizePage: React.FC = () => {
messages,
postChat,
clear: clearChat,
updateSystemContextByModel,
} = useChat(pathname);
const { setTypingTextInput, typingTextOutput } = useTyping(loading);
const { modelIds: availableModels } = MODELS;
Expand All @@ -80,6 +81,11 @@ const SummarizePage: React.FC = () => {
return getPrompter(modelId);
}, [modelId]);

useEffect(() => {
updateSystemContextByModel();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [prompter]);

const disabledExec = useMemo(() => {
return sentence === '' || loading;
}, [sentence, loading]);
Expand Down
6 changes: 6 additions & 0 deletions packages/web/src/pages/TranslatePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ const TranslatePage: React.FC = () => {
messages,
postChat,
clear: clearChat,
updateSystemContextByModel,
} = useChat(pathname);
const { setTypingTextInput, typingTextOutput } = useTyping(loading);
const { modelIds: availableModels } = MODELS;
Expand All @@ -104,6 +105,11 @@ const TranslatePage: React.FC = () => {
}, [modelId]);
const [auto, setAuto] = useState(true);

useEffect(() => {
updateSystemContextByModel();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [prompter]);

// Memo 変数
const disabledExec = useMemo(() => {
return sentence === '' || loading;
Expand Down
6 changes: 6 additions & 0 deletions packages/web/src/pages/WebContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ const WebContent: React.FC = () => {
messages,
postChat,
clear: clearChat,
updateSystemContextByModel,
} = useChat(pathname);
const { setTypingTextInput, typingTextOutput } = useTyping(loading);
const { getWebText } = useChatApi();
Expand All @@ -106,6 +107,11 @@ const WebContent: React.FC = () => {
return getPrompter(modelId);
}, [modelId]);

useEffect(() => {
updateSystemContextByModel();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [prompter]);

const disabledExec = useMemo(() => {
return url === '' || loading || fetching;
}, [url, loading, fetching]);
Expand Down
Loading