Skip to content

Commit

Permalink
Merge pull request #3255 from danswer-ai/hotfix/v0.14-llm_assistant
Browse files Browse the repository at this point in the history
Hotfix/v0.14 llm assistant
  • Loading branch information
pablonyx authored Nov 26, 2024
2 parents 4e85524 + 8427c38 commit a038c05
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 60 deletions.
8 changes: 4 additions & 4 deletions backend/danswer/db/persona.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,9 @@ def upsert_prompt(
return prompt


# NOTE: This operation cannot update persona configuration options that
# are core to the persona, such as its display priority and
# whether or not the assistant is a built-in / default assistant
def upsert_persona(
user: User | None,
name: str,
Expand Down Expand Up @@ -459,7 +462,7 @@ def upsert_persona(
validate_persona_tools(tools)

if persona:
if not builtin_persona and persona.builtin_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
Expand All @@ -475,7 +478,6 @@ def upsert_persona(
persona.llm_relevance_filter = llm_relevance_filter
persona.llm_filter_extraction = llm_filter_extraction
persona.recency_bias = recency_bias
persona.builtin_persona = builtin_persona
persona.llm_model_provider_override = llm_model_provider_override
persona.llm_model_version_override = llm_model_version_override
persona.starter_messages = starter_messages
Expand All @@ -485,10 +487,8 @@ def upsert_persona(
persona.icon_shape = icon_shape
if remove_image or uploaded_image_id:
persona.uploaded_image_id = uploaded_image_id
persona.display_priority = display_priority
persona.is_visible = is_visible
persona.search_start_date = search_start_date
persona.is_default_persona = is_default_persona
persona.category_id = category_id
# Do not delete any associations manually added unless
# a new updated list is provided
Expand Down
3 changes: 3 additions & 0 deletions backend/danswer/server/features/persona/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ def create_persona(
)


# NOTE: This endpoint cannot update persona configuration options that
# are core to the persona, such as its display priority and
# whether or not the assistant is a built-in / default assistant
@basic_router.patch("/{persona_id}")
def update_persona(
persona_id: int,
Expand Down
1 change: 0 additions & 1 deletion backend/danswer/server/manage/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,6 @@ def update_user_assistant_list(
if user is None:
if AUTH_TYPE == AuthType.DISABLED:
store = get_kv_store()

no_auth_user = fetch_no_auth_user(store)
no_auth_user.preferences.chosen_assistants = request.chosen_assistants
set_no_auth_user_preferences(store, no_auth_user.preferences)
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
10 changes: 5 additions & 5 deletions web/src/app/assistants/gallery/AssistantsGallery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,19 @@ import {
} from "@/components/ui/select";

export function AssistantGalleryCard({
onlyAssistant,
assistant,
user,
setPopup,
selectedAssistant,
}: {
onlyAssistant: boolean;
assistant: Persona;
user: User | null;
setPopup: (popup: PopupSpec) => void;
selectedAssistant: boolean;
}) {
const { data: categories } = useCategories();

const { refreshUser } = useUser();

return (
Expand Down Expand Up @@ -83,10 +84,7 @@ export function AssistantGalleryCard({
"
icon={FiMinus}
onClick={async () => {
if (
user.preferences?.chosen_assistants &&
user.preferences?.chosen_assistants.length === 1
) {
if (onlyAssistant) {
setPopup({
message: `Cannot remove "${assistant.name}" - you must have at least one assistant.`,
type: "error",
Expand Down Expand Up @@ -356,6 +354,7 @@ export function AssistantsGallery() {
>
{defaultAssistants.map((assistant) => (
<AssistantGalleryCard
onlyAssistant={visibleAssistants.length === 1}
selectedAssistant={visibleAssistants.includes(assistant)}
key={assistant.id}
assistant={assistant}
Expand Down Expand Up @@ -389,6 +388,7 @@ export function AssistantsGallery() {
>
{nonDefaultAssistants.map((assistant) => (
<AssistantGalleryCard
onlyAssistant={visibleAssistants.length === 1}
selectedAssistant={visibleAssistants.includes(assistant)}
key={assistant.id}
assistant={assistant}
Expand Down
11 changes: 7 additions & 4 deletions web/src/app/assistants/mine/AssistantsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ import { CustomTooltip } from "@/components/tooltip/CustomTooltip";
import { useAssistants } from "@/components/context/AssistantsContext";
import { useUser } from "@/components/user/UserProvider";

function DraggableAssistantListItem(props: any) {
function DraggableAssistantListItem({ ...props }: any) {
const {
attributes,
listeners,
Expand Down Expand Up @@ -100,6 +100,7 @@ function AssistantListItem({
deleteAssistant,
shareAssistant,
isDragging,
onlyAssistant,
}: {
assistant: Persona;
user: User | null;
Expand All @@ -109,14 +110,13 @@ function AssistantListItem({
shareAssistant: Dispatch<SetStateAction<Persona | null>>;
setPopup: (popupSpec: PopupSpec | null) => void;
isDragging?: boolean;
onlyAssistant: boolean;
}) {
const { refreshUser } = useUser();
const router = useRouter();
const [showSharingModal, setShowSharingModal] = useState(false);

const isOwnedByUser = checkUserOwnsAssistant(user, assistant);
const currentChosenAssistants = user?.preferences
?.chosen_assistants as number[];

return (
<>
Expand Down Expand Up @@ -192,13 +192,14 @@ function AssistantListItem({
key="remove"
className="flex items-center gap-x-2 px-4 py-2 hover:bg-gray-100 w-full text-left"
onClick={async () => {
if (currentChosenAssistants?.length === 1) {
if (onlyAssistant) {
setPopup({
message: `Cannot remove "${assistant.name}" - you must have at least one assistant.`,
type: "error",
});
return;
}

const success = await removeAssistantFromList(
assistant.id
);
Expand Down Expand Up @@ -432,6 +433,7 @@ export function AssistantsList() {
<div className="w-full items-center py-4">
{currentlyVisibleAssistants.map((assistant, index) => (
<DraggableAssistantListItem
onlyAssistant={currentlyVisibleAssistants.length === 1}
deleteAssistant={setDeletingPersona}
shareAssistant={setMakePublicPersona}
key={assistant.id}
Expand Down Expand Up @@ -461,6 +463,7 @@ export function AssistantsList() {
<div className="w-full p-4">
{ownedButHiddenAssistants.map((assistant, index) => (
<AssistantListItem
onlyAssistant={currentlyVisibleAssistants.length === 1}
deleteAssistant={setDeletingPersona}
shareAssistant={setMakePublicPersona}
key={assistant.id}
Expand Down
4 changes: 2 additions & 2 deletions web/src/app/chat/ChatPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
useLayoutEffect,
useRef,
useState,
useMemo,
} from "react";
import { usePopup } from "@/components/admin/connectors/Popup";
import { SEARCH_PARAM_NAMES, shouldSubmitOnLoad } from "./searchParams";
Expand Down Expand Up @@ -266,7 +267,6 @@ export function ChatPage({
availableAssistants[0];

const noAssistants = liveAssistant == null || liveAssistant == undefined;

// always set the model override for the chat session, when an assistant, llm provider, or user preference exists
useEffect(() => {
const personaDefault = getLLMProviderOverrideForPersona(
Expand All @@ -282,7 +282,7 @@ export function ChatPage({
);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [liveAssistant, llmProviders, user?.preferences.default_model]);
}, [liveAssistant, user?.preferences.default_model]);

const stopGenerating = () => {
const currentSession = currentSessionId();
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,
]
);
}
1 change: 0 additions & 1 deletion web/src/lib/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ export function useLlmOverride(
modelName: "",
}
);

const [llmOverride, setLlmOverride] = useState<LlmOverride>(
currentChatSession && currentChatSession.current_alternate_model
? destructureValue(currentChatSession.current_alternate_model)
Expand Down

0 comments on commit a038c05

Please sign in to comment.