Skip to content

Commit

Permalink
feat(gen-ai): apply user feedback from server
Browse files Browse the repository at this point in the history
- Apply user feedback loaded from server

jira: F1-645
risk: low
  • Loading branch information
Andy Chumak committed Nov 15, 2024
1 parent 5756ddd commit dd3b718
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 37 deletions.
11 changes: 11 additions & 0 deletions libs/api-client-tiger/api/api-client-tiger.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2344,8 +2344,19 @@ export interface ChatHistoryInteraction {
routing: RouteResult;
textResponse?: string;
threadIdSuffix?: string;
userFeedback?: ChatHistoryInteractionUserFeedbackEnum;
}

// @public (undocumented)
export const ChatHistoryInteractionUserFeedbackEnum: {
readonly POSITIVE: "POSITIVE";
readonly NEGATIVE: "NEGATIVE";
readonly NONE: "NONE";
};

// @public (undocumented)
export type ChatHistoryInteractionUserFeedbackEnum = typeof ChatHistoryInteractionUserFeedbackEnum[keyof typeof ChatHistoryInteractionUserFeedbackEnum];

// @public
export interface ChatHistoryRequest {
chatHistoryInteractionId?: number;
Expand Down
16 changes: 16 additions & 0 deletions libs/api-client-tiger/src/generated/afm-rest-api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,23 @@ export interface ChatHistoryInteraction {
* @memberof ChatHistoryInteraction
*/
createdVisualizations?: CreatedVisualizations;
/**
* User feedback.
* @type {string}
* @memberof ChatHistoryInteraction
*/
userFeedback?: ChatHistoryInteractionUserFeedbackEnum;
}

export const ChatHistoryInteractionUserFeedbackEnum = {
POSITIVE: "POSITIVE",
NEGATIVE: "NEGATIVE",
NONE: "NONE",
} as const;

export type ChatHistoryInteractionUserFeedbackEnum =
typeof ChatHistoryInteractionUserFeedbackEnum[keyof typeof ChatHistoryInteractionUserFeedbackEnum];

/**
*
* @export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3257,6 +3257,11 @@
},
"createdVisualizations": {
"$ref": "#/components/schemas/CreatedVisualizations"
},
"userFeedback": {
"type": "string",
"description": "User feedback.",
"enum": ["POSITIVE", "NEGATIVE", "NONE"]
}
},
"description": "List of chat history interactions."
Expand Down
1 change: 1 addition & 0 deletions libs/api-client-tiger/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ export type {
ChatHistoryRequest,
ChatHistoryRequestUserFeedbackEnum,
ChatHistoryInteraction,
ChatHistoryInteractionUserFeedbackEnum,
ActionsApiAiChatRequest,
ActionsApiAiChatStreamRequest,
ActionsApiAiChatHistoryRequest,
Expand Down
1 change: 1 addition & 0 deletions libs/sdk-model/api/sdk-model.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1885,6 +1885,7 @@ export interface IGenAIChatInteraction {
question: string;
routing: IGenAIChatRouting;
textResponse?: string;
userFeedback?: GenAIChatInteractionUserFeedback;
}

// @alpha
Expand Down
4 changes: 4 additions & 0 deletions libs/sdk-model/src/genAI/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ export interface IGenAIChatInteraction {
* A list of created visualizations for the interaction.
*/
createdVisualizations?: IGenAICreatedVisualizations;
/**
* User feedback for the assistant reply.
*/
userFeedback?: GenAIChatInteractionUserFeedback;
}

/**
Expand Down
74 changes: 38 additions & 36 deletions libs/sdk-ui-gen-ai/src/components/messages/AssistantMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,45 +44,47 @@ const AssistantMessageComponentCore: React.FC<AssistantMessageProps & WrappedCom
isComplete={Boolean(message.complete || message.cancelled)}
isCancelled={message.cancelled}
/>
<div
className={cx({
"gd-gen-ai-chat__messages__feedback": true,
"gd-gen-ai-chat__messages__feedback--assigned": message.feedback !== "NONE",
})}
>
<button
{message.complete ? (
<div
className={cx({
"gd-gen-ai-chat__messages__feedback__button": true,
"gd-gen-ai-chat__messages__feedback__button--positive":
message.feedback === "POSITIVE",
"gd-gen-ai-chat__messages__feedback": true,
"gd-gen-ai-chat__messages__feedback--assigned": message.feedback !== "NONE",
})}
type="button"
onClick={() =>
setUserFeedback({
assistantMessageId: message.localId,
feedback: message.feedback === "POSITIVE" ? "NONE" : "POSITIVE",
})
}
>
<Icon.ThumbsUp />
</button>
<button
className={cx({
"gd-gen-ai-chat__messages__feedback__button": true,
"gd-gen-ai-chat__messages__feedback__button--negative":
message.feedback === "NEGATIVE",
})}
type="button"
onClick={() =>
setUserFeedback({
assistantMessageId: message.localId,
feedback: message.feedback === "NEGATIVE" ? "NONE" : "NEGATIVE",
})
}
>
<Icon.ThumbsDown />
</button>
</div>
<button
className={cx({
"gd-gen-ai-chat__messages__feedback__button": true,
"gd-gen-ai-chat__messages__feedback__button--positive":
message.feedback === "POSITIVE",
})}
type="button"
onClick={() =>
setUserFeedback({
assistantMessageId: message.localId,
feedback: message.feedback === "POSITIVE" ? "NONE" : "POSITIVE",
})
}
>
<Icon.ThumbsUp />
</button>
<button
className={cx({
"gd-gen-ai-chat__messages__feedback__button": true,
"gd-gen-ai-chat__messages__feedback__button--negative":
message.feedback === "NEGATIVE",
})}
type="button"
onClick={() =>
setUserFeedback({
assistantMessageId: message.localId,
feedback: message.feedback === "NEGATIVE" ? "NONE" : "NEGATIVE",
})
}
>
<Icon.ThumbsDown />
</button>
</div>
) : null}
</div>
</div>
);
Expand Down
3 changes: 2 additions & 1 deletion libs/sdk-ui-gen-ai/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,14 @@ export const makeAssistantMessage = (
content: Contents[],
complete = false,
id?: number,
feedback: GenAIChatInteractionUserFeedback = "NONE",
): AssistantMessage => ({
id: id,
localId: uuidv4(),
role: "assistant",
feedback: "NONE",
created: Date.now(),
cancelled: false,
feedback,
complete,
content,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const interactionsToMessages = (interactions: IGenAIChatInteraction[]): M
assistantMessageContents,
interaction.interactionFinished,
interaction.chatHistoryInteractionId,
interaction.userFeedback,
),
);
}
Expand Down
1 change: 1 addition & 0 deletions libs/sdk-ui-gen-ai/styles/scss/messages.scss
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
display: flex;
flex-direction: column;
gap: 5px;
flex-grow: 1;
}

.gd-gen-ai-chat__messages__feedback {
Expand Down

0 comments on commit dd3b718

Please sign in to comment.