Skip to content

Commit

Permalink
Fix assistant prompt zero-ing (#3293)
Browse files Browse the repository at this point in the history
  • Loading branch information
Weves authored Nov 30, 2024
1 parent 16863de commit f12eb4a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
4 changes: 3 additions & 1 deletion backend/danswer/db/persona.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def create_update_persona(
"persona_id": persona_id,
"user": user,
"db_session": db_session,
**create_persona_request.dict(exclude={"users", "groups"}),
**create_persona_request.model_dump(exclude={"users", "groups"}),
}

persona = upsert_persona(**persona_data)
Expand Down Expand Up @@ -758,6 +758,8 @@ def get_prompt_by_name(
if user and user.role != UserRole.ADMIN:
stmt = stmt.where(Prompt.user_id == user.id)

# Order by ID to ensure consistent result when multiple prompts exist
stmt = stmt.order_by(Prompt.id).limit(1)
result = db_session.execute(stmt).scalar_one_or_none()
return result

Expand Down
47 changes: 25 additions & 22 deletions web/src/app/admin/assistants/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,29 +259,8 @@ export async function updatePersona(
): Promise<[Response, Response | null]> {
const { id, existingPromptId } = personaUpdateRequest;

let fileId = null;
if (personaUpdateRequest.uploaded_image) {
fileId = await uploadFile(personaUpdateRequest.uploaded_image);
if (!fileId) {
return [new Response(null, { status: 400 }), null];
}
}

const updatePersonaResponse = await fetch(`/api/persona/${id}`, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(
buildPersonaAPIBody(personaUpdateRequest, existingPromptId ?? 0, fileId)
),
});

if (!updatePersonaResponse.ok) {
return [updatePersonaResponse, null];
}

let promptResponse;
let promptId: number | null = null;
if (existingPromptId !== undefined) {
promptResponse = await updatePrompt({
promptId: existingPromptId,
Expand All @@ -290,15 +269,39 @@ export async function updatePersona(
taskPrompt: personaUpdateRequest.task_prompt,
includeCitations: personaUpdateRequest.include_citations,
});
promptId = existingPromptId;
} else {
promptResponse = await createPrompt({
personaName: personaUpdateRequest.name,
systemPrompt: personaUpdateRequest.system_prompt,
taskPrompt: personaUpdateRequest.task_prompt,
includeCitations: personaUpdateRequest.include_citations,
});
promptId = promptResponse.ok
? ((await promptResponse.json()).id as number)
: null;
}
let fileId = null;
if (personaUpdateRequest.uploaded_image) {
fileId = await uploadFile(personaUpdateRequest.uploaded_image);
if (!fileId) {
return [promptResponse, null];
}
}

const updatePersonaResponse =
promptResponse.ok && promptId !== null
? await fetch(`/api/persona/${id}`, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(
buildPersonaAPIBody(personaUpdateRequest, promptId, fileId)
),
})
: null;

return [promptResponse, updatePersonaResponse];
}

Expand Down

0 comments on commit f12eb4a

Please sign in to comment.