mirror of
https://github.com/Crosstalk-Solutions/project-nomad.git
synced 2026-03-28 03:29:25 +01: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[]>({
|
||||
queryKey: ['chatSuggestions'],
|
||||
queryFn: async () => {
|
||||
const res = await api.getChatSuggestions()
|
||||
queryFn: async ({ signal }) => {
|
||||
const res = await api.getChatSuggestions(signal)
|
||||
return res ?? []
|
||||
},
|
||||
enabled: suggestionsEnabled,
|
||||
enabled: suggestionsEnabled && !activeSessionId,
|
||||
refetchOnWindowFocus: false,
|
||||
refetchOnMount: false,
|
||||
})
|
||||
|
||||
const deleteAllSessionsMutation = useMutation({
|
||||
|
|
@ -151,6 +153,9 @@ export default function Chat({
|
|||
|
||||
const handleSessionSelect = useCallback(
|
||||
async (sessionId: string) => {
|
||||
// Cancel any ongoing suggestions fetch
|
||||
queryClient.cancelQueries({ queryKey: ['chatSuggestions'] })
|
||||
|
||||
setActiveSessionId(sessionId)
|
||||
// Load messages for this session
|
||||
const sessionData = await api.getChatSession(sessionId)
|
||||
|
|
@ -172,7 +177,7 @@ export default function Chat({
|
|||
setSelectedModel(sessionData.model)
|
||||
}
|
||||
},
|
||||
[installedModels]
|
||||
[installedModels, queryClient]
|
||||
)
|
||||
|
||||
const handleSendMessage = useCallback(
|
||||
|
|
|
|||
|
|
@ -147,10 +147,11 @@ class API {
|
|||
})()
|
||||
}
|
||||
|
||||
async getChatSuggestions() {
|
||||
async getChatSuggestions(signal?: AbortSignal) {
|
||||
return catchInternal(async () => {
|
||||
const response = await this.client.get<{ suggestions: string[] }>(
|
||||
'/chat/suggestions'
|
||||
'/chat/suggestions',
|
||||
{ signal }
|
||||
)
|
||||
return response.data.suggestions
|
||||
})()
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user