Skip to content

Commit

Permalink
Refresh all assistants on assistant refresh (danswer-ai#3216)
Browse files Browse the repository at this point in the history
* k

* k
  • Loading branch information
pablodanswer authored and ahmadassaf committed Nov 25, 2024
1 parent 27e7f2c commit c7230dc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
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

0 comments on commit c7230dc

Please sign in to comment.