Skip to content

Commit

Permalink
add username and tenant to feedback (opensearch-project#32)
Browse files Browse the repository at this point in the history
* add username and tenant to feedback

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

* update context

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

---------

Signed-off-by: tygao <[email protected]>
  • Loading branch information
raintygao authored and ruanyl committed Nov 22, 2023
1 parent 8347146 commit 60de4fc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
11 changes: 10 additions & 1 deletion public/hooks/use_feed_back.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@ import { useChatContext } from '../contexts/chat_context';
import { useCore } from '../contexts/core_context';
import { useChatState } from './use_chat_state';

interface AccountResponse {
data: { user_name: string; user_requested_tenant: string; roles: string[] };
}

interface SendFeedbackBody {
metadata: {
type: 'event_analytics' | 'chat' | 'ppl_submit';
sessionId?: string;
traceId?: string;
error?: boolean;
user: string;
tenant: string;
};
input: string;
output: string;
Expand Down Expand Up @@ -44,12 +50,15 @@ export const useFeedback = () => {
return;
}

const { username, tenant } = chatContext.currentAccount;
const body: SendFeedbackBody = {
metadata: {
type: 'chat', // currently type is only chat in feedback
sessionId: chatContext.sessionId,
traceId: outputMessage.traceId,
error: false,
user: username,
tenant,
},
input: inputMessage.content,
output: outputMessage.content,
Expand All @@ -59,7 +68,7 @@ export const useFeedback = () => {
};

try {
const response = await core.services.http.post(ASSISTANT_API.FEEDBACK, {
await core.services.http.post(ASSISTANT_API.FEEDBACK, {
body: JSON.stringify(body),
});
setFeedbackResult(correct);
Expand Down
9 changes: 5 additions & 4 deletions public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ export class AssistantPlugin
const actionExecutors: Record<string, ActionExecutor> = {};
const assistantActions: AssistantActions = {} as AssistantActions;
const getAccount = async () => {
return await core.http.get<{ data: { roles: string[]; user_name: string } }>(
'/api/v1/configuration/account'
);
return await core.http.get<{
data: { roles: string[]; user_name: string; user_requested_tenant: string | null };
}>('/api/v1/configuration/account');
};
const assistantEnabled = (() => {
let enabled: boolean;
Expand All @@ -73,6 +73,7 @@ export class AssistantPlugin
});
const account = await getAccount();
const username = account.data.user_name;
const tenant = account.data.user_requested_tenant ?? '';

coreStart.chrome.navControls.registerRight({
order: 10000,
Expand All @@ -86,7 +87,7 @@ export class AssistantPlugin
contentRenderers={contentRenderers}
actionExecutors={actionExecutors}
assistantActions={assistantActions}
currentAccount={{ username }}
currentAccount={{ username, tenant }}
/>
</CoreContext.Provider>
),
Expand Down
1 change: 1 addition & 0 deletions public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export interface AssistantStart {}

export interface UserAccount {
username: string;
tenant: string;
}

export interface ChatConfig {
Expand Down

0 comments on commit 60de4fc

Please sign in to comment.