Skip to content

Commit

Permalink
ensure shared chats are shared (#2801)
Browse files Browse the repository at this point in the history
* ensure shared chats are shared

* k

* k

* nit

* k
  • Loading branch information
pablodanswer authored Oct 15, 2024
1 parent da46f61 commit 98e88e2
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 25 deletions.
25 changes: 24 additions & 1 deletion web/src/app/admin/assistants/lib.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FullLLMProvider } from "../configuration/llm/interfaces";
import { Persona, Prompt, StarterMessage } from "./interfaces";
import { Persona, StarterMessage } from "./interfaces";

interface PersonaCreationRequest {
name: string;
Expand Down Expand Up @@ -377,3 +377,26 @@ export function providersContainImageGeneratingSupport(
) {
return providers.some((provider) => provider.provider === "openai");
}

// Default fallback persona for when we must display a persona
// but assistant has access to none
export const defaultPersona: Persona = {
id: 0,
name: "Default Assistant",
description: "A default assistant",
is_visible: true,
is_public: true,
builtin_persona: false,
is_default_persona: true,
users: [],
groups: [],
document_sets: [],
prompts: [],
tools: [],
starter_messages: null,
display_priority: null,
search_start_date: null,
owner: null,
icon_shape: 50910,
icon_color: "#FF6F6F",
};
7 changes: 0 additions & 7 deletions web/src/app/chat/ChatPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2185,7 +2185,6 @@ export function ChatPage({
query={
messageHistory[i]?.query || undefined
}
personaName={liveAssistant.name}
citedDocuments={getCitedDocumentsFromMessage(
message
)}
Expand Down Expand Up @@ -2247,9 +2246,6 @@ export function ChatPage({
}
: undefined
}
isCurrentlyShowingRetrieved={
isShowingRetrieved
}
handleShowRetrieved={(messageNumber) => {
if (isShowingRetrieved) {
setSelectedMessageForDocDisplay(null);
Expand Down Expand Up @@ -2299,7 +2295,6 @@ export function ChatPage({
<AIMessage
currentPersona={liveAssistant}
messageId={message.messageId}
personaName={liveAssistant.name}
content={
<p className="text-red-700 text-sm my-auto">
{message.message}
Expand Down Expand Up @@ -2347,7 +2342,6 @@ export function ChatPage({
alternativeAssistant
}
messageId={null}
personaName={liveAssistant.name}
content={
<div
key={"Generating"}
Expand All @@ -2367,7 +2361,6 @@ export function ChatPage({
<AIMessage
currentPersona={liveAssistant}
messageId={-1}
personaName={liveAssistant.name}
content={
<p className="text-red-700 text-sm my-auto">
{loadingError}
Expand Down
4 changes: 0 additions & 4 deletions web/src/app/chat/message/Messages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,11 @@ export const AIMessage = ({
files,
selectedDocuments,
query,
personaName,
citedDocuments,
toolCall,
isComplete,
hasDocs,
handleFeedback,
isCurrentlyShowingRetrieved,
handleShowRetrieved,
handleSearchQueryEdit,
handleForceSearch,
Expand All @@ -153,13 +151,11 @@ export const AIMessage = ({
content: string | JSX.Element;
files?: FileDescriptor[];
query?: string;
personaName?: string;
citedDocuments?: [string, DanswerDocument][] | null;
toolCall?: ToolCallMetadata;
isComplete?: boolean;
hasDocs?: boolean;
handleFeedback?: (feedbackType: FeedbackType) => void;
isCurrentlyShowingRetrieved?: boolean;
handleShowRetrieved?: (messageNumber: number | null) => void;
handleSearchQueryEdit?: (query: string) => void;
handleForceSearch?: () => void;
Expand Down
12 changes: 4 additions & 8 deletions web/src/app/chat/shared/[chatId]/SharedChatDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import {
import { AIMessage, HumanMessage } from "../../message/Messages";
import { Button, Callout, Divider } from "@tremor/react";
import { useRouter } from "next/navigation";
import { Persona } from "@/app/admin/assistants/interfaces";
import { useContext, useEffect, useState } from "react";
import { SettingsContext } from "@/components/settings/SettingsProvider";
import { DanswerInitializingLoader } from "@/components/DanswerInitializingLoader";
import { Persona } from "@/app/admin/assistants/interfaces";

function BackToDanswerButton() {
const router = useRouter();
Expand All @@ -34,10 +34,10 @@ function BackToDanswerButton() {

export function SharedChatDisplay({
chatSession,
availableAssistants,
persona,
}: {
chatSession: BackendChatSession | null;
availableAssistants: Persona[];
persona: Persona;
}) {
const [isReady, setIsReady] = useState(false);
useEffect(() => {
Expand All @@ -56,9 +56,6 @@ export function SharedChatDisplay({
</div>
);
}
const currentPersona = availableAssistants.find(
(persona) => persona.id === chatSession.persona_id
);

const messages = buildLatestMessageChain(
processRawChatHistory(chatSession.messages)
Expand Down Expand Up @@ -96,12 +93,11 @@ export function SharedChatDisplay({
return (
<AIMessage
shared
currentPersona={currentPersona!}
currentPersona={persona}
key={message.messageId}
messageId={message.messageId}
content={message.message}
files={message.files || []}
personaName={chatSession.persona_name}
citedDocuments={getCitedDocumentsFromMessage(message)}
isComplete
/>
Expand Down
13 changes: 8 additions & 5 deletions web/src/app/chat/shared/[chatId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { SharedChatDisplay } from "./SharedChatDisplay";
import { Persona } from "@/app/admin/assistants/interfaces";
import { fetchAssistantsSS } from "@/lib/assistants/fetchAssistantsSS";
import FunctionalHeader from "@/components/chat_search/Header";
import { defaultPersona } from "@/app/admin/assistants/lib";

async function getSharedChat(chatId: string) {
const response = await fetchSS(
Expand Down Expand Up @@ -43,7 +44,7 @@ export default async function Page({ params }: { params: { chatId: string } }) {
const authTypeMetadata = results[0] as AuthTypeMetadata | null;
const user = results[1] as User | null;
const chatSession = results[2] as BackendChatSession | null;
const [availableAssistants, _] = results[3] as [Persona[], string | null];
const availableAssistants = results[3] as Persona[] | null;

const authDisabled = authTypeMetadata?.authType === "disabled";
if (!authDisabled && !user) {
Expand All @@ -53,6 +54,11 @@ export default async function Page({ params }: { params: { chatId: string } }) {
if (user && !user.is_verified && authTypeMetadata?.requiresVerification) {
return redirect("/auth/waiting-on-verification");
}
const persona = chatSession?.persona_id
? (availableAssistants?.find((p) => p.id === chatSession.persona_id) ??
availableAssistants?.[0] ??
null)
: (availableAssistants?.[0] ?? defaultPersona);

return (
<div>
Expand All @@ -61,10 +67,7 @@ export default async function Page({ params }: { params: { chatId: string } }) {
</div>

<div className="flex relative bg-background text-default overflow-hidden pt-16 h-screen">
<SharedChatDisplay
chatSession={chatSession}
availableAssistants={availableAssistants}
/>
<SharedChatDisplay chatSession={chatSession} persona={persona!} />
</div>
</div>
);
Expand Down
1 change: 1 addition & 0 deletions web/src/components/chat_search/ProviderContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export function ProviderContextProvider({
const fetchProviderInfo = useCallback(async () => {
const { providers, options, defaultCheckSuccessful } =
await checkLlmProvider(user);

setValidProviderExists(providers.length > 0 && defaultCheckSuccessful);
setProviderOptions(options);
}, [user, setValidProviderExists, setProviderOptions]);
Expand Down

0 comments on commit 98e88e2

Please sign in to comment.