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

fix: add chat error and waiting status #96

Merged
merged 1 commit into from
Nov 28, 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 .changeset/dry-poets-confess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@difizen/magent-chat': patch
---

add chat error and waiting status
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { LoadingOutlined, RightOutlined } from '@ant-design/icons';
import { useInject, useObserve, ViewInstance } from '@difizen/mana-app';
import { l10n } from '@difizen/mana-l10n';
import { Alert } from 'antd';
import classNames from 'classnames';
import debounce from 'lodash.debounce';
import type { ReactNode } from 'react';
Expand Down Expand Up @@ -109,12 +110,28 @@ export const AIMessageContent = (props: AIMessageProps) => {
className={classNames({
['chat-message-ai-empty']: true,
['chat-message-ai-error']: item.error,
['chat-message-ai-waiting']: item.state === AnswerState.WAITING,
})}
>
<div className="chat-message-ai-content">
{item.state === AnswerState.RECEIVING && (
<LoadingOutlined className="chat-message-ai-receiving" />
)}
{item.state === AnswerState.FAIL && (
<Alert
message={l10n.t('生成失败,请重试!')}
type="error"
description={item.error?.message || ''}
showIcon
className="chat-message-ai-fail"
/>
)}
{item.state === AnswerState.WAITING && (
<span className="chat-message-ai-waiting">
<LoadingOutlined style={{ marginRight: '12px' }} />
{l10n.t('请求中...')}
</span>
)}
</div>
<AIMessageAddon {...props} />
</div>
Expand Down Expand Up @@ -143,6 +160,15 @@ export const AIMessageContent = (props: AIMessageProps) => {
{item.state === AnswerState.RECEIVING && (
<LoadingOutlined className="chat-message-ai-receiving" />
)}
{item.state === AnswerState.FAIL && (
<Alert
message={l10n.t('生成失败,请重试!')}
type="error"
description={item.error?.message || ''}
showIcon
className="chat-message-ai-fail"
/>
)}
<AIMessageAddon {...props} />
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,20 @@
width: 100%;
}

&-waiting {
padding: 10px 0 2px 12px;
font-size: 14px;
color: rgba(0, 0, 0, 60%);

.chat-message-ai-content {
min-height: 30px;
}
}

&-fail {
padding: 8px 16px;
}

&-receiving {
color: var(--mana-text-quaternary);
padding: 8px 16px;
Expand All @@ -183,6 +197,7 @@

.chat-message-ai-content {
box-shadow: var(--mana-ant-box-shadow-tabs-overflow-bottom);
min-height: 30px;
}

.chat-message-addon-error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ export function MessageOp({
message: BaseChatMessageModel;
item: BaseChatMessageItemModel;
}) {
if (!item.content) {
return null;
}
return (
<div style={{ paddingTop: 8, display: 'flex' }}>
{/* <div
Expand Down