mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-07 13:59:28 +08:00
fix: update quick assistant ID handling and improve error management in HomeWindow
This commit is contained in:
parent
4d553beb85
commit
97b7eebf7d
@ -170,7 +170,7 @@ const ModelSettings: FC = () => {
|
|||||||
<HStack alignItems="center" gap={0}>
|
<HStack alignItems="center" gap={0}>
|
||||||
<StyledButton
|
<StyledButton
|
||||||
type={!quickAssistantId ? 'primary' : 'default'}
|
type={!quickAssistantId ? 'primary' : 'default'}
|
||||||
onClick={() => dispatch(setQuickAssistantId(null))}
|
onClick={() => dispatch(setQuickAssistantId(''))}
|
||||||
selected={!quickAssistantId}>
|
selected={!quickAssistantId}>
|
||||||
{t('settings.models.use_model')}
|
{t('settings.models.use_model')}
|
||||||
</StyledButton>
|
</StyledButton>
|
||||||
|
|||||||
@ -29,7 +29,7 @@ export interface LlmState {
|
|||||||
defaultModel: Model
|
defaultModel: Model
|
||||||
topicNamingModel: Model
|
topicNamingModel: Model
|
||||||
translateModel: Model
|
translateModel: Model
|
||||||
quickAssistantId: string | null
|
quickAssistantId: string
|
||||||
settings: LlmSettings
|
settings: LlmSettings
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -534,7 +534,7 @@ export const initialState: LlmState = {
|
|||||||
defaultModel: SYSTEM_MODELS.defaultModel[0],
|
defaultModel: SYSTEM_MODELS.defaultModel[0],
|
||||||
topicNamingModel: SYSTEM_MODELS.defaultModel[1],
|
topicNamingModel: SYSTEM_MODELS.defaultModel[1],
|
||||||
translateModel: SYSTEM_MODELS.defaultModel[2],
|
translateModel: SYSTEM_MODELS.defaultModel[2],
|
||||||
quickAssistantId: null,
|
quickAssistantId: '',
|
||||||
providers: INITIAL_PROVIDERS,
|
providers: INITIAL_PROVIDERS,
|
||||||
settings: {
|
settings: {
|
||||||
ollama: {
|
ollama: {
|
||||||
@ -650,7 +650,7 @@ const llmSlice = createSlice({
|
|||||||
state.translateModel = action.payload.model
|
state.translateModel = action.payload.model
|
||||||
},
|
},
|
||||||
|
|
||||||
setQuickAssistantId: (state, action: PayloadAction<string | null>) => {
|
setQuickAssistantId: (state, action: PayloadAction<string>) => {
|
||||||
state.quickAssistantId = action.payload
|
state.quickAssistantId = action.payload
|
||||||
},
|
},
|
||||||
setOllamaKeepAliveTime: (state, action: PayloadAction<number>) => {
|
setOllamaKeepAliveTime: (state, action: PayloadAction<number>) => {
|
||||||
|
|||||||
@ -56,6 +56,8 @@ const HomeWindow: FC = () => {
|
|||||||
//indicator for wether the first message is outputted
|
//indicator for wether the first message is outputted
|
||||||
const [isOutputted, setIsOutputted] = useState(false)
|
const [isOutputted, setIsOutputted] = useState(false)
|
||||||
|
|
||||||
|
const [error, setError] = useState<string | null>(null)
|
||||||
|
|
||||||
const { quickAssistantId } = useAppSelector((state) => state.llm)
|
const { quickAssistantId } = useAppSelector((state) => state.llm)
|
||||||
const currentAssistant = useRef<Assistant | null>(null)
|
const currentAssistant = useRef<Assistant | null>(null)
|
||||||
const currentTopic = useRef<Topic | null>(null)
|
const currentTopic = useRef<Topic | null>(null)
|
||||||
@ -206,6 +208,11 @@ const HomeWindow: FC = () => {
|
|||||||
setUserInputText(e.target.value)
|
setUserInputText(e.target.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleError = (error: Error) => {
|
||||||
|
setIsLoading(false)
|
||||||
|
setError(error.message)
|
||||||
|
}
|
||||||
|
|
||||||
const handleSendMessage = useCallback(
|
const handleSendMessage = useCallback(
|
||||||
async (prompt?: string) => {
|
async (prompt?: string) => {
|
||||||
if (isEmpty(content) || !currentAssistant.current || !currentTopic.current) {
|
if (isEmpty(content) || !currentAssistant.current || !currentTopic.current) {
|
||||||
@ -247,6 +254,7 @@ const HomeWindow: FC = () => {
|
|||||||
|
|
||||||
setIsLoading(true)
|
setIsLoading(true)
|
||||||
setIsOutputted(false)
|
setIsOutputted(false)
|
||||||
|
setError(null)
|
||||||
|
|
||||||
setIsFirstMessage(false)
|
setIsFirstMessage(false)
|
||||||
setUserInputText('')
|
setUserInputText('')
|
||||||
@ -332,8 +340,12 @@ const HomeWindow: FC = () => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case ChunkType.BLOCK_COMPLETE:
|
|
||||||
case ChunkType.ERROR:
|
case ChunkType.ERROR:
|
||||||
|
if (!isAbortError(chunk.error)) {
|
||||||
|
throw new Error(chunk.error.message)
|
||||||
|
}
|
||||||
|
//fall through
|
||||||
|
case ChunkType.BLOCK_COMPLETE:
|
||||||
setIsLoading(false)
|
setIsLoading(false)
|
||||||
setIsOutputted(true)
|
setIsOutputted(true)
|
||||||
currentAskId.current = ''
|
currentAskId.current = ''
|
||||||
@ -343,7 +355,7 @@ const HomeWindow: FC = () => {
|
|||||||
})
|
})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (isAbortError(err)) return
|
if (isAbortError(err)) return
|
||||||
// onError(err instanceof Error ? err : new Error('An error occurred'))
|
handleError(err instanceof Error ? err : new Error('An error occurred'))
|
||||||
console.error('Error fetching result:', err)
|
console.error('Error fetching result:', err)
|
||||||
} finally {
|
} finally {
|
||||||
setIsLoading(false)
|
setIsLoading(false)
|
||||||
@ -371,6 +383,7 @@ const HomeWindow: FC = () => {
|
|||||||
currentTopic.current = getDefaultTopic(currentAssistant.current.id)
|
currentTopic.current = getDefaultTopic(currentAssistant.current.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setError(null)
|
||||||
setRoute('home')
|
setRoute('home')
|
||||||
setUserInputText('')
|
setUserInputText('')
|
||||||
}
|
}
|
||||||
@ -443,6 +456,8 @@ const HomeWindow: FC = () => {
|
|||||||
topic={currentTopic.current!}
|
topic={currentTopic.current!}
|
||||||
isOutputted={isOutputted}
|
isOutputted={isOutputted}
|
||||||
/>
|
/>
|
||||||
|
{error && <ErrorMsg>{error}</ErrorMsg>}
|
||||||
|
|
||||||
<Divider style={{ margin: '10px 0' }} />
|
<Divider style={{ margin: '10px 0' }} />
|
||||||
<Footer key="footer" route={route} loading={isLoading} onEsc={handleEsc} />
|
<Footer key="footer" route={route} loading={isLoading} onEsc={handleEsc} />
|
||||||
</Container>
|
</Container>
|
||||||
@ -514,4 +529,15 @@ const Main = styled.main`
|
|||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const ErrorMsg = styled.div`
|
||||||
|
color: var(--color-error);
|
||||||
|
background: rgba(255, 0, 0, 0.15);
|
||||||
|
border: 1px solid var(--color-error);
|
||||||
|
padding: 8px 12px;
|
||||||
|
border-radius: 4px;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
font-size: 13px;
|
||||||
|
word-break: break-all;
|
||||||
|
`
|
||||||
|
|
||||||
export default HomeWindow
|
export default HomeWindow
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user