Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refresh all assistants on assistant refresh #3216

Merged
merged 2 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions web/src/app/admin/assistants/AssistantEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,9 @@ export function AssistantEditor({
});
}
}

await refreshAssistants();
console.log("redirectType", redirectType);
router.push(
redirectType === SuccessfulPersonaUpdateRedirectType.ADMIN
? `/admin/assistants?u=${Date.now()}`
Expand Down
57 changes: 33 additions & 24 deletions web/src/components/context/AssistantsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,34 +81,36 @@ export const AssistantsProvider: React.FC<{
checkImageGenerationAvailability();
}, []);

useEffect(() => {
const fetchPersonas = async () => {
if (!isAdmin && !isCurator) {
return;
}
const fetchPersonas = async () => {
if (!isAdmin && !isCurator) {
return;
}

try {
const [editableResponse, allResponse] = await Promise.all([
fetch("/api/admin/persona?get_editable=true"),
fetch("/api/admin/persona"),
]);

if (editableResponse.ok) {
const editablePersonas = await editableResponse.json();
setEditablePersonas(editablePersonas);
}
try {
const [editableResponse, allResponse] = await Promise.all([
fetch("/api/admin/persona?get_editable=true"),
fetch("/api/admin/persona"),
]);

if (editableResponse.ok) {
const editablePersonas = await editableResponse.json();
setEditablePersonas(editablePersonas);
}

if (allResponse.ok) {
const allPersonas = await allResponse.json();
setAllAssistants(allPersonas);
} else {
console.error("Error fetching personas:", allResponse);
}
} catch (error) {
console.error("Error fetching personas:", error);
if (allResponse.ok) {
console.log("allResponse", allResponse);
const allPersonas = await allResponse.json();
setAllAssistants(allPersonas);
console.log("allAssistants", allAssistants);
} else {
console.error("Error fetching personas:", allResponse);
}
};
} catch (error) {
console.error("Error fetching personas:", error);
}
};

useEffect(() => {
fetchPersonas();
}, [isAdmin, isCurator]);

Expand Down Expand Up @@ -144,6 +146,7 @@ export const AssistantsProvider: React.FC<{
});
if (!response.ok) throw new Error("Failed to fetch assistants");
let assistants: Persona[] = await response.json();

if (!hasImageCompatibleModel) {
assistants = assistants.filter(
(assistant) =>
Expand All @@ -152,15 +155,21 @@ export const AssistantsProvider: React.FC<{
)
);
}

if (!hasAnyConnectors) {
assistants = assistants.filter(
(assistant) => assistant.num_chunks === 0
);
}

setAssistants(assistants);

// Fetch and update allAssistants for admins and curators
await fetchPersonas();
} catch (error) {
console.error("Error refreshing assistants:", error);
}

setRecentAssistants(
assistants.filter(
(assistant) =>
Expand Down
Loading