Skip to content

Commit d503917

Browse files
committed
Assistant cleanup (#3236)
* minor cleanup * ensure users don't modify built-in attributes of assistants * update sidebar * k * update update flow + assistant creation
1 parent 214c9a2 commit d503917

File tree

8 files changed

+60
-55
lines changed

8 files changed

+60
-55
lines changed

backend/danswer/db/persona.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,9 @@ def upsert_prompt(
390390
return prompt
391391

392392

393+
# NOTE: This operation cannot update persona configuration options that
394+
# are core to the persona, such as its display priority and
395+
# whether or not the assistant is a built-in / default assistant
393396
def upsert_persona(
394397
user: User | None,
395398
name: str,
@@ -457,7 +460,7 @@ def upsert_persona(
457460
validate_persona_tools(tools)
458461

459462
if persona:
460-
if not builtin_persona and persona.builtin_persona:
463+
if persona.builtin_persona and not builtin_persona:
461464
raise ValueError("Cannot update builtin persona with non-builtin.")
462465

463466
# this checks if the user has permission to edit the persona
@@ -473,7 +476,6 @@ def upsert_persona(
473476
persona.llm_relevance_filter = llm_relevance_filter
474477
persona.llm_filter_extraction = llm_filter_extraction
475478
persona.recency_bias = recency_bias
476-
persona.builtin_persona = builtin_persona
477479
persona.llm_model_provider_override = llm_model_provider_override
478480
persona.llm_model_version_override = llm_model_version_override
479481
persona.starter_messages = starter_messages
@@ -483,7 +485,6 @@ def upsert_persona(
483485
persona.icon_shape = icon_shape
484486
if remove_image or uploaded_image_id:
485487
persona.uploaded_image_id = uploaded_image_id
486-
persona.display_priority = display_priority
487488
persona.is_visible = is_visible
488489
persona.search_start_date = search_start_date
489490
persona.is_default_persona = is_default_persona

backend/danswer/server/features/persona/api.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ def create_persona(
168168
)
169169

170170

171+
# NOTE: This endpoint cannot update persona configuration options that
172+
# are core to the persona, such as its display priority and
173+
# whether or not the assistant is a built-in / default assistant
171174
@basic_router.patch("/{persona_id}")
172175
def update_persona(
173176
persona_id: int,

backend/danswer/server/manage/users.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,6 @@ def update_user_assistant_list(
614614
if user is None:
615615
if AUTH_TYPE == AuthType.DISABLED:
616616
store = get_kv_store()
617-
618617
no_auth_user = fetch_no_auth_user(store)
619618
no_auth_user.preferences.chosen_assistants = request.chosen_assistants
620619
set_no_auth_user_preferences(store, no_auth_user.preferences)

web/src/app/admin/assistants/AssistantEditor.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ export function AssistantEditor({
359359
if (!promptResponse.ok) {
360360
error = await promptResponse.text();
361361
}
362+
362363
if (!personaResponse) {
363364
error = "Failed to create Assistant - no response received";
364365
} else if (!personaResponse.ok) {

web/src/app/admin/assistants/lib.ts

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,29 @@ export async function updatePersona(
219219
): Promise<[Response, Response | null]> {
220220
const { id, existingPromptId } = personaUpdateRequest;
221221

222-
// first update prompt
222+
let fileId = null;
223+
if (personaUpdateRequest.uploaded_image) {
224+
fileId = await uploadFile(personaUpdateRequest.uploaded_image);
225+
if (!fileId) {
226+
return [new Response(null, { status: 400 }), null];
227+
}
228+
}
229+
230+
const updatePersonaResponse = await fetch(`/api/persona/${id}`, {
231+
method: "PATCH",
232+
headers: {
233+
"Content-Type": "application/json",
234+
},
235+
body: JSON.stringify(
236+
buildPersonaAPIBody(personaUpdateRequest, existingPromptId ?? 0, fileId)
237+
),
238+
});
239+
240+
if (!updatePersonaResponse.ok) {
241+
return [updatePersonaResponse, null];
242+
}
243+
223244
let promptResponse;
224-
let promptId;
225245
if (existingPromptId !== undefined) {
226246
promptResponse = await updatePrompt({
227247
promptId: existingPromptId,
@@ -230,38 +250,15 @@ export async function updatePersona(
230250
taskPrompt: personaUpdateRequest.task_prompt,
231251
includeCitations: personaUpdateRequest.include_citations,
232252
});
233-
promptId = existingPromptId;
234253
} else {
235254
promptResponse = await createPrompt({
236255
personaName: personaUpdateRequest.name,
237256
systemPrompt: personaUpdateRequest.system_prompt,
238257
taskPrompt: personaUpdateRequest.task_prompt,
239258
includeCitations: personaUpdateRequest.include_citations,
240259
});
241-
promptId = promptResponse.ok ? (await promptResponse.json()).id : null;
242260
}
243261

244-
let fileId = null;
245-
if (personaUpdateRequest.uploaded_image) {
246-
fileId = await uploadFile(personaUpdateRequest.uploaded_image);
247-
if (!fileId) {
248-
return [promptResponse, null];
249-
}
250-
}
251-
252-
const updatePersonaResponse =
253-
promptResponse.ok && promptId
254-
? await fetch(`/api/persona/${id}`, {
255-
method: "PATCH",
256-
headers: {
257-
"Content-Type": "application/json",
258-
},
259-
body: JSON.stringify(
260-
buildPersonaAPIBody(personaUpdateRequest, promptId, fileId)
261-
),
262-
})
263-
: null;
264-
265262
return [promptResponse, updatePersonaResponse];
266263
}
267264

web/src/app/assistants/gallery/AssistantsGallery.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ import { classifyAssistants } from "@/lib/assistants/utils";
1818
import { useAssistants } from "@/components/context/AssistantsContext";
1919
import { useUser } from "@/components/user/UserProvider";
2020
export function AssistantGalleryCard({
21+
onlyAssistant,
2122
assistant,
2223
user,
2324
setPopup,
2425
selectedAssistant,
2526
}: {
27+
onlyAssistant: boolean;
2628
assistant: Persona;
2729
user: User | null;
2830
setPopup: (popup: PopupSpec) => void;
@@ -66,10 +68,7 @@ export function AssistantGalleryCard({
6668
"
6769
icon={FiMinus}
6870
onClick={async () => {
69-
if (
70-
user.preferences?.chosen_assistants &&
71-
user.preferences?.chosen_assistants.length === 1
72-
) {
71+
if (onlyAssistant) {
7372
setPopup({
7473
message: `Cannot remove "${assistant.name}" - you must have at least one assistant.`,
7574
type: "error",
@@ -268,6 +267,7 @@ export function AssistantsGallery() {
268267
>
269268
{defaultAssistants.map((assistant) => (
270269
<AssistantGalleryCard
270+
onlyAssistant={visibleAssistants.length === 1}
271271
selectedAssistant={visibleAssistants.includes(assistant)}
272272
key={assistant.id}
273273
assistant={assistant}
@@ -301,6 +301,7 @@ export function AssistantsGallery() {
301301
>
302302
{nonDefaultAssistants.map((assistant) => (
303303
<AssistantGalleryCard
304+
onlyAssistant={visibleAssistants.length === 1}
304305
selectedAssistant={visibleAssistants.includes(assistant)}
305306
key={assistant.id}
306307
assistant={assistant}

web/src/app/assistants/mine/AssistantsList.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ import { CustomTooltip } from "@/components/tooltip/CustomTooltip";
6060
import { useAssistants } from "@/components/context/AssistantsContext";
6161
import { useUser } from "@/components/user/UserProvider";
6262

63-
function DraggableAssistantListItem(props: any) {
63+
function DraggableAssistantListItem({ ...props }: any) {
6464
const {
6565
attributes,
6666
listeners,
@@ -100,6 +100,7 @@ function AssistantListItem({
100100
deleteAssistant,
101101
shareAssistant,
102102
isDragging,
103+
onlyAssistant,
103104
}: {
104105
assistant: Persona;
105106
user: User | null;
@@ -109,14 +110,13 @@ function AssistantListItem({
109110
shareAssistant: Dispatch<SetStateAction<Persona | null>>;
110111
setPopup: (popupSpec: PopupSpec | null) => void;
111112
isDragging?: boolean;
113+
onlyAssistant: boolean;
112114
}) {
113115
const { refreshUser } = useUser();
114116
const router = useRouter();
115117
const [showSharingModal, setShowSharingModal] = useState(false);
116118

117119
const isOwnedByUser = checkUserOwnsAssistant(user, assistant);
118-
const currentChosenAssistants = user?.preferences
119-
?.chosen_assistants as number[];
120120

121121
return (
122122
<>
@@ -192,13 +192,14 @@ function AssistantListItem({
192192
key="remove"
193193
className="flex items-center gap-x-2 px-4 py-2 hover:bg-gray-100 w-full text-left"
194194
onClick={async () => {
195-
if (currentChosenAssistants?.length === 1) {
195+
if (onlyAssistant) {
196196
setPopup({
197197
message: `Cannot remove "${assistant.name}" - you must have at least one assistant.`,
198198
type: "error",
199199
});
200200
return;
201201
}
202+
202203
const success = await removeAssistantFromList(
203204
assistant.id
204205
);
@@ -434,6 +435,7 @@ export function AssistantsList() {
434435
<div className="w-full items-center py-4">
435436
{currentlyVisibleAssistants.map((assistant, index) => (
436437
<DraggableAssistantListItem
438+
onlyAssistant={currentlyVisibleAssistants.length === 1}
437439
deleteAssistant={setDeletingPersona}
438440
shareAssistant={setMakePublicPersona}
439441
key={assistant.id}
@@ -463,6 +465,7 @@ export function AssistantsList() {
463465
<div className="w-full p-4">
464466
{ownedButHiddenAssistants.map((assistant, index) => (
465467
<AssistantListItem
468+
onlyAssistant={currentlyVisibleAssistants.length === 1}
466469
deleteAssistant={setDeletingPersona}
467470
shareAssistant={setMakePublicPersona}
468471
key={assistant.id}

web/src/lib/assistants/fetchPersonaEditorInfoSS.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@ import {
88
} from "@/app/admin/configuration/llm/interfaces";
99
import { ToolSnapshot } from "../tools/interfaces";
1010
import { fetchToolsSS } from "../tools/fetchTools";
11-
import {
12-
OpenAIIcon,
13-
AnthropicIcon,
14-
AWSIcon,
15-
AzureIcon,
16-
OpenSourceIcon,
17-
} from "@/components/icons/icons";
1811

1912
export async function fetchAssistantEditorInfoSS(
2013
personaId?: number | string
@@ -104,15 +97,22 @@ export async function fetchAssistantEditorInfoSS(
10497
? ((await personaResponse.json()) as Persona)
10598
: null;
10699

107-
return [
108-
{
109-
ccPairs,
110-
documentSets,
111-
llmProviders,
112-
user,
113-
existingPersona,
114-
tools: toolsResponse,
115-
},
116-
null,
117-
];
100+
let error: string | null = null;
101+
if (existingPersona?.builtin_persona) {
102+
return [null, "cannot update builtin persona"];
103+
}
104+
105+
return (
106+
error || [
107+
{
108+
ccPairs,
109+
documentSets,
110+
llmProviders,
111+
user,
112+
existingPersona,
113+
tools: toolsResponse,
114+
},
115+
null,
116+
]
117+
);
118118
}

0 commit comments

Comments
 (0)