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

Draft: Deprecate default avatar #213

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import Message from '@patternfly/virtual-assistant/dist/dynamic/Message';
import patternflyAvatar from './patternfly_avatar.jpg';

export const AttachmentMenuExample: React.FunctionComponent = () => {
const markdown = `
Expand Down Expand Up @@ -35,9 +35,15 @@ export default MessageLoading;
`;
return (
<>
<Message name="Bot" role="bot" content="Example content with updated timestamp text" timestamp="1 hour ago" />
<Message name="Bot" role="bot" content={markdown} />
<Message name="Bot" role="bot" content="Example content" isLoading />
<Message
name="Bot"
role="bot"
avatar={patternflyAvatar}
content="Example content with updated timestamp text"
timestamp="1 hour ago"
/>
<Message name="Bot" role="bot" avatar={patternflyAvatar} content={markdown} />
<Message name="Bot" role="bot" avatar={patternflyAvatar} content="Example content" isLoading />
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import AttachmentEdit from '@patternfly/virtual-assistant/dist/dynamic/Attachmen
import SourcesCard from '@patternfly/virtual-assistant/dist/dynamic/SourcesCard';
import customImage from './custom_user_img.jpeg';
import { RobotIcon } from '@patternfly/react-icons/dist/esm/icons/robot-icon';
import patternflyAvatar from './patternfly_avatar.jpg';
import userAvatar from './user_avatar.jpg';

The `content` prop of the `<Message>` component is passed to a `<Markdown>` component (from [react-markdown](https://remarkjs.github.io/react-markdown/)), which is configured to translate plain text strings into PatternFly [`<Content>` components](/components/content) and code blocks into PatternFly [`<CodeBlock>` components.](/components/code-block)

Expand Down Expand Up @@ -77,7 +79,7 @@ You can add actions to a message, to allow users to interact with the message co

### Messages with sources

If you are using Retrieval-Augmented Generation, you may want to display sources in a message. Passing `sources` to `<Message>` allows you to paginate between the sources you provide.
If you are using Retrieval-Augmented Generation, you may want to display sources in a message. Passing `sources` to `<Message>` allows you to paginate between the sources you provide.

The API for a source requires a link at minimum, but we strongly recommend providing a more descriptive title and body description so users have enough context. The title is limited to 1 line and the body is limited to 2 lines.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React from 'react';
import Message from '@patternfly/virtual-assistant/dist/dynamic/Message';
import PreviewAttachment from '@patternfly/virtual-assistant/dist/dynamic/PreviewAttachment';
import AttachmentEdit from '@patternfly/virtual-assistant/dist/dynamic/AttachmentEdit';
import userAvatar from './user_avatar.jpg';

export const AttachmentMenuExample: React.FunctionComponent = () => {
const [isPreviewModalOpen, setIsPreviewModalOpen] = React.useState<boolean>(false);
Expand All @@ -14,6 +15,7 @@ export const AttachmentMenuExample: React.FunctionComponent = () => {
<Message
name="User"
role="user"
avatar={userAvatar}
content="Here is an uploaded file"
attachmentName="auth-operator.yml"
attachmentId="1"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React from 'react';

import Message from '@patternfly/virtual-assistant/dist/dynamic/Message';
import patternflyAvatar from './patternfly_avatar.jpg';

export const AttachmentMenuExample: React.FunctionComponent = () => (
<Message
name="Bot"
role="bot"
avatar={patternflyAvatar}
content="Example content with updated timestamp text"
timestamp="1 hour ago"
actions={{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import Message from '@patternfly/virtual-assistant/dist/dynamic/Message';
import patternflyAvatar from './patternfly_avatar.jpg';

export const AttachmentMenuExample: React.FunctionComponent = () => {
const onSetPage = (_event: React.MouseEvent | React.KeyboardEvent | MouseEvent, newPage: number) => {
Expand All @@ -13,6 +13,7 @@ export const AttachmentMenuExample: React.FunctionComponent = () => {
<Message
name="Bot"
role="bot"
avatar={patternflyAvatar}
content="Example with sources"
sources={{
sources: [
Expand All @@ -38,6 +39,7 @@ export const AttachmentMenuExample: React.FunctionComponent = () => {
<Message
name="Bot"
role="bot"
avatar={patternflyAvatar}
content="Example with very long sources"
sources={{
sources: [
Expand All @@ -58,6 +60,7 @@ export const AttachmentMenuExample: React.FunctionComponent = () => {
<Message
name="Bot"
role="bot"
avatar={patternflyAvatar}
content="Example with only one source"
sources={{
sources: [
Expand All @@ -73,6 +76,7 @@ export const AttachmentMenuExample: React.FunctionComponent = () => {
<Message
name="Bot"
role="bot"
avatar={patternflyAvatar}
content="Example with sources that include a title and link"
sources={{
sources: [
Expand All @@ -92,6 +96,7 @@ export const AttachmentMenuExample: React.FunctionComponent = () => {
<Message
name="Bot"
role="bot"
avatar={patternflyAvatar}
content="Example with link-only sources (not recommended)"
sources={{
sources: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';

import Message from '@patternfly/virtual-assistant/dist/dynamic/Message';
import userAvatar from './user_avatar.jpg';
import customImage from './custom_user_img.jpeg';

export const AttachmentMenuExample: React.FunctionComponent = () => {
Expand All @@ -19,7 +20,7 @@ Here is an inline code - \`() => void\``;
timestamp="1 hour ago"
avatar={customImage}
/>
<Message name="User" role="user" content={markdown} />
<Message name="User" role="user" content={markdown} avatar={userAvatar} />
</>
);
};
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ import OpenDrawerRightIcon from '@patternfly/react-icons/dist/esm/icons/open-dra
import OutlinedWindowRestoreIcon from '@patternfly/react-icons/dist/esm/icons/outlined-window-restore-icon';
import PFIconLogoColor from '../ChatbotHeader/PF-IconLogo-Color.svg';
import PFIconLogoReverse from '../ChatbotHeader/PF-IconLogo-Reverse.svg';
import userAvatar from '../ChatbotMessage/user_avatar.jpg';
import patternflyAvatar from '../ChatbotMessage/patternfly_avatar.jpg';

# Demos

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ import PFHorizontalLogoColor from '../ChatbotHeader/PF-HorizontalLogo-Color.svg'
import PFHorizontalLogoReverse from '../ChatbotHeader/PF-HorizontalLogo-Reverse.svg';
import PFIconLogoColor from '../ChatbotHeader/PF-IconLogo-Color.svg';
import PFIconLogoReverse from '../ChatbotHeader/PF-IconLogo-Reverse.svg';
import userAvatar from '../ChatbotMessage/user_avatar.jpg';
import patternflyAvatar from '../ChatbotMessage/patternfly_avatar.jpg';

### Basic chatbot

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import PFHorizontalLogoColor from '../ChatbotHeader/PF-HorizontalLogo-Color.svg'
import PFHorizontalLogoReverse from '../ChatbotHeader/PF-HorizontalLogo-Reverse.svg';
import PFIconLogoColor from '../ChatbotHeader/PF-IconLogo-Color.svg';
import PFIconLogoReverse from '../ChatbotHeader/PF-IconLogo-Reverse.svg';
import userAvatar from '../ChatbotMessage/user_avatar.jpg';
import patternflyAvatar from '../ChatbotMessage/patternfly_avatar.jpg';

const footnoteProps = {
label: 'Lightspeed uses AI. Check for mistakes.',
Expand Down Expand Up @@ -93,12 +95,14 @@ const initialMessages: MessageProps[] = [
{
role: 'user',
content: 'Hello, can you give me an example of what you can do?',
name: 'User'
name: 'User',
avatar: userAvatar
},
{
role: 'bot',
content: markdown,
name: 'Bot',
avatar: patternflyAvatar,
actions: {
// eslint-disable-next-line no-console
positive: { onClick: () => console.log('Good response') },
Expand Down Expand Up @@ -191,12 +195,13 @@ export const ChatbotDemo: React.FunctionComponent = () => {
// we can't use structuredClone since messages contains functions, but we can't mutate
// items that are going into state or the UI won't update correctly
messages.forEach((message) => newMessages.push(message));
newMessages.push({ role: 'user', content: message, name: 'User' });
newMessages.push({ role: 'user', content: message, name: 'User', avatar: userAvatar });
newMessages.push({
role: 'bot',
content: 'API response goes here',
name: 'bot',
isLoading: true
isLoading: true,
avatar: patternflyAvatar
});
setMessages(newMessages);

Expand All @@ -212,6 +217,7 @@ export const ChatbotDemo: React.FunctionComponent = () => {
content: 'API response goes here',
name: 'bot',
isLoading: false,
avatar: patternflyAvatar,
actions: {
// eslint-disable-next-line no-console
positive: { onClick: () => console.log('Good response') },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import PFHorizontalLogoColor from '../ChatbotHeader/PF-HorizontalLogo-Color.svg'
import PFHorizontalLogoReverse from '../ChatbotHeader/PF-HorizontalLogo-Reverse.svg';
import PFIconLogoColor from '../ChatbotHeader/PF-IconLogo-Color.svg';
import PFIconLogoReverse from '../ChatbotHeader/PF-IconLogo-Reverse.svg';
import userAvatar from '../ChatbotMessage/user_avatar.jpg';
import patternflyAvatar from '../ChatbotMessage/patternfly_avatar.jpg';

interface ModalData {
code: string;
Expand All @@ -51,6 +53,7 @@ export const BasicDemo: React.FunctionComponent = () => {
role: 'user',
content: "I'm referring to this attachment for added context in our conversation.",
name: 'User',
avatar: userAvatar,
attachmentName: 'auth-operator.yml',
attachmentId: '1',
onAttachmentClose,
Expand All @@ -63,6 +66,7 @@ export const BasicDemo: React.FunctionComponent = () => {
{
role: 'bot',
content: 'Great, I can reference this attachment throughout our conversation.',
avatar: patternflyAvatar,
name: 'Bot'
}
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { Divider, DropdownGroup, DropdownItem, DropdownList, DropEvent } from '@
import FileDetailsLabel from '@patternfly/virtual-assistant/dist/dynamic/FileDetailsLabel';
import { BellIcon, CalendarAltIcon, ClipboardIcon, CodeIcon, UploadIcon } from '@patternfly/react-icons';
import { useDropzone } from 'react-dropzone';
import userAvatar from '../ChatbotMessage/user_avatar.jpg';
import patternflyAvatar from '../ChatbotMessage/patternfly_avatar.jpg';

const initialMenuItems = [
<DropdownList key="list-1">
Expand Down Expand Up @@ -68,12 +70,14 @@ const messages: MessageProps[] = [
{
role: 'user',
content: 'Hello, can you give me an example of what you can do?',
name: 'User'
name: 'User',
avatar: userAvatar
},
{
role: 'bot',
content: 'I sure can!',
name: 'Bot'
name: 'Bot',
avatar: patternflyAvatar
}
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import ChatbotHeader, {
import PFHorizontalLogoColor from '../ChatbotHeader/PF-HorizontalLogo-Color.svg';
import PFHorizontalLogoReverse from '../ChatbotHeader/PF-HorizontalLogo-Reverse.svg';
import { BarsIcon } from '@patternfly/react-icons';
import userAvatar from '../ChatbotMessage/user_avatar.jpg';
import patternflyAvatar from '../ChatbotMessage/patternfly_avatar.jpg';

const footnoteProps = {
label: 'Lightspeed uses AI. Check for mistakes.',
Expand Down Expand Up @@ -100,12 +102,14 @@ const initialMessages: MessageProps[] = [
{
role: 'user',
content: 'Hello, can you give me an example of what you can do?',
name: 'User'
name: 'User',
avatar: userAvatar
},
{
role: 'bot',
content: markdown,
name: 'Bot',
avatar: patternflyAvatar,
actions: {
// eslint-disable-next-line no-console
positive: { onClick: () => console.log('Good response') },
Expand Down Expand Up @@ -190,11 +194,12 @@ export const EmbeddedChatbotDemo: React.FunctionComponent = () => {
// we can't use structuredClone since messages contains functions, but we can't mutate
// items that are going into state or the UI won't update correctly
messages.forEach((message) => newMessages.push(message));
newMessages.push({ role: 'user', content: message, name: 'User' });
newMessages.push({ role: 'user', content: message, name: 'User', avatar: userAvatar });
newMessages.push({
role: 'bot',
content: 'API response goes here',
name: 'bot',
avatar: patternflyAvatar,
isLoading: true
});
setMessages(newMessages);
Expand All @@ -210,6 +215,7 @@ export const EmbeddedChatbotDemo: React.FunctionComponent = () => {
role: 'bot',
content: 'API response goes here',
name: 'bot',
avatar: patternflyAvatar,
isLoading: false,
actions: {
// eslint-disable-next-line no-console
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 4 additions & 18 deletions packages/module/src/Message/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ export interface MessageProps extends Omit<React.HTMLProps<HTMLDivElement>, 'rol
/** Role of the user sending the message */
role: 'user' | 'bot';
/** Message content */
content: string;
content?: string;
/** Name of the user */
name?: string;
name: string;
/** Avatar src for the user */
avatar?: string;
avatar: string;
/** Alt text placed on the avatar */
avatarAltText?: string;
/** Timestamp for the message */
Expand Down Expand Up @@ -66,27 +66,13 @@ export const Message: React.FunctionComponent<MessageProps> = ({
avatarAltText,
...props
}: MessageProps) => {
// Configure default values

const DEFAULTS = {
user: {
name: 'User',
avatar: 'https://img.freepik.com/premium-photo/graphic-designer-digital-avatar-generative-ai_934475-9292.jpg'
},
bot: {
name: 'Bot',
avatar:
'https://yt3.googleusercontent.com/ej8uvIe1AIFiJQXBwY9cfJmt0kO1cAeWxpBqG_cJndGHx95mFq1F8WakSoXIjtcprTbMQJoqH5M=s900-c-k-c0x00ffffff-no-rj'
}
};

const onClose = () => {
onAttachmentClose && attachmentId && onAttachmentClose(attachmentId);
};

return (
<div className={`pf-chatbot__message pf-chatbot__message--${role}`} {...props}>
<Avatar src={avatar ?? DEFAULTS[role].avatar} alt={avatarAltText || `Profile picture of ${role}`} />
<Avatar src={avatar} alt={avatarAltText || `Profile picture of ${role}`} />
<div className="pf-chatbot__message-contents">
<div className="pf-chatbot__message-meta">
<span className="pf-chatbot__message-name">{name}</span>
Expand Down
Loading