forked from opensearch-project/dashboards-observability
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request opensearch-project#1325 from opensearch-project/fe…
…ature/explorer-query-assistant Merge feature/explorer-query-assistant to main
- Loading branch information
Showing
47 changed files
with
2,684 additions
and
850 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
const QUERY_ASSIST_API_PREFIX = '/api/observability/query_assist'; | ||
export const QUERY_ASSIST_API = { | ||
GENERATE_PPL: `${QUERY_ASSIST_API_PREFIX}/generate_ppl`, | ||
SUMMARIZE: `${QUERY_ASSIST_API_PREFIX}/summarize`, | ||
}; | ||
|
||
export const ML_COMMONS_API_PREFIX = '/_plugins/_ml'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { EuiCodeEditor, EuiFlexGroup, EuiFlexItem, EuiPanel } from '@elastic/eui'; | ||
import React, { useEffect, useMemo } from 'react'; | ||
import { coreRefs } from '../../../framework/core_refs'; | ||
import { QueryAssistInput } from '../../event_analytics/explorer/query_assist/input'; | ||
import { useFetchEvents } from '../../event_analytics/hooks/use_fetch_events'; | ||
|
||
export function QueryArea({ | ||
tabId, | ||
handleQueryChange, | ||
handleTimeRangePickerRefresh, | ||
runQuery, | ||
tempQuery, | ||
setNeedsUpdate, | ||
setFillRun, | ||
selectedIndex, | ||
nlqInput, | ||
setNlqInput, | ||
pplService, | ||
}: any) { | ||
const requestParams = { tabId }; | ||
const { getAvailableFields } = useFetchEvents({ | ||
pplService, | ||
requestParams, | ||
}); | ||
|
||
// use effect that sets the editor text and populates sidebar field for a particular index upon initialization | ||
const memoizedGetAvailableFields = useMemo(() => getAvailableFields, []); | ||
const memoizedHandleQueryChange = useMemo(() => handleQueryChange, []); | ||
useEffect(() => { | ||
const indexQuery = `source = ${selectedIndex[0].label}`; | ||
memoizedHandleQueryChange(indexQuery); | ||
memoizedGetAvailableFields(indexQuery); | ||
}, [selectedIndex, memoizedGetAvailableFields, memoizedHandleQueryChange]); | ||
|
||
return ( | ||
<EuiPanel paddingSize="m"> | ||
<EuiFlexGroup gutterSize="m" direction="column"> | ||
<EuiFlexItem> | ||
<EuiCodeEditor | ||
theme="textmate" | ||
width="100%" | ||
height="4rem" | ||
showPrintMargin={false} | ||
setOptions={{ | ||
fontSize: '14px', | ||
}} | ||
aria-label="Code Editor" | ||
onChange={(query) => { | ||
handleQueryChange(query); | ||
// query is considered updated when the last run query is not the same as whats in the editor | ||
// setUpdatedQuery(runQuery !== query); | ||
setNeedsUpdate(runQuery !== query); | ||
}} | ||
onFocus={() => setFillRun(true)} | ||
onBlur={() => setFillRun(false)} | ||
value={tempQuery} | ||
wrapEnabled={true} | ||
/> | ||
</EuiFlexItem> | ||
{coreRefs.queryAssistEnabled && ( | ||
<EuiFlexItem> | ||
<QueryAssistInput | ||
tabId={tabId} | ||
handleQueryChange={handleQueryChange} | ||
handleTimeRangePickerRefresh={handleTimeRangePickerRefresh} | ||
setNeedsUpdate={setNeedsUpdate} | ||
selectedIndex={selectedIndex} | ||
nlqInput={nlqInput} | ||
setNlqInput={setNlqInput} | ||
/> | ||
</EuiFlexItem> | ||
)} | ||
</EuiFlexGroup> | ||
</EuiPanel> | ||
); | ||
} |
111 changes: 111 additions & 0 deletions
111
public/components/common/search/query_assist_summarization.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { | ||
EuiAccordion, | ||
EuiBadge, | ||
EuiCallOut, | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiIcon, | ||
EuiLink, | ||
EuiMarkdownFormat, | ||
EuiPanel, | ||
EuiSpacer, | ||
EuiText, | ||
} from '@elastic/eui'; | ||
import chatLogo from '../../datasources/icons/query-assistant-logo.svg'; | ||
import React from 'react'; | ||
|
||
export function QueryAssistSummarization({ | ||
queryAssistantSummarization, | ||
setNlqInput, | ||
showFlyout, | ||
}: any) { | ||
return ( | ||
<EuiPanel> | ||
<EuiAccordion | ||
id="summarization-accordion" | ||
buttonContent="AI Insights" | ||
initialIsOpen | ||
isLoading={queryAssistantSummarization?.summaryLoading ?? false} | ||
isLoadingMessage="Loading summary.." | ||
extraAction={ | ||
<EuiFlexGroup direction="row" alignItems="center" gutterSize="s"> | ||
<EuiFlexItem grow={false}> | ||
<EuiText color="subdued"> | ||
<small>Generated by Opensearch Assistant</small> | ||
</EuiText> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<EuiIcon type={chatLogo} size="l" /> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
} | ||
> | ||
{queryAssistantSummarization?.summary?.length > 0 && ( | ||
<> | ||
<EuiSpacer size="m" /> | ||
{queryAssistantSummarization?.isPPLError ? ( | ||
<> | ||
<EuiCallOut title="There was an error" color="danger" iconType="alert"> | ||
<EuiMarkdownFormat>{queryAssistantSummarization.summary}</EuiMarkdownFormat> | ||
</EuiCallOut> | ||
<EuiSpacer size="s" /> | ||
<EuiFlexGroup wrap gutterSize="s"> | ||
<EuiFlexItem grow={false}> | ||
<EuiText size="s">Suggestions:</EuiText> | ||
</EuiFlexItem> | ||
{queryAssistantSummarization.suggestedQuestions.map((question) => ( | ||
<EuiFlexItem grow={false}> | ||
<EuiBadge | ||
color="hollow" | ||
iconType="chatRight" | ||
iconSide="left" | ||
onClick={() => setNlqInput(question)} | ||
onClickAriaLabel="Set input to the suggested question" | ||
> | ||
{question} | ||
</EuiBadge> | ||
</EuiFlexItem> | ||
))} | ||
<EuiFlexItem grow={false}> | ||
<EuiBadge | ||
color="hollow" | ||
iconType="questionInCircle" | ||
iconSide="left" | ||
onClick={showFlyout} | ||
onClickAriaLabel="Show PPL documentation" | ||
> | ||
PPL Documentation | ||
</EuiBadge> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</> | ||
) : ( | ||
<EuiPanel color="subdued" style={{ marginLeft: 16, marginRight: 16 }}> | ||
<EuiMarkdownFormat>{queryAssistantSummarization.summary}</EuiMarkdownFormat> | ||
</EuiPanel> | ||
)} | ||
<EuiSpacer size="m" /> | ||
<EuiText color="subdued"> | ||
<small> | ||
The OpenSearch Assistant may produce inaccurate information. Verify all information | ||
before using it in any environment or workload. Share feedback via{' '} | ||
<EuiLink href="https://forum.opensearch.org/t/feedback-opensearch-assistant/16741"> | ||
Forum | ||
</EuiLink>{' '} | ||
or{' '} | ||
<EuiLink href="https://opensearch.slack.com/channels/assistant-feedback"> | ||
Slack | ||
</EuiLink> | ||
</small> | ||
</EuiText> | ||
</> | ||
)} | ||
</EuiAccordion> | ||
</EuiPanel> | ||
); | ||
} |
Oops, something went wrong.