Skip to content

Commit

Permalink
display feedback state when loading a past conversation (#41)
Browse files Browse the repository at this point in the history
* feat: display feedback state when loading a past conversation

Signed-off-by: tygao <[email protected]>

* update additional_info type

Signed-off-by: tygao <[email protected]>

* update interface

Signed-off-by: tygao <[email protected]>

---------

Signed-off-by: tygao <[email protected]>
  • Loading branch information
raintygao authored Dec 6, 2023
1 parent 40838c6 commit 36ac34b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
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>;
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

0 comments on commit 36ac34b

Please sign in to comment.