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

[Chatbot] Add flag to disable traces #379

Open
wants to merge 2 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
### Features
### Enhancements
- feat: Hide navigate to discover button if alert is not from visual editor monitor([#368](https://github.com/opensearch-project/dashboards-assistant/pull/368))
- Add a flag in the config to control the trace view button in message bubbles ([#379](https://github.com/opensearch-project/dashboards-assistant/pull/379))

### Bug Fixes
- Optimize the response of AI agent APIs ([#373](https://github.com/opensearch-project/dashboards-assistant/pull/373))
Expand Down
1 change: 1 addition & 0 deletions common/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const configSchema = schema.object({
enabled: schema.boolean({ defaultValue: true }),
chat: schema.object({
enabled: schema.boolean({ defaultValue: false }),
trace: schema.boolean({ defaultValue: true }),
}),
incontextInsight: schema.object({
enabled: schema.boolean({ defaultValue: true }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ export const GeneratePopoverBody: React.FC<{
};

const renderInnerFooter = () => {
const traceTip = 'Insight With RAG';
return (
<EuiPopoverFooter className="incontextInsightGeneratePopoverFooter" paddingSize="none">
{
Expand All @@ -332,6 +333,7 @@ export const GeneratePopoverBody: React.FC<{
onViewTrace={() => {
setShowInsight(true);
}}
traceTip={traceTip}
usageCollection={usageCollection}
isOnTrace={showInsight}
metricAppName={metricAppName}
Expand All @@ -345,6 +347,7 @@ export const GeneratePopoverBody: React.FC<{
showFeedback
showTraceIcon={insightAvailable}
onViewTrace={() => {}}
traceTip={traceTip}
usageCollection={usageCollection}
isOnTrace={showInsight}
metricAppName={metricAppName}
Expand Down
4 changes: 3 additions & 1 deletion public/tabs/chat/messages/message_action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ interface MessageActionsProps {
showTraceIcon?: boolean;
isOnTrace?: boolean;
traceInteractionId?: string;
traceTip?: string;
onViewTrace?: () => void;
shouldActionBarVisibleOnHover?: boolean;
isFullWidth?: boolean;
Expand All @@ -44,6 +45,7 @@ export const MessageActions: React.FC<MessageActionsProps> = ({
showTraceIcon = false,
isOnTrace = false,
traceInteractionId = null,
traceTip = 'info',
onViewTrace,
shouldActionBarVisibleOnHover = false,
isFullWidth = false,
Expand Down Expand Up @@ -146,7 +148,7 @@ export const MessageActions: React.FC<MessageActionsProps> = ({
trace: {
show: showTraceIcon && onViewTrace,
component: renderButtonWithTooltip(
'Insight with RAG',
traceTip,
<EuiSmallButtonIcon
aria-label="How was this generated?"
{...(traceInteractionId && {
Expand Down
47 changes: 47 additions & 0 deletions public/tabs/chat/messages/message_bubble.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { render, screen, fireEvent } from '@testing-library/react';

import { MessageBubble } from './message_bubble';
import { IOutput } from '../../../../common/types/chat_saved_object_attributes';
import * as services from '../../../services';
import * as useFeedbackHookExports from '../../../hooks/use_feed_back';
import * as useChatActionsExports from '../../../hooks/use_chat_actions';
import * as coreHookExports from '../../../contexts/core_context';
Expand All @@ -18,6 +19,7 @@ describe('<MessageBubble />', () => {
const reportUiStatsMock = jest.fn();

beforeEach(() => {
jest.spyOn(services, 'getConfigSchema').mockReturnValue({ chat: { trace: true } });
jest
.spyOn(useFeedbackHookExports, 'useFeedback')
.mockReturnValue({ feedbackResult: undefined, sendFeedback: sendFeedbackMock });
Expand Down Expand Up @@ -289,4 +291,49 @@ describe('<MessageBubble />', () => {
);
expect(screen.queryByTestId('trace-icon-bar')).toBeNull();
});

it('should control view trace through config flag', () => {
render(
<MessageBubble
showActionBar={true}
showRegenerate={true}
message={{
type: 'output',
contentType: 'markdown',
content: 'here are the indices in your cluster: .alert',
interactionId: 'bar1',
}}
interaction={{
input: 'foo',
response: 'bar1',
conversation_id: 'foo',
interaction_id: 'bar1',
create_time: new Date().toLocaleString(),
}}
/>
);
expect(screen.queryByTestId('trace-icon-bar1')).toBeVisible();

jest.spyOn(services, 'getConfigSchema').mockReturnValue({ chat: { trace: false } });
render(
<MessageBubble
showActionBar={true}
showRegenerate={true}
message={{
type: 'output',
contentType: 'markdown',
content: 'here are the indices in your cluster: .alert',
interactionId: 'bar2',
}}
interaction={{
input: 'foo',
response: 'bar2',
conversation_id: 'foo',
interaction_id: 'bar2',
create_time: new Date().toLocaleString(),
}}
/>
);
expect(screen.queryByTestId('trace-icon-bar2')).toBeNull();
});
});
5 changes: 4 additions & 1 deletion public/tabs/chat/messages/message_bubble.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import React from 'react';
import { IconType } from '@elastic/eui/src/components/icon/icon';
import { MessageActions } from './message_action';
import { useCore } from '../../../contexts';
import { getConfigSchema } from '../../../services';

// TODO: Replace with getChrome().logos.Chat.url
import { useChatActions } from '../../../hooks';
Expand Down Expand Up @@ -123,6 +124,7 @@ export const MessageBubble: React.FC<MessageBubbleProps> = React.memo((props) =>
}

const fullWidth = props.message.fullWidth;
const configSchema = getConfigSchema();

return (
<EuiFlexGroup
Expand Down Expand Up @@ -159,7 +161,8 @@ export const MessageBubble: React.FC<MessageBubbleProps> = React.memo((props) =>
interaction={props.interaction}
message={props.message as IOutput}
showFeedback={showFeedback}
showTraceIcon={!!props.message.interactionId}
showTraceIcon={configSchema.chat.trace && !!props.message.interactionId}
traceTip="How was this generated?"
traceInteractionId={props.message.interactionId || ''}
onViewTrace={() => {
const message = props.message as IOutput;
Expand Down
Loading