Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tbrandaws committed Mar 12, 2024
1 parent 6161458 commit feef2bc
Show file tree
Hide file tree
Showing 11 changed files with 798 additions and 0 deletions.
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
6 changes: 6 additions & 0 deletions packages/web/src/pages/AgentChatPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,18 @@ 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();

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

const title = useMemo(() => {
if (chatId) {
return getConversationTitle(chatId) || 'Agent チャット';
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
}, [modelId]);

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
}, [modelId]);

// Memo 変数
const filterComment = (
_comments: DocumentComment[],
Expand Down
6 changes: 6 additions & 0 deletions packages/web/src/pages/GenerateImagePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ const GenerateImagePage: React.FC = () => {
setModelId,
loading: loadingChat,
clear: clearChat,
updateSystemContextByModel,
} = useChat(pathname);

const [generating, setGenerating] = useState(false);
Expand All @@ -242,6 +243,11 @@ const GenerateImagePage: React.FC = () => {
const { modelIds, imageGenModelIds, imageGenModels } = MODELS;
const modelId = getModelId();

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

// LandingPage のデモデータ設定
useEffect(() => {
const _modelId = !modelId ? modelIds[0] : modelId;
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
}, [modelId]);

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
}, [modelId]);

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
}, [modelId]);

// 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
}, [modelId]);

const disabledExec = useMemo(() => {
return url === '' || loading || fetching;
}, [url, loading, fetching]);
Expand Down
3 changes: 3 additions & 0 deletions packages/web/src/prompts/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { UnrecordedMessage } from 'generative-ai-use-cases-jp';
import { RetrieveResultItem } from '@aws-sdk/client-kendra';
import { claudePrompter } from './claude';
import { mistralPrompter } from './mistral';

export const getPrompter = (modelId: string) => {
if (modelId.startsWith('anthropic.claude-')) {
return claudePrompter;
} else if (modelId.startsWith('mistral.')) {
return mistralPrompter;
}

// デフォルトでは Claude の prompter を返す
Expand Down
Loading

0 comments on commit feef2bc

Please sign in to comment.