Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add avatars and adjust send button #14

Merged
merged 2 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"@patternfly/react-core": "^6.0.0",
"@patternfly/react-icons": "^6.0.0",
"@patternfly/react-styles": "^6.0.0",
"@patternfly/virtual-assistant": "^2.1.0-prerelease.8",
"@patternfly/virtual-assistant": "^2.1.0-prerelease.11",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"sirv-cli": "^2.0.2"
Expand Down
22 changes: 18 additions & 4 deletions src/app/BaseChatbot/BaseChatbot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,19 @@
import { HeaderDropdown } from '@app/HeaderDropdown/HeaderDropdown';
import { ERROR_TITLE, getId } from '@app/utils/utils';
import { Button } from '@patternfly/react-core';
import botAvatar from '@app/bgimages/RHCAI-studio-avatar.svg';
import userAvatar from '@app/bgimages/avatarImg.svg';

interface Source {
link: string;
}

const BaseChatbot: React.FunctionComponent = () => {
const { chatbots } = useLoaderData() as { chatbots: CannedChatbot[] };
const [isSendButtonDisabled, setIsSendButtonDisabled] = React.useState(true);
const [messages, setMessages] = React.useState<MessageProps[]>([]);
const [currentMessage, setCurrentMessage] = React.useState<string[]>([]);
const [currentSources, setCurrentSources] = React.useState<Source[]>();
const [isSendButtonDisabled, setIsSendButtonDisabled] = React.useState(false);
const scrollToBottomRef = React.useRef<HTMLDivElement>(null);
const [error, setError] = React.useState<{ title: string; body: string }>();
const [announcement, setAnnouncement] = React.useState<string>();
Expand All @@ -39,7 +42,7 @@

React.useEffect(() => {
document.title = `Red Hat Composer AI Studio | ${currentChatbot?.name}`;
}, []);

Check warning on line 45 in src/app/BaseChatbot/BaseChatbot.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook React.useEffect has a missing dependency: 'currentChatbot?.name'. Either include it or remove the dependency array

React.useEffect(() => {
document.title = `Red Hat Composer AI Studio | ${currentChatbot?.name}`;
Expand All @@ -47,7 +50,7 @@

React.useEffect(() => {
document.title = `Red Hat Composer AI Studio | ${currentChatbot?.name}${announcement ? ` - ${announcement}` : ''}`;
}, [announcement]);

Check warning on line 53 in src/app/BaseChatbot/BaseChatbot.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook React.useEffect has a missing dependency: 'currentChatbot?.name'. Either include it or remove the dependency array

// Auto-scrolls to the latest message
React.useEffect(() => {
Expand Down Expand Up @@ -170,6 +173,7 @@
const newMessages = structuredClone(messages);
if (currentMessage.length > 0) {
newMessages.push({
avatar: botAvatar,
id: getId(),
name: currentChatbot?.displayName,
role: 'bot',
Expand All @@ -184,6 +188,7 @@
setCurrentDate(undefined);
}
newMessages.push({
avatar: userAvatar,
id: getId(),
name: 'You',
role: 'user',
Expand All @@ -201,7 +206,6 @@
}
// make announcement to assistive devices that new message has been added
currentMessage.length > 0 && setAnnouncement(`Message from Chatbot: ${currentMessage.join('')}`);
setIsSendButtonDisabled(false);
setHasStopButton(false);
};

Expand All @@ -218,7 +222,6 @@
setCurrentSources(undefined);
setError(undefined);
setAnnouncement(undefined);
setIsSendButtonDisabled(false);
};

const handleStopButton = () => {
Expand All @@ -228,6 +231,14 @@
setHasStopButton(false);
};

const handleChange = (event: React.ChangeEvent<HTMLTextAreaElement>, value: string) => {
if (value !== '') {
setIsSendButtonDisabled(false);
return;
}
setIsSendButtonDisabled(true);
};

return (
<Chatbot displayMode={displayMode}>
<ChatbotHeader>
Expand Down Expand Up @@ -260,6 +271,7 @@
))}
{currentMessage.length > 0 && (
<Message
avatar={botAvatar}
name={currentChatbot?.displayName}
key="currentMessage"
role="bot"
Expand All @@ -276,9 +288,11 @@
onSendMessage={handleSend}
hasMicrophoneButton
hasAttachButton={false}
isSendButtonDisabled={isSendButtonDisabled}
hasStopButton={hasStopButton}
handleStopButton={handleStopButton}
alwayShowSendButton
onChange={handleChange}
isSendButtonDisabled={isSendButtonDisabled}
/>
<ChatbotFootnote label="Verify all information from this tool. LLMs make mistakes." />
</ChatbotFooter>
Expand Down
13 changes: 7 additions & 6 deletions src/app/Compare/CompareChild.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@
import { HeaderDropdown } from '@app/HeaderDropdown/HeaderDropdown';
import { ERROR_TITLE, getId } from '@app/utils/utils';
import { useChildStatus } from './ChildStatusProvider';
import botAvatar from '@app/bgimages/RHCAI-studio-avatar.svg';
import userAvatar from '@app/bgimages/avatarImg.svg';

interface Source {
link: string;
}

interface CompareChildProps {
chatbot: CannedChatbot;
allChatbots: CannedChatbot[];
setIsSendButtonDisabled: (bool: boolean) => void;
controller?: AbortController;
setController: (controller: AbortController | undefined) => void;
input?: string;
Expand All @@ -35,7 +37,6 @@
const CompareChild: React.FunctionComponent<CompareChildProps> = ({
chatbot,
allChatbots,
setIsSendButtonDisabled,
controller,
setController,
input,
Expand All @@ -57,12 +58,12 @@
const displayMode = ChatbotDisplayMode.embedded;

const handleSend = async (input: string) => {
setIsSendButtonDisabled(true);
const date = new Date();
const newMessages = structuredClone(messages);
// when a new message comes in, we add the last streaming message to the array and reset it
if (currentMessage.length > 0) {
newMessages.push({
avatar: botAvatar,
id: getId(),
name: currentChatbot?.displayName,
role: 'bot',
Expand All @@ -76,6 +77,7 @@
setCurrentSources(undefined);
}
newMessages.push({
avatar: userAvatar,
id: getId(),
name: 'You',
role: 'user',
Expand All @@ -94,7 +96,6 @@
}
// make announcement to assistive devices that new message has been added
currentMessage.length > 0 && setAnnouncement(`Message from Chatbot: ${currentMessage.join('')}`);
setIsSendButtonDisabled(false);
// this is used to control state of stop button
updateStatus(order === 'first' ? 'child1' : 'child2', { isMessageStreaming: false });
};
Expand All @@ -103,7 +104,7 @@
if (input) {
handleSend(input);
}
}, [hasNewInput]);

Check warning on line 107 in src/app/Compare/CompareChild.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook React.useEffect has missing dependencies: 'handleSend' and 'input'. Either include them or remove the dependency array

// Auto-scrolls to the latest message
React.useEffect(() => {
Expand Down Expand Up @@ -136,6 +137,7 @@

// fixme this is getting too large; we should refactor
async function fetchData(userMessage: string) {
updateStatus(order === 'first' ? 'child1' : 'child2', { isMessageStreaming: true });
if (controller) {
controller.abort();
}
Expand Down Expand Up @@ -168,7 +170,6 @@
throw new Error('Other');
}
}
updateStatus(order === 'first' ? 'child1' : 'child2', { isMessageStreaming: true });

// start reading the streaming message
const reader = response.body.getReader();
Expand Down Expand Up @@ -232,7 +233,6 @@
setCurrentSources(undefined);
setError(undefined);
setAnnouncement(undefined);
setIsSendButtonDisabled(false);
setChatbot(value);
setSearchParams(_event, value.name, order);
updateStatus(order === 'first' ? 'child1' : 'child2', {
Expand Down Expand Up @@ -267,6 +267,7 @@
))}
{currentMessage.length > 0 && (
<Message
avatar={botAvatar}
name={currentChatbot?.displayName}
key="currentMessage"
role="bot"
Expand Down
17 changes: 13 additions & 4 deletions src/app/Compare/CompareLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
const { chatbots } = useLoaderData() as { chatbots: CannedChatbot[] };

// state
const [isSendButtonDisabled, setIsSendButtonDisabled] = React.useState(false);
const [isSendButtonDisabled, setIsSendButtonDisabled] = React.useState(true);
const [input, setInput] = React.useState<string>();
const [hasNewInput, setHasNewInput] = React.useState(false);
const [firstController, setFirstController] = React.useState<AbortController>();
Expand Down Expand Up @@ -67,7 +67,7 @@
return () => {
window.removeEventListener('resize', updateChatbotVisibility);
};
}, []);

Check warning on line 70 in src/app/Compare/CompareLayout.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook React.useEffect has missing dependencies: 'assistants', 'chatbots', and 'navigate'. Either include them or remove the dependency array

React.useEffect(() => {
if (status) {
Expand Down Expand Up @@ -97,6 +97,7 @@
const handleSend = (value: string) => {
setInput(value);
setHasNewInput(!hasNewInput);
setIsSendButtonDisabled(true);
};

const changeSearchParams = (_event, value: string, order: string) => {
Expand All @@ -118,6 +119,14 @@
setHasStopButton(false);
};

const handleChange = (event: React.ChangeEvent<HTMLTextAreaElement>, value: string) => {
if (value !== '') {
setIsSendButtonDisabled(false);
return;
}
setIsSendButtonDisabled(true);
};

return (
firstChatbot &&
secondChatbot && (
Expand Down Expand Up @@ -147,7 +156,6 @@
allChatbots={chatbots}
controller={firstController}
setController={setFirstController}
setIsSendButtonDisabled={setIsSendButtonDisabled}
input={input}
setChatbot={setFirstChatbot}
hasNewInput={hasNewInput}
Expand All @@ -161,7 +169,6 @@
allChatbots={chatbots}
controller={secondController}
setController={setSecondController}
setIsSendButtonDisabled={setIsSendButtonDisabled}
input={input}
setChatbot={setSecondChatbot}
hasNewInput={hasNewInput}
Expand All @@ -175,9 +182,11 @@
onSendMessage={handleSend}
hasMicrophoneButton
hasAttachButton={false}
isSendButtonDisabled={isSendButtonDisabled}
hasStopButton={hasStopButton}
handleStopButton={handleStopButton}
alwayShowSendButton
onChange={handleChange}
isSendButtonDisabled={isSendButtonDisabled}
/>
<ChatbotFootnote label="Verify all information from this tool. LLMs make mistakes." />
</ChatbotFooter>
Expand Down
6 changes: 6 additions & 0 deletions src/app/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,9 @@ pf-v6-c-page__main-container.pf-m-fill {
}
}
}

.pf-chatbot__message.pf-chatbot__message--user {
img {
border: 1px solid var(--pf-t--global--border--color--default);
}
}
11 changes: 11 additions & 0 deletions src/app/bgimages/RHCAI-studio-avatar.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions src/app/bgimages/avatarImg.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading