Skip to content

Commit

Permalink
Added: openarmor assistant based on opensearch
Browse files Browse the repository at this point in the history
  • Loading branch information
mranv committed Sep 11, 2024
1 parent 8f2779b commit 31bd116
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 79 deletions.
12 changes: 6 additions & 6 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
contact_links:
- name: OpenSearch Community Support
url: https://discuss.opendistrocommunity.dev/
about: Please ask and answer questions here.
- name: AWS/Amazon Security
url: https://aws.amazon.com/security/vulnerability-reporting/
about: Please report security vulnerabilities here.
- name: Anubhav Gain
url: https://www.linkedin.com/in/anubhavgain/
about: A DevSecOps Engineer.
- name: Hriday Sheth
url: https://www.linkedin.com/in/hridaysheth/
about: Official maintainer of this Ai based Chat Bot.
4 changes: 2 additions & 2 deletions public/components/__tests__/chat_window_header_title.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,11 @@ describe('<ChatWindowHeaderTitle />', () => {
expect(renderResult.getByRole('button', { name: 'Save to notebook' })).toBeDisabled();
});

it('should show "OpenSearch Assistant" when conversationId is undefined', async () => {
it('should show "OpenArmor Assistant" when conversationId is undefined', async () => {
const { renderResult } = setup({
conversationId: undefined,
});

expect(renderResult.getByText('OpenSearch Assistant')).toBeInTheDocument();
expect(renderResult.getByText('OpenArmor Assistant')).toBeInTheDocument();
});
});
4 changes: 2 additions & 2 deletions public/components/chat_welcome_message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ export const WelcomeMessage = (props: Props) => {
titleSize="s"
body={
<EuiText color="default">
<p>Welcome{usernamePlaceHolder}to the OpenSearch Assistant!</p>
<p>Welcome{usernamePlaceHolder}to the OpenArmor Assistant!</p>
<p>I can help you analyze data, create visualizations, and get other insights.</p>
<p>How can I help?</p>
<EuiText size="xs" color="subdued">
The OpenSearch Assistant may produce inaccurate information. Verify all information
The OpenArmor Assistant may produce inaccurate information. Verify all information
before using it in any environment or workload.
</EuiText>
</EuiText>
Expand Down
2 changes: 1 addition & 1 deletion public/components/chat_window_header_title.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const ChatWindowHeaderTitle = React.memo(() => {
const [isSaveNotebookModalOpen, setSaveNotebookModalOpen] = useState(false);
const { chatState } = useChatState();
const { saveChat } = useSaveChat();
const displayTitle = chatContext.conversationId ? chatContext.title : 'OpenSearch Assistant';
const displayTitle = chatContext.conversationId ? chatContext.title : 'OpenArmor Assistant';

const onButtonClick = useCallback(() => {
setPopoverOpen((flag) => !flag);
Expand Down
6 changes: 3 additions & 3 deletions public/components/incontext_insight/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export const IncontextInsight = ({ children }: IncontextInsightProps) => {
</EuiPopoverFooter>
);

const GeneratePopoverBody: React.FC<{}> = ({}) => (
const GeneratePopoverBody: React.FC<{}> = ({ }) => (
<EuiButton onClick={() => toasts.addDanger('To be implemented...')}>Generate summary</EuiButton>
);

Expand All @@ -195,7 +195,7 @@ export const IncontextInsight = ({ children }: IncontextInsightProps) => {
</>
);

const ChatPopoverBody: React.FC<{}> = ({}) => (
const ChatPopoverBody: React.FC<{}> = ({ }) => (
<EuiFlexGroup>
<EuiFlexItem grow={6}>
<EuiFormRow>
Expand Down Expand Up @@ -286,7 +286,7 @@ export const IncontextInsight = ({ children }: IncontextInsightProps) => {
<div>
<EuiBadge color="hollow" iconType={chatIcon} iconSide="left">
{i18n.translate('assistantDashboards.incontextInsight.assistant', {
defaultMessage: 'OpenSearch Assistant',
defaultMessage: 'OpenArmor Assistant',
})}
</EuiBadge>
</div>
Expand Down
4 changes: 2 additions & 2 deletions public/components/invite_message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React from 'react';
export const InviteMessage: React.FC = () => {
// using https://mailtolinkgenerator.com/
const mailtoLink =
'mailto:opensearch-assistant@amazon.com?subject=Requesting%20invite%20to%20OpenSearch%20Assistant%20Playground';
'mailto:openarmor-assistant@theopenarmor.org?subject=Requesting%20invite%20to%20OpenSearch%20Assistant%20Playground';

return (
<EuiEmptyPrompt
Expand All @@ -21,7 +21,7 @@ export const InviteMessage: React.FC = () => {
<p>
To request access, please send an email to{' '}
<EuiLink href={mailtoLink} external>
opensearch-assistant@amazon.com
opensearch-assistant@theopenarmor.org
</EuiLink>
.
</p>
Expand Down
4 changes: 2 additions & 2 deletions public/tabs/__tests__/chat_window_header.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { TabId } from '../../types';
import { SIDECAR_DOCKED_MODE } from '../../../../../src/core/public';

jest.mock('../../components/chat_window_header_title', () => {
return { ChatWindowHeaderTitle: () => <div>OpenSearch Assistant</div> };
return { ChatWindowHeaderTitle: () => <div>OpenArmor Assistant</div> };
});

const setup = ({ selectedTabId }: { selectedTabId?: TabId } = {}) => {
Expand Down Expand Up @@ -40,7 +40,7 @@ describe('<ChatWindowHeader />', () => {
it('should render title, history, setSidecarMode and close button', () => {
const { renderResult } = setup();

expect(renderResult.getByText('OpenSearch Assistant')).toBeInTheDocument();
expect(renderResult.getByText('OpenArmor Assistant')).toBeInTheDocument();
expect(renderResult.getByLabelText('history')).toBeInTheDocument();
expect(renderResult.getByLabelText('setSidecarMode')).toBeInTheDocument();
expect(renderResult.getByLabelText('close')).toBeInTheDocument();
Expand Down
79 changes: 42 additions & 37 deletions public/utils/notebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,40 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { v4 as uuid } from 'uuid';
import { htmlIdGenerator } from '@elastic/eui';
import { IMessage } from '../../common/types/chat_saved_object_attributes';
import { v4 as uuid } from "uuid";
import { htmlIdGenerator } from "@elastic/eui";
import { IMessage } from "../../common/types/chat_saved_object_attributes";

const buildBasicGraph = () => ({
id: 'paragraph_' + uuid(),
id: "paragraph_" + uuid(),
dateCreated: new Date().toISOString(),
dateModified: new Date().toISOString(),
input: {
inputText: '',
inputType: '',
inputText: "",
inputType: "",
},
output: [{ result: '', outputType: '', execution_time: '0 ms' }],
output: [{ result: "", outputType: "", execution_time: "0 ms" }],
});

const ASSISTANT_MESSAGE_PREFIX = 'OpenSearch Assistant: ';
const ASSISTANT_MESSAGE_PREFIX = "OpenArmor Assistant: ";

const createDashboardVizObject = (objectId: string) => {
const vizUniqueId = htmlIdGenerator()();
// a dashboard container object for new visualization
const basicVizObject = {
viewMode: 'view',
viewMode: "view",
panels: {
'1': {
"1": {
gridData: {
x: 0,
y: 0,
w: 50,
h: 20,
i: '1',
i: "1",
},
type: 'visualization',
type: "visualization",
explicitInput: {
id: '1',
id: "1",
savedObjectId: objectId,
},
},
Expand All @@ -47,13 +47,13 @@ const createDashboardVizObject = (objectId: string) => {
id: vizUniqueId,
timeRange: {
// We support last 15minutes here to keep consistent with chat bot preview.
to: 'now',
from: 'now-15m',
to: "now",
from: "now-15m",
},
title: 'embed_viz_' + vizUniqueId,
title: "embed_viz_" + vizUniqueId,
query: {
query: '',
language: 'lucene',
query: "",
language: "lucene",
},
refreshConfig: {
pause: true,
Expand All @@ -63,30 +63,33 @@ const createDashboardVizObject = (objectId: string) => {
return basicVizObject;
};

export const convertMessagesToParagraphs = (messages: IMessage[], username?: string) => {
const userMessagePrefix = username ? `${username}: ` : 'User: ';
export const convertMessagesToParagraphs = (
messages: IMessage[],
username?: string
) => {
const userMessagePrefix = username ? `${username}: ` : "User: ";

return messages.map((message: IMessage) => {
const paragraph = buildBasicGraph();

switch (message.contentType) {
// markdown,text and error are all text formatted in notebook.
case 'markdown':
case 'text':
case 'error':
case "markdown":
case "text":
case "error":
const messageText =
// markdown and error represents assistant, text represents user.
message.contentType === 'text'
message.contentType === "text"
? userMessagePrefix + message.content
: ASSISTANT_MESSAGE_PREFIX + message.content;

Object.assign(paragraph, {
input: { inputText: `%md\n${messageText}`, inputType: 'MARKDOWN' },
input: { inputText: `%md\n${messageText}`, inputType: "MARKDOWN" },
output: [
{
result: messageText,
outputType: 'MARKDOWN',
execution_time: '0 ms',
outputType: "MARKDOWN",
execution_time: "0 ms",
},
],
});
Expand All @@ -95,30 +98,32 @@ export const convertMessagesToParagraphs = (messages: IMessage[], username?: str
/**
* TODO migrate ppl_data_grid logic to dashboards-observerability
*/
case 'ppl_data_grid':
case "ppl_data_grid":
const queryText = message.content;
Object.assign(paragraph, {
input: { inputText: `%ppl\n${queryText}`, inputType: 'MARKDOWN' },
input: { inputText: `%ppl\n${queryText}`, inputType: "MARKDOWN" },
output: [
{
result: `\n${queryText}`,
outputType: 'QUERY',
execution_time: '0 ms',
outputType: "QUERY",
execution_time: "0 ms",
},
],
});
break;

case 'visualization':
case "visualization":
const visualizationObjectId = message.content;
const inputText = JSON.stringify(createDashboardVizObject(visualizationObjectId));
const inputText = JSON.stringify(
createDashboardVizObject(visualizationObjectId)
);
Object.assign(paragraph, {
input: { inputText, inputType: 'VISUALIZATION' },
input: { inputText, inputType: "VISUALIZATION" },
output: [
{
result: '',
outputType: 'VISUALIZATION',
execution_time: '0 ms',
result: "",
outputType: "VISUALIZATION",
execution_time: "0 ms",
},
],
});
Expand Down
Loading

0 comments on commit 31bd116

Please sign in to comment.