Markdown Toggle

Makes it easier to compare/contrast what Markdown support adds
This commit is contained in:
Chris Kent 2024-02-08 12:44:03 -05:00
parent 8b0388beda
commit 9c8bfe0c9b
5 changed files with 33 additions and 6 deletions

View File

@ -6,6 +6,7 @@ import MarkdownContent from "./MarkdownContent";
export interface IAssistantResponseProps { export interface IAssistantResponseProps {
message: string; message: string;
disableMarkdown?: boolean;
} }
export default class AssistantResponse extends React.Component< export default class AssistantResponse extends React.Component<
@ -19,7 +20,12 @@ export default class AssistantResponse extends React.Component<
<Icon iconName="Robot" /> <Icon iconName="Robot" />
</div> </div>
<div className={styles.messageBox}> <div className={styles.messageBox}>
{this.props.disableMarkdown &&
<p className={styles.message}>{this.props.message}</p>
}
{!this.props.disableMarkdown &&
<MarkdownContent className={styles.message}>{this.props.message}</MarkdownContent> <MarkdownContent className={styles.message}>{this.props.message}</MarkdownContent>
}
<div className={styles.beak}/> <div className={styles.beak}/>
</div> </div>
</Stack> </Stack>

View File

@ -25,7 +25,8 @@ export default class ChatStreaming extends React.Component<IChatStreamingProps,
role: 'assistant', role: 'assistant',
text: 'Hello! I am your AI assistant. How can I help you today?' text: 'Hello! I am your AI assistant. How can I help you today?'
}], }],
thinking: false thinking: false,
disableMarkdown: false,
} }
this._controller = new AbortController(); this._controller = new AbortController();
@ -37,7 +38,7 @@ export default class ChatStreaming extends React.Component<IChatStreamingProps,
const content = this._validateWebPartProperties() ? ( const content = this._validateWebPartProperties() ? (
<Stack className={css(styles.chatStreaming, this.props.hasTeamsContext && styles.teams)}> <Stack className={css(styles.chatStreaming, this.props.hasTeamsContext && styles.teams)}>
<Stack.Item grow className={styles.messagesContainer}> <Stack.Item grow className={styles.messagesContainer}>
<MessagesList messages={this.state.sessionMessages} /> <MessagesList messages={this.state.sessionMessages} disableMarkdown={this.state.disableMarkdown} />
</Stack.Item> </Stack.Item>
{this.state.thinking && ( {this.state.thinking && (
<Stack.Item> <Stack.Item>
@ -52,9 +53,11 @@ export default class ChatStreaming extends React.Component<IChatStreamingProps,
<Stack.Item> <Stack.Item>
<UserMessage <UserMessage
textFieldValue={this.state.userQuery} textFieldValue={this.state.userQuery}
onMessageChange={this._onUserQueryChange} onMessageChange={this._onUserQueryChange.bind(this)}
sendQuery={this._onQuerySent} sendQuery={this._onQuerySent.bind(this)}
controller={this._controller} controller={this._controller}
disableMarkdown={this.state.disableMarkdown}
toggleMarkdown={this._toggleMarkdown.bind(this)}
/> />
</Stack.Item> </Stack.Item>
</Stack> </Stack>
@ -175,4 +178,10 @@ export default class ChatStreaming extends React.Component<IChatStreamingProps,
return true; return true;
} }
private _toggleMarkdown(): void {
this.setState({
disableMarkdown: !this.state.disableMarkdown
});
}
} }

View File

@ -4,4 +4,5 @@ export interface IChatStreamingState {
userQuery: string; userQuery: string;
sessionMessages: IChatMessage[]; sessionMessages: IChatMessage[];
thinking: boolean; thinking: boolean;
disableMarkdown: boolean;
} }

View File

@ -8,6 +8,7 @@ import { ScrollablePane, ScrollbarVisibility } from '@fluentui/react';
export interface IMessagesListProps { export interface IMessagesListProps {
messages: IChatMessage[]; messages: IChatMessage[];
disableMarkdown?: boolean;
} }
export default class MessagesList extends React.Component<IMessagesListProps, {}> { export default class MessagesList extends React.Component<IMessagesListProps, {}> {
@ -27,7 +28,7 @@ export default class MessagesList extends React.Component<IMessagesListProps, {}
if (m.role === 'user') { if (m.role === 'user') {
return <UserQuestion key={i} message={m.text} /> return <UserQuestion key={i} message={m.text} />
} }
return <AssistantResponse key={i} message={m.text} /> return <AssistantResponse key={i} message={m.text} disableMarkdown={this.props.disableMarkdown} />
}); });
return ( return (

View File

@ -7,6 +7,8 @@ export interface IUserMessageProps {
sendQuery: () => Promise<void>; sendQuery: () => Promise<void>;
controller: AbortController; controller: AbortController;
textFieldValue: string; textFieldValue: string;
disableMarkdown?: boolean;
toggleMarkdown: () => void;
} }
export default class UserMessage extends React.Component<IUserMessageProps, {}> { export default class UserMessage extends React.Component<IUserMessageProps, {}> {
@ -37,6 +39,7 @@ export default class UserMessage extends React.Component<IUserMessageProps, {}>
<TextField <TextField
multiline multiline
autoAdjustHeight autoAdjustHeight
rows={5}
value={this.props.textFieldValue} value={this.props.textFieldValue}
onChange={this._onChange} onChange={this._onChange}
onKeyDown={this._keyDownHandler} onKeyDown={this._keyDownHandler}
@ -56,6 +59,13 @@ export default class UserMessage extends React.Component<IUserMessageProps, {}>
ariaLabel="Stop" ariaLabel="Stop"
onClick={() => this.props.controller.abort()} onClick={() => this.props.controller.abort()}
/> />
<IconButton
toggle
checked={!this.props.disableMarkdown}
onClick={this.props.toggleMarkdown}
title="Toggle Markdown"
ariaLabel="Markdown"
iconProps={{iconName:'MarkDownLanguage'}}/>
</Stack> </Stack>
</Stack> </Stack>
); );