ensure shared chats are shared (#2801)

* ensure shared chats are shared

* k

* k

* nit

* k
This commit is contained in:
pablodanswer 2024-10-15 10:26:01 -07:00 committed by GitHub
parent da46f61123
commit 98e88e2715
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 37 additions and 25 deletions

View File

@ -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;
@ -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",
};

View File

@ -2185,7 +2185,6 @@ export function ChatPage({
query={
messageHistory[i]?.query || undefined
}
personaName={liveAssistant.name}
citedDocuments={getCitedDocumentsFromMessage(
message
)}
@ -2247,9 +2246,6 @@ export function ChatPage({
}
: undefined
}
isCurrentlyShowingRetrieved={
isShowingRetrieved
}
handleShowRetrieved={(messageNumber) => {
if (isShowingRetrieved) {
setSelectedMessageForDocDisplay(null);
@ -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}
@ -2347,7 +2342,6 @@ export function ChatPage({
alternativeAssistant
}
messageId={null}
personaName={liveAssistant.name}
content={
<div
key={"Generating"}
@ -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}

View File

@ -124,13 +124,11 @@ export const AIMessage = ({
files,
selectedDocuments,
query,
personaName,
citedDocuments,
toolCall,
isComplete,
hasDocs,
handleFeedback,
isCurrentlyShowingRetrieved,
handleShowRetrieved,
handleSearchQueryEdit,
handleForceSearch,
@ -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;

View File

@ -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();
@ -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(() => {
@ -56,9 +56,6 @@ export function SharedChatDisplay({
</div>
);
}
const currentPersona = availableAssistants.find(
(persona) => persona.id === chatSession.persona_id
);
const messages = buildLatestMessageChain(
processRawChatHistory(chatSession.messages)
@ -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
/>

View File

@ -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(
@ -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) {
@ -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>
@ -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>
);

View File

@ -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]);