-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Uses assistant name instead of id
1 parent
b0421be
commit 967be0f
Showing
3 changed files
with
56 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./useAssistantList"; | ||
export * from "./useAssistant"; | ||
export * from "./useMessageList"; | ||
export * from "./useThreadList"; |
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,48 @@ | ||
import { useCallback } from "react"; | ||
import { useState } from "react"; | ||
import { | ||
AssistantSchema, | ||
djangoAiAssistantViewsGetAssistant, | ||
} from "../client"; | ||
|
||
/** | ||
* React hook to manage the Assistants. | ||
*/ | ||
export function useAssistant({ assistantId }: { | ||
assistantId: string; | ||
}) { | ||
const [assistant, setAssistant] = useState<AssistantSchema | null>(null); | ||
const [loadingFetchAssistant, setLoadingFetchAssistant] = | ||
useState<boolean>(false); | ||
|
||
/** | ||
* Fetches a list of AI assistants. | ||
* | ||
* @returns A promise that resolves with the fetched list of AI assistants. | ||
*/ | ||
const fetchAssistant = useCallback(async (): Promise<AssistantSchema> => { | ||
try { | ||
setLoadingFetchAssistant(true); | ||
const fetchedAssistant = await djangoAiAssistantViewsGetAssistant({ assistantId }); | ||
setAssistant(fetchedAssistant); | ||
return fetchedAssistant; | ||
} finally { | ||
setLoadingFetchAssistant(false); | ||
} | ||
}, [assistantId]); | ||
|
||
return { | ||
/** | ||
* Function to fetch an AI assistant from the server. | ||
*/ | ||
fetchAssistant, | ||
/** | ||
* Fetched AI assistant. | ||
*/ | ||
assistant, | ||
/** | ||
* Loading state of the fetch operation. | ||
*/ | ||
loadingFetchAssistant, | ||
}; | ||
} |