Skip to content

Commit

Permalink
update update flow + assistant creation
Browse files Browse the repository at this point in the history
  • Loading branch information
pablonyx committed Nov 24, 2024
1 parent ee2267f commit ccae1e9
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 43 deletions.
3 changes: 3 additions & 0 deletions backend/danswer/db/persona.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,9 @@ def upsert_persona(
validate_persona_tools(tools)

if persona:
if persona.builtin_persona and not builtin_persona:
raise ValueError("Cannot update builtin persona with non-builtin.")

# this checks if the user has permission to edit the persona
persona = fetch_persona_by_id(
db_session=db_session, persona_id=persona.id, user=user, get_editable=True
Expand Down
1 change: 1 addition & 0 deletions web/src/app/admin/assistants/AssistantEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ export function AssistantEditor({
if (!promptResponse.ok) {
error = await promptResponse.text();
}

if (!personaResponse) {
error = "Failed to create Assistant - no response received";
} else if (!personaResponse.ok) {
Expand Down
47 changes: 22 additions & 25 deletions web/src/app/admin/assistants/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,29 @@ export async function updatePersona(
): Promise<[Response, Response | null]> {
const { id, existingPromptId } = personaUpdateRequest;

// first update prompt
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;
if (existingPromptId !== undefined) {
promptResponse = await updatePrompt({
promptId: existingPromptId,
Expand All @@ -270,38 +290,15 @@ 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 : null;
}

let fileId = null;
if (personaUpdateRequest.uploaded_image) {
fileId = await uploadFile(personaUpdateRequest.uploaded_image);
if (!fileId) {
return [promptResponse, null];
}
}

const updatePersonaResponse =
promptResponse.ok && promptId
? 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
36 changes: 18 additions & 18 deletions web/src/lib/assistants/fetchPersonaEditorInfoSS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@ import {
} from "@/app/admin/configuration/llm/interfaces";
import { ToolSnapshot } from "../tools/interfaces";
import { fetchToolsSS } from "../tools/fetchTools";
import {
OpenAIIcon,
AnthropicIcon,
AWSIcon,
AzureIcon,
OpenSourceIcon,
} from "@/components/icons/icons";

export async function fetchAssistantEditorInfoSS(
personaId?: number | string
Expand Down Expand Up @@ -104,15 +97,22 @@ export async function fetchAssistantEditorInfoSS(
? ((await personaResponse.json()) as Persona)
: null;

return [
{
ccPairs,
documentSets,
llmProviders,
user,
existingPersona,
tools: toolsResponse,
},
null,
];
let error: string | null = null;
if (existingPersona?.builtin_persona) {
return [null, "cannot update builtin persona"];
}

return (
error || [
{
ccPairs,
documentSets,
llmProviders,
user,
existingPersona,
tools: toolsResponse,
},
null,
]
);
}

0 comments on commit ccae1e9

Please sign in to comment.