-
Notifications
You must be signed in to change notification settings - Fork 73
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
会話一覧の最新化 #59
Merged
Merged
会話一覧の最新化 #59
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,13 @@ import { | |
UnrecordedMessage, | ||
ToBeRecordedMessage, | ||
Chat, | ||
ListChatsResponse, | ||
} from 'generative-ai-use-cases-jp'; | ||
import { useEffect, useMemo } from 'react'; | ||
import { v4 as uuid } from 'uuid'; | ||
import useChatApi from './useChatApi'; | ||
import useConversation from './useConversation'; | ||
import { KeyedMutator } from 'swr'; | ||
|
||
const useChatState = create<{ | ||
chats: { | ||
|
@@ -28,7 +31,11 @@ const useChatState = create<{ | |
chat: Chat | ||
) => void; | ||
clear: (id: string, systemContext: string) => void; | ||
post: (id: string, content: string) => void; | ||
post: ( | ||
id: string, | ||
content: string, | ||
mutateListChat: KeyedMutator<ListChatsResponse> | ||
) => void; | ||
Comment on lines
+34
to
+38
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. ZsutandとSWRの相性問題があり、Zsutandの中でSWRを実行するとエラーになってしまうので、Mutate関数を渡す実装にしました。 |
||
}>((set, get) => { | ||
const { createChat, createMessages, predictStream, predictTitle } = | ||
useChatApi(); | ||
|
@@ -172,7 +179,7 @@ const useChatState = create<{ | |
clear: (id: string, systemContext: string) => { | ||
initChat(id, [{ role: 'system', content: systemContext }], undefined); | ||
}, | ||
post: async (id: string, content: string) => { | ||
post: async (id: string, content: string, mutateListChat) => { | ||
setLoading(id, true); | ||
|
||
const unrecordedUserMessage: UnrecordedMessage = { | ||
|
@@ -229,7 +236,9 @@ const useChatState = create<{ | |
|
||
// タイトルが空文字列だった場合、タイトルを予測して設定 | ||
if (get().chats[id].chat?.title === '') { | ||
updateTitle(id); | ||
updateTitle(id).then(() => { | ||
mutateListChat(); | ||
}); | ||
} | ||
|
||
const toBeRecordedMessages = addMessageIdsToUnrecordedMessages(id); | ||
|
@@ -249,6 +258,7 @@ const useChat = (id: string, systemContext?: string, chatId?: string) => { | |
useChatApi().listMessages(chatId); | ||
const { data: chatData, isLoading: isLoadingChat } = | ||
useChatApi().findChatById(chatId); | ||
const { mutate: mutateConversations } = useConversation(); | ||
|
||
useEffect(() => { | ||
// 新規チャットの場合 | ||
|
@@ -277,7 +287,7 @@ const useChat = (id: string, systemContext?: string, chatId?: string) => { | |
messages: filteredMessages, | ||
isEmpty: filteredMessages.length === 0, | ||
postChat: (content: string) => { | ||
post(id, content); | ||
post(id, content, mutateConversations); | ||
}, | ||
}; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ import React, { useCallback, useEffect } from 'react'; | |
import { BaseProps } from '../@types/common'; | ||
import useChat from '../hooks/useChat'; | ||
import Card from '../components/Card'; | ||
import { PiDotsThree } from 'react-icons/pi'; | ||
import Markdown from '../components/Markdown'; | ||
import InputChatContent from '../components/InputChatContent'; | ||
import ButtonCopy from '../components/ButtonCopy'; | ||
|
@@ -109,13 +108,21 @@ const PromptTamplatePageBase: React.FC<Props> = (props) => { | |
</div> | ||
) : ( | ||
<> | ||
<Markdown>{message.content}</Markdown> | ||
<Markdown> | ||
{message.content + | ||
`${ | ||
loading && | ||
idx === messages.length - 1 && | ||
messages[idx].content !== '' | ||
? '▍' | ||
: '' | ||
}`} | ||
</Markdown> | ||
{loading && | ||
message.role === 'assistant' && | ||
idx === messages.length - 1 && ( | ||
<div className="animate-pulse text-2xl text-gray-700"> | ||
<PiDotsThree /> | ||
</div> | ||
idx === messages.length - 1 && | ||
messages[idx].content === '' && ( | ||
<div className="animate-pulse text-gray-700">▍</div> | ||
Comment on lines
+111
to
+125
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. Loading表示の修正を入れ忘れていたので、こちらも修正しました。 |
||
)} | ||
<div className="flex justify-end"> | ||
<ButtonCopy | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
これそうなんすよねぇ〜自分も気になってました。タイトルが出せると良いのにと。Issue 化しておきます!