feat: prevent user sending messages during message generation
This commit is contained in:
parent
848797e824
commit
ba2659afd1
@ -19,6 +19,7 @@ import { isEmpty } from 'lodash'
|
||||
import SendMessageSetting from './SendMessageSetting'
|
||||
import { useSettings } from '@renderer/hooks/useSettings'
|
||||
import dayjs from 'dayjs'
|
||||
import { useAppSelector } from '@renderer/store'
|
||||
|
||||
interface Props {
|
||||
assistant: Assistant
|
||||
@ -31,9 +32,14 @@ const Inputbar: FC<Props> = ({ assistant, setActiveTopic }) => {
|
||||
const { addTopic } = useAssistant(assistant.id)
|
||||
const { sendMessageShortcut } = useSettings()
|
||||
const [expended, setExpend] = useState(false)
|
||||
const generating = useAppSelector((state) => state.runtime.generating)
|
||||
const inputRef = useRef<TextAreaRef>(null)
|
||||
|
||||
const sendMessage = () => {
|
||||
if (generating) {
|
||||
return
|
||||
}
|
||||
|
||||
if (isEmpty(text.trim())) {
|
||||
return
|
||||
}
|
||||
|
||||
@ -6,6 +6,8 @@ import OpenAI from 'openai'
|
||||
import { getAssistantProvider, getDefaultModel, getProviderByModel, getTopNamingModel } from './assistant'
|
||||
import { takeRight } from 'lodash'
|
||||
import dayjs from 'dayjs'
|
||||
import store from '@renderer/store'
|
||||
import { setGenerating } from '@renderer/store/runtime'
|
||||
|
||||
interface FetchChatCompletionParams {
|
||||
messages: Message[]
|
||||
@ -29,6 +31,8 @@ export async function fetchChatCompletion({ messages, topic, assistant, onRespon
|
||||
const defaultModel = getDefaultModel()
|
||||
const model = assistant.model || defaultModel
|
||||
|
||||
store.dispatch(setGenerating(true))
|
||||
|
||||
const _message: Message = {
|
||||
id: uuid(),
|
||||
role: 'assistant',
|
||||
@ -74,8 +78,8 @@ export async function fetchChatCompletion({ messages, topic, assistant, onRespon
|
||||
}
|
||||
|
||||
_message.status = 'success'
|
||||
|
||||
EventEmitter.emit(EVENT_NAMES.AI_CHAT_COMPLETION, _message)
|
||||
store.dispatch(setGenerating(false))
|
||||
|
||||
return _message
|
||||
}
|
||||
|
||||
@ -3,10 +3,12 @@ import Logo from '@renderer/assets/images/logo.png'
|
||||
|
||||
export interface RuntimeState {
|
||||
avatar: string
|
||||
generating: boolean
|
||||
}
|
||||
|
||||
const initialState: RuntimeState = {
|
||||
avatar: Logo
|
||||
avatar: Logo,
|
||||
generating: false
|
||||
}
|
||||
|
||||
const runtimeSlice = createSlice({
|
||||
@ -15,10 +17,13 @@ const runtimeSlice = createSlice({
|
||||
reducers: {
|
||||
setAvatar: (state, action: PayloadAction<string | null>) => {
|
||||
state.avatar = action.payload || Logo
|
||||
},
|
||||
setGenerating: (state, action: PayloadAction<boolean>) => {
|
||||
state.generating = action.payload
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
export const { setAvatar } = runtimeSlice.actions
|
||||
export const { setAvatar, setGenerating } = runtimeSlice.actions
|
||||
|
||||
export default runtimeSlice.reducer
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user