-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: refresh should not create new thread
- Loading branch information
Showing
16 changed files
with
243 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { useQuery } from '@tanstack/react-query' | ||
|
||
import { useSetAtom } from 'jotai' | ||
|
||
import useCortex from './useCortex' | ||
|
||
import { downloadedModelsAtom } from '@/helpers/atoms/Model.atom' | ||
|
||
export const modelQueryKey = ['getModels'] | ||
|
||
const useModelQuery = () => { | ||
const { fetchModels } = useCortex() | ||
const setDownloadedModels = useSetAtom(downloadedModelsAtom) | ||
|
||
return useQuery({ | ||
queryKey: modelQueryKey, | ||
queryFn: async () => { | ||
const models = await fetchModels() | ||
setDownloadedModels(models) | ||
return models | ||
}, | ||
staleTime: 30 * 1000, | ||
}) | ||
} | ||
|
||
export default useModelQuery |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { Assistant } from '@janhq/core' | ||
import { useMutation } from '@tanstack/react-query' | ||
|
||
import { useSetAtom } from 'jotai' | ||
|
||
import { toaster } from '@/containers/Toast' | ||
|
||
import useCortex from './useCortex' | ||
|
||
import { setThreadMessagesAtom } from '@/helpers/atoms/ChatMessage.atom' | ||
import { setActiveThreadIdAtom, threadsAtom } from '@/helpers/atoms/Thread.atom' | ||
|
||
export type ThreadCreateMutationVariables = { | ||
modelId: string | ||
assistant: Assistant | ||
instructions?: string | ||
} | ||
|
||
const useThreadCreateMutation = () => { | ||
const { createThread } = useCortex() | ||
const setThreads = useSetAtom(threadsAtom) | ||
const setActiveThreadId = useSetAtom(setActiveThreadIdAtom) | ||
const setThreadMessage = useSetAtom(setThreadMessagesAtom) | ||
|
||
return useMutation({ | ||
mutationFn: async (variables: ThreadCreateMutationVariables) => { | ||
const { assistant, modelId, instructions } = variables | ||
if (instructions) { | ||
assistant.instructions = instructions | ||
} | ||
|
||
return createThread({ | ||
...assistant, | ||
model: modelId, | ||
}) | ||
}, | ||
|
||
onSuccess: (thread, variables, context) => { | ||
console.log('New thread created', thread, variables, context) | ||
setThreads((threads) => [thread, ...threads]) | ||
setActiveThreadId(thread.id) | ||
setThreadMessage(thread.id, []) | ||
}, | ||
|
||
onError: (error, variables) => { | ||
console.error( | ||
`Failed to create new thread: ${JSON.stringify(variables)}, error: ${error}` | ||
) | ||
toaster({ | ||
title: 'Failed to create thread', | ||
description: `Unexpected error while creating thread. Please try again!`, | ||
type: 'error', | ||
}) | ||
}, | ||
}) | ||
} | ||
|
||
export default useThreadCreateMutation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { useQuery } from '@tanstack/react-query' | ||
|
||
import { useSetAtom } from 'jotai' | ||
|
||
import useCortex from './useCortex' | ||
|
||
import { threadsAtom } from '@/helpers/atoms/Thread.atom' | ||
|
||
export const threadQueryKey = ['getThreads'] | ||
|
||
const useThreadQuery = () => { | ||
const { fetchThreads } = useCortex() | ||
const setThreads = useSetAtom(threadsAtom) | ||
|
||
return useQuery({ | ||
queryKey: threadQueryKey, | ||
queryFn: async () => { | ||
const threads = await fetchThreads() | ||
setThreads(threads) | ||
return threads | ||
}, | ||
staleTime: 30 * 1000, | ||
}) | ||
} | ||
|
||
export default useThreadQuery |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 0 additions & 41 deletions
41
web/screens/Settings/Advanced/components/CopyOverInstruction.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.