Skip to content

Commit

Permalink
Merge pull request elastic#2 from yansavitski/ai-playground-base-ui
Browse files Browse the repository at this point in the history
Ai playground base UI
  • Loading branch information
yansavitski authored Feb 1, 2024
2 parents 4a2afa6 + b0e6e07 commit f172e64
Show file tree
Hide file tree
Showing 7 changed files with 207 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
*
* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* * or more contributor license agreements. Licensed under the Elastic License
* * 2.0; you may not use this file except in compliance with the Elastic License
* * 2.0.
*
*/

import React from 'react';
import { i18n } from '@kbn/i18n';

import { EuiFlexGroup, EuiFlexItem, EuiPageTemplate, useEuiTheme } from '@elastic/eui';

import { EnterpriseSearchContentPageTemplate } from '../../layout/page_template';
import { AIPlaygroundSidebar } from './ai_playground_sidebar';

export const AIPlayground: React.FC = () => {
const { euiTheme } = useEuiTheme();

return (
<EnterpriseSearchContentPageTemplate
pageChrome={[
i18n.translate('xpack.enterpriseSearch.content.aiPlayground.breadcrumb', {
defaultMessage: 'AI Playground',
}),
]}
pageHeader={{
pageTitle: i18n.translate('xpack.enterpriseSearch.content.aiPlayground.headerTitle', {
defaultMessage: 'AI Playground',
}),
rightSideItems: [],
}}
pageViewTelemetry="AI Playground"
isLoading={false}
customPageSections
bottomBorder="extended"
>
<EuiPageTemplate.Section
alignment="top"
restrictWidth={false}
grow
contentProps={{ css: { display: 'flex', flexGrow: 1 } }}
paddingSize="none"
>
<EuiFlexGroup gutterSize="none">
<EuiFlexItem
grow={2}
css={{
borderRight: euiTheme.border.thin,
padding: euiTheme.size.l,
}}
>
<EuiFlexGroup direction="column" justifyContent="spaceBetween"></EuiFlexGroup>
</EuiFlexItem>

<EuiFlexItem
grow={1}
css={{
padding: euiTheme.size.l,
}}
>
<AIPlaygroundSidebar />
</EuiFlexItem>
</EuiFlexGroup>
</EuiPageTemplate.Section>
</EnterpriseSearchContentPageTemplate>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
*
* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* * or more contributor license agreements. Licensed under the Elastic License
* * 2.0; you may not use this file except in compliance with the Elastic License
* * 2.0.
*
*/

import React from 'react';
import { i18n } from '@kbn/i18n';
import { EuiFormRow, EuiSwitch } from '@elastic/eui';

import { InstructionsField } from './instructions_field';

export const AIPlaygroundSidebar: React.FC = () => {
const [prompt, setPrompt] = React.useState('');
const [isIncludeCitations, setIncludeCitations] = React.useState<boolean>(true);

return (
<>
<InstructionsField
label={i18n.translate(
'xpack.enterpriseSearch.content.aiPlayground.instructionsField.label',
{
defaultMessage: 'Instructions',
}
)}
placeholder={i18n.translate(
'xpack.enterpriseSearch.content.aiPlayground.instructionsField.placeholder',
{
defaultMessage: 'Replace me',
}
)}
helpText={i18n.translate(
'xpack.enterpriseSearch.content.aiPlayground.instructionsField.help',
{
defaultMessage:
'This is the instruction or question you want the AI to respond to. Be clear and specific for the best results.',
}
)}
value={prompt}
onChange={setPrompt}
/>

<EuiFormRow>
<EuiSwitch
label={i18n.translate(
'xpack.enterpriseSearch.content.aiPlayground.citationsField.label',
{
defaultMessage: 'Include citations',
}
)}
checked={isIncludeCitations}
onChange={(e) => setIncludeCitations(e.target.checked)}
/>
</EuiFormRow>
</>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
*
* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* * or more contributor license agreements. Licensed under the Elastic License
* * 2.0; you may not use this file except in compliance with the Elastic License
* * 2.0.
*
*/

import React from 'react';
import { EuiFormRow, EuiIcon, EuiTextArea, EuiToolTip } from '@elastic/eui';

interface InstructionsFieldProps {
label: string;
helpText: string;
placeholder: string;
value?: string;
onChange: (value: string) => void;
}

export const InstructionsField: React.FC<InstructionsFieldProps> = ({
label,
value,
onChange,
placeholder,
helpText,
}) => {
const handlePromptChange = (e: React.ChangeEvent<HTMLTextAreaElement>) =>
onChange(e.target.value);

return (
<EuiFormRow
label={
<EuiToolTip content={helpText}>
<span>
{label} <EuiIcon type="questionInCircle" color="subdued" />
</span>
</EuiToolTip>
}
>
<EuiTextArea
placeholder={placeholder}
value={value}
onChange={handlePromptChange}
fullWidth
/>
</EuiFormRow>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
*
* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* * or more contributor license agreements. Licensed under the Elastic License
* * 2.0; you may not use this file except in compliance with the Elastic License
* * 2.0.
*
*/

export * from "./components/ai_playground";

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { Connectors } from './components/connectors/connectors';
import { NotFound } from './components/not_found';
import { SearchIndicesRouter } from './components/search_indices';
import { Settings } from './components/settings';
import { AIPlayground } from './components/ai_playground';
import {
CONNECTORS_PATH,
CRAWLERS_PATH,
Expand All @@ -32,6 +33,7 @@ import {
SEARCH_INDICES_PATH,
SETTINGS_PATH,
SETUP_GUIDE_PATH,
AI_PLAYGROUND_PATH,
} from './routes';

export const EnterpriseSearchContent: React.FC<InitialAppData> = (props) => {
Expand Down Expand Up @@ -86,6 +88,9 @@ export const EnterpriseSearchContentConfigured: React.FC<Required<InitialAppData
<Route path={SETTINGS_PATH}>
<Settings />
</Route>
<Route path={AI_PLAYGROUND_PATH}>
<AIPlayground />
</Route>
<Route>
<NotFound />
</Route>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const ERROR_STATE_PATH = '/error_state';
export const SEARCH_INDICES_PATH = `${ROOT_PATH}search_indices`;
export const CONNECTORS_PATH = `${ROOT_PATH}connectors`;
export const CRAWLERS_PATH = `${ROOT_PATH}crawlers`;
export const AI_PLAYGROUND_PATH = `${ROOT_PATH}ai_playground`;
export const SETTINGS_PATH = `${ROOT_PATH}settings`;

export const NEW_INDEX_PATH = `${SEARCH_INDICES_PATH}/new_index`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
} from '../../../../common/constants';
import { SEARCH_APPLICATIONS_PATH, SearchApplicationViewTabs } from '../../applications/routes';
import {
AI_PLAYGROUND_PATH,
CONNECTORS_PATH,
CRAWLERS_PATH,
SEARCH_INDICES_PATH,
Expand Down Expand Up @@ -105,6 +106,17 @@ export const useEnterpriseSearchNav = () => {
},
]
: []),
{
id: 'ai-playground',
name: i18n.translate('xpack.enterpriseSearch.nav.aiPlaygroundTitle', {
defaultMessage: 'AI Playground',
}),
...generateNavLink({
shouldNotCreateHref: true,
shouldShowActiveForSubroutes: true,
to: ENTERPRISE_SEARCH_CONTENT_PLUGIN.URL + AI_PLAYGROUND_PATH,
}),
},
],
name: i18n.translate('xpack.enterpriseSearch.nav.contentTitle', {
defaultMessage: 'Content',
Expand Down

0 comments on commit f172e64

Please sign in to comment.