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

display feedback state when loading a past conversation #41

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
5 changes: 4 additions & 1 deletion common/types/chat_saved_object_attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface Interaction {
conversation_id: string;
interaction_id: string;
create_time: string;
additional_info?: Record<string, unknown>;
Copy link
Member

@SuZhou-Joe SuZhou-Joe Dec 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Interaciton type is used in many places. The key-value pair does not have to be Record<string, boolean> I suppose?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it may can also be string. But i assumed this could be updated when needed in future or predefined.

Copy link
Member

@SuZhou-Joe SuZhou-Joe Dec 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
What about { feedback?: SendFeedbackBody, [key: string]: unknown }.

My intent to set value as unknown is letting consumers to cast to other types explicitly in their functions if they want to consume specific field and know exactly what the type those values are.

https://github.com/opensearch-project/dashboards-assistant/blob/feature/agent-framework/server/parsers/visualization_card_parser.ts#L19 for reference.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense.

additional_info?: { feedback?: SendFeedbackBody; [key: string]: unknown };
parent_interaction_id?: string;
}

Expand Down Expand Up @@ -64,3 +64,6 @@ export type ISuggestedAction = ISuggestedActionBase &
metadata: { traceId: string; icon: string };
}
);
export interface SendFeedbackBody {
satisfaction: boolean;
}
15 changes: 6 additions & 9 deletions public/hooks/use_feed_back.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,17 @@

import { useState } from 'react';
import { ASSISTANT_API } from '../../common/constants/llm';
import { IOutput } from '../../common/types/chat_saved_object_attributes';
import { useChatContext } from '../contexts/chat_context';
import { IOutput, Interaction } from '../../common/types/chat_saved_object_attributes';
import { useCore } from '../contexts/core_context';
import { useChatState } from './use_chat_state';
import { SendFeedbackBody } from '../../common/types/chat_saved_object_attributes';

interface SendFeedbackBody {
satisfaction: boolean;
}

export const useFeedback = () => {
const chatContext = useChatContext();
export const useFeedback = (interaction?: Interaction | null) => {
const core = useCore();
const { chatState } = useChatState();
const [feedbackResult, setFeedbackResult] = useState<undefined | boolean>(undefined);
const [feedbackResult, setFeedbackResult] = useState<undefined | boolean>(
interaction?.additional_info?.feedback?.satisfaction ?? undefined
);

const sendFeedback = async (message: IOutput, correct: boolean) => {
const outputMessage = message;
Expand Down
4 changes: 3 additions & 1 deletion public/tabs/chat/messages/message_bubble.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ type MessageBubbleProps = {
);

export const MessageBubble: React.FC<MessageBubbleProps> = React.memo((props) => {
const { feedbackResult, sendFeedback } = useFeedback();
const { feedbackResult, sendFeedback } = useFeedback(
'interaction' in props ? props.interaction : null
);

// According to the design of the feedback, only markdown type output is supported.
const showFeedback =
Expand Down
Loading