-
-
Notifications
You must be signed in to change notification settings - Fork 658
feat(use-x-chat): add updating status #833
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
Open
wzc520pyfm
wants to merge
6
commits into
ant-design:main
Choose a base branch
from
wzc520pyfm:feat/add-updating-status-for-use-x-chat
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
df366d6
feat(use-x-chat): add updating status
wzc520pyfm 6f72729
test(use-x-chat): fix test error about on-update callback
wzc520pyfm 411d21e
docs(use-x-chat): add loading for stream demo
wzc520pyfm 5fe6ada
fix(use-x-chat): always set loadingMsg when init
wzc520pyfm 8a51262
fix(use-x-chat): set placeholderMsg default value to empty string
wzc520pyfm 13f90c3
test(use-x-chat): fix check filed for case about loading placeholder msg
wzc520pyfm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -8,7 +8,7 @@ import useSyncState from './useSyncState'; | |
|
||
export type SimpleType = string | number | boolean | object; | ||
|
||
export type MessageStatus = 'local' | 'loading' | 'success' | 'error'; | ||
export type MessageStatus = 'local' | 'loading' | 'updating' | 'success' | 'error'; | ||
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. The addition of the |
||
|
||
type RequestPlaceholderFn<Message extends SimpleType> = ( | ||
message: Message, | ||
|
@@ -178,11 +178,7 @@ export default function useXChat< | |
let message: AgentMessage; | ||
let otherRequestParams = {}; | ||
|
||
if ( | ||
requestParams && | ||
typeof requestParams === 'object' && | ||
'message' in requestParams | ||
) { | ||
if (requestParams && typeof requestParams === 'object' && 'message' in requestParams) { | ||
const { message: requestParamsMessage, ...other } = | ||
requestParams as RequestParams<AgentMessage>; | ||
message = requestParamsMessage; | ||
|
@@ -193,8 +189,8 @@ export default function useXChat< | |
// Add placeholder message | ||
setMessages((ori) => { | ||
let nextMessages = [...ori, createMessage(message, 'local')]; | ||
let placeholderMsg = '' as AgentMessage; | ||
if (requestPlaceholder) { | ||
let placeholderMsg: AgentMessage; | ||
if (typeof requestPlaceholder === 'function') { | ||
// typescript has bug that not get real return type when use `typeof function` check | ||
placeholderMsg = (requestPlaceholder as RequestPlaceholderFn<AgentMessage>)(message, { | ||
|
@@ -203,11 +199,11 @@ export default function useXChat< | |
} else { | ||
placeholderMsg = requestPlaceholder; | ||
} | ||
const loadingMsg = createMessage(placeholderMsg, 'loading'); | ||
loadingMsgId = loadingMsg.id; | ||
|
||
nextMessages = [...nextMessages, loadingMsg]; | ||
} | ||
const loadingMsg = createMessage(placeholderMsg, 'loading'); | ||
loadingMsgId = loadingMsg.id; | ||
|
||
nextMessages = [...nextMessages, loadingMsg]; | ||
|
||
return nextMessages; | ||
}); | ||
|
@@ -257,7 +253,7 @@ export default function useXChat< | |
} as Input, | ||
{ | ||
onUpdate: (chunk) => { | ||
updateMessage('loading', chunk, []); | ||
updateMessage('updating', chunk, []); | ||
wzc520pyfm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
onSuccess: (chunks) => { | ||
updateMessage('success', undefined as Output, chunks); | ||
|
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.
该pr之后,流式输出和非流式输出可以使用相同的方式设置bubble loading