mirror of
https://github.com/Crosstalk-Solutions/project-nomad.git
synced 2026-04-04 15:56:16 +02:00
fix(AI Assistant): chat suggestion performance improvements
This commit is contained in:
parent
276bdcd0b2
commit
9301c44d3f
|
|
@ -55,11 +55,13 @@ export default function Chat({
|
||||||
|
|
||||||
const { data: chatSuggestions, isLoading: chatSuggestionsLoading } = useQuery<string[]>({
|
const { data: chatSuggestions, isLoading: chatSuggestionsLoading } = useQuery<string[]>({
|
||||||
queryKey: ['chatSuggestions'],
|
queryKey: ['chatSuggestions'],
|
||||||
queryFn: async () => {
|
queryFn: async ({ signal }) => {
|
||||||
const res = await api.getChatSuggestions()
|
const res = await api.getChatSuggestions(signal)
|
||||||
return res ?? []
|
return res ?? []
|
||||||
},
|
},
|
||||||
enabled: suggestionsEnabled,
|
enabled: suggestionsEnabled && !activeSessionId,
|
||||||
|
refetchOnWindowFocus: false,
|
||||||
|
refetchOnMount: false,
|
||||||
})
|
})
|
||||||
|
|
||||||
const deleteAllSessionsMutation = useMutation({
|
const deleteAllSessionsMutation = useMutation({
|
||||||
|
|
@ -151,6 +153,9 @@ export default function Chat({
|
||||||
|
|
||||||
const handleSessionSelect = useCallback(
|
const handleSessionSelect = useCallback(
|
||||||
async (sessionId: string) => {
|
async (sessionId: string) => {
|
||||||
|
// Cancel any ongoing suggestions fetch
|
||||||
|
queryClient.cancelQueries({ queryKey: ['chatSuggestions'] })
|
||||||
|
|
||||||
setActiveSessionId(sessionId)
|
setActiveSessionId(sessionId)
|
||||||
// Load messages for this session
|
// Load messages for this session
|
||||||
const sessionData = await api.getChatSession(sessionId)
|
const sessionData = await api.getChatSession(sessionId)
|
||||||
|
|
@ -172,7 +177,7 @@ export default function Chat({
|
||||||
setSelectedModel(sessionData.model)
|
setSelectedModel(sessionData.model)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[installedModels]
|
[installedModels, queryClient]
|
||||||
)
|
)
|
||||||
|
|
||||||
const handleSendMessage = useCallback(
|
const handleSendMessage = useCallback(
|
||||||
|
|
|
||||||
|
|
@ -147,10 +147,11 @@ class API {
|
||||||
})()
|
})()
|
||||||
}
|
}
|
||||||
|
|
||||||
async getChatSuggestions() {
|
async getChatSuggestions(signal?: AbortSignal) {
|
||||||
return catchInternal(async () => {
|
return catchInternal(async () => {
|
||||||
const response = await this.client.get<{ suggestions: string[] }>(
|
const response = await this.client.get<{ suggestions: string[] }>(
|
||||||
'/chat/suggestions'
|
'/chat/suggestions',
|
||||||
|
{ signal }
|
||||||
)
|
)
|
||||||
return response.data.suggestions
|
return response.data.suggestions
|
||||||
})()
|
})()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user