feat: add a loading status for messages
This commit is contained in:
parent
7274473c23
commit
e311adc417
@ -9,6 +9,7 @@ import CodeBlock from './CodeBlock'
|
|||||||
import { EVENT_NAMES, EventEmitter } from '@renderer/services/event'
|
import { EVENT_NAMES, EventEmitter } from '@renderer/services/event'
|
||||||
import { getModelLogo } from '@renderer/services/provider'
|
import { getModelLogo } from '@renderer/services/provider'
|
||||||
import Logo from '@renderer/assets/images/logo.png'
|
import Logo from '@renderer/assets/images/logo.png'
|
||||||
|
import { SyncOutlined } from '@ant-design/icons'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
message: Message
|
message: Message
|
||||||
@ -49,9 +50,16 @@ const MessageItem: FC<Props> = ({ message, showMenu, onDeleteMessage }) => {
|
|||||||
)}
|
)}
|
||||||
</AvatarWrapper>
|
</AvatarWrapper>
|
||||||
<MessageContent>
|
<MessageContent>
|
||||||
<Markdown className="markdown" components={{ code: CodeBlock as any }}>
|
{message.status === 'sending' && (
|
||||||
{message.content}
|
<MessageContentLoading>
|
||||||
</Markdown>
|
<SyncOutlined spin size={24} />
|
||||||
|
</MessageContentLoading>
|
||||||
|
)}
|
||||||
|
{message.status !== 'sending' && (
|
||||||
|
<Markdown className="markdown" components={{ code: CodeBlock as any }}>
|
||||||
|
{message.content}
|
||||||
|
</Markdown>
|
||||||
|
)}
|
||||||
{showMenu && (
|
{showMenu && (
|
||||||
<MenusBar className="menubar">
|
<MenusBar className="menubar">
|
||||||
{message.role === 'user' && (
|
{message.role === 'user' && (
|
||||||
@ -98,6 +106,13 @@ const MessageContent = styled.div`
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const MessageContentLoading = styled.div`
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
height: 32px;
|
||||||
|
`
|
||||||
|
|
||||||
const MenusBar = styled.div`
|
const MenusBar = styled.div`
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
|
|||||||
@ -37,9 +37,11 @@ export async function fetchChatCompletion({ messages, topic, assistant, onRespon
|
|||||||
topicId: topic.id,
|
topicId: topic.id,
|
||||||
modelId: model.id,
|
modelId: model.id,
|
||||||
createdAt: dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
createdAt: dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
||||||
status: 'pending'
|
status: 'sending'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onResponse({ ..._message })
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const stream = await openaiProvider.chat.completions.create({
|
const stream = await openaiProvider.chat.completions.create({
|
||||||
model: model.id,
|
model: model.id,
|
||||||
@ -54,7 +56,7 @@ export async function fetchChatCompletion({ messages, topic, assistant, onRespon
|
|||||||
|
|
||||||
for await (const chunk of stream) {
|
for await (const chunk of stream) {
|
||||||
content = content + (chunk.choices[0]?.delta?.content || '')
|
content = content + (chunk.choices[0]?.delta?.content || '')
|
||||||
onResponse({ ..._message, content })
|
onResponse({ ..._message, content, status: 'pending' })
|
||||||
}
|
}
|
||||||
|
|
||||||
_message.content = content
|
_message.content = content
|
||||||
|
|||||||
@ -15,7 +15,7 @@ export type Message = {
|
|||||||
topicId: string
|
topicId: string
|
||||||
modelId?: string
|
modelId?: string
|
||||||
createdAt: string
|
createdAt: string
|
||||||
status: 'pending' | 'success' | 'error'
|
status: 'sending' | 'pending' | 'success' | 'error'
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Topic = {
|
export type Topic = {
|
||||||
@ -37,7 +37,7 @@ export type Provider = {
|
|||||||
apiKey: string
|
apiKey: string
|
||||||
apiHost: string
|
apiHost: string
|
||||||
models: Model[]
|
models: Model[]
|
||||||
enabled: boolean
|
enabled?: boolean
|
||||||
isSystem?: boolean
|
isSystem?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user