Skip to content

Commit

Permalink
Add flag for trace view
Browse files Browse the repository at this point in the history
Signed-off-by: Sihan He <[email protected]>
  • Loading branch information
000FLMS committed Dec 20, 2024
1 parent 581a7ca commit 5ec4f1c
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 2 deletions.
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
3 changes: 3 additions & 0 deletions public/components/incontext_insight/generate_popover_body.tsx
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

0 comments on commit 5ec4f1c

Please sign in to comment.