Skip to content

Commit

Permalink
Llm code
Browse files Browse the repository at this point in the history
  • Loading branch information
frankyhollywood committed Aug 12, 2024
1 parent 55b48a1 commit 7b32e79
Show file tree
Hide file tree
Showing 13 changed files with 763 additions and 25 deletions.
3 changes: 2 additions & 1 deletion projects/mercury/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
"private": true,
"scripts": {
"dev": "yarn build && concurrently \"yarn localdevelopment\" \"yarn saturn\" \"yarn pluto\" \"yarn start\"",
"dev-nosat": "yarn build && concurrently \"yarn localdevelopment\" \"yarn pluto\" \"yarn start\"",
"dev-be": "concurrently \"yarn localdevelopment\" \"yarn saturn\" \"yarn pluto\"",
"dev-fe": "yarn build && yarn start",
"localdevelopment": "cd ../../local-development && docker compose up",
"saturn": "wait-on http://localhost:5100/ && wait-on tcp:9432 && cd ../saturn/ && KEYCLOAK_CLIENT_SECRET=********** ./gradlew run",
"saturn": "wait-on http://localhost:5100/ && wait-on tcp:9432 && cd ../saturn/ && KEYCLOAK_CLIENT_SECRET=********** LLM_API_KEY=ewogICJ0eXBlIjogInNlcnZpY2VfYWNjb3VudCIsCiAgInByb2plY3RfaWQiOiAiaHl2ZWxsbSIsCiAgInByaXZhdGVfa2V5X2lkIjogIjZkNTNhZjQyZWIzZmU3NjhkMTgyMzAzM2VjMzgxNjA5ZTU2OTcxNzAiLAogICJwcml2YXRlX2tleSI6ICItLS0tLUJFR0lOIFBSSVZBVEUgS0VZLS0tLS1cbk1JSUV2UUlCQURBTkJna3Foa2lHOXcwQkFRRUZBQVNDQktjd2dnU2pBZ0VBQW9JQkFRQ3Y2VjRDTGlXOEUxb0tcbkM3Q080SFhKc0w4MEpOcDFobE9HL2NWZUlpUjl2UkdDWnorMi8wbWJiZy9qN216QXRQbnE1WElIaWxGYnQrSEFcbkZIamU1aWJpdkhJYlAvTHE0d1ozeURtUHNSRDU2UURzRmJQY1JpSXpNWlp3cUo5Qjl0a0FSYytMK0xzSFlYK1Vcbi9MZWl6Qkl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iMTA3ODY2Mjc1NTE5MzUwMzgzOTQ3IiwKICAiYXV0aF91cmkiOiAiaHR0cHM6Ly9hY2NvdW50cy5nb29nbGUuY29tL28vb2F1dGgyL2F1dGgiLAogICJ0b2tlbl91cmkiOiAiaHR0cHM6Ly9vYXV0aDIuZ29vZ2xlYXBpcy5jb20vdG9rZW4iLAogICJhdXRoX3Byb3ZpZGVyX3g1MDlfY2VydF91cmwiOiAiaHR0cHM6Ly93d3cuZ29vZ2xlYXBpcy5jb20vb2F1dGgyL3YxL2NlcnRzIiwKICAiY2xpZW50X3g1MDlfY2VydF91cmwiOiAiaHR0cHM6Ly93d3cuZ29vZ2xlYXBpcy5jb20vcm9ib3QvdjEvbWV0YWRhdGEveDUwOS9oeXZlLWxsbS1zZXJ2aWNlYWNjb3VudCU0MGh5dmVsbG0uaWFtLmdzZXJ2aWNlYWNjb3VudC5jb20iLAogICJ1bml2ZXJzZV9kb21haW4iOiAiZ29vZ2xlYXBpcy5jb20iCn0K ./gradlew run",
"pluto": "wait-on http://localhost:8090/api/health/ && cd ../pluto/ && KEYCLOAK_CLIENT_SECRET=********** ./gradlew bootRun --args='--spring.profiles.active=local'",
"start": "craco start",
"build": "yarn check-format && craco build",
Expand Down
2 changes: 1 addition & 1 deletion projects/mercury/src/common/contexts/FeaturesContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
import {extractJsonData, handleHttpError} from '../utils/httpUtils';
import useAsync from '../hooks/UseAsync';

export type Feature = 'ExtraStorage' | any; // more to come
export type Feature = 'ExtraStorage' | 'LlmSearch' | any; // more to come

const FeaturesContext = React.createContext({});

Expand Down
16 changes: 14 additions & 2 deletions projects/mercury/src/dashboard/DashboardPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,32 @@ import React, {useContext} from 'react';

import withStyles from '@mui/styles/withStyles';
import {Grid, Link, Paper, Typography, TextField} from '@mui/material';
import {useHistory} from 'react-router-dom';
import queryString from 'query-string';
import styles from './DashboardPage.styles';
import MetadataViewContext from '../metadata/views/MetadataViewContext';
import ExternalMetadataSourceContext from '../metadata/metadata-sources/ExternalMetadataSourceContext';
import UserContext from '../users/UserContext';
import DomainInfo from './DomainInfo';
import {APPLICATION_DOCS_URL, APPLICATION_NAME, THE_HYVE_URL} from '../constants';
import InternalMetadataSourceContext from '../metadata/metadata-sources/InternalMetadataSourceContext';
import FeaturesContext from '../common/contexts/FeaturesContext';

const DashboardPage = props => {
const {currentUser, classes} = props;
const history = useHistory();
const {views} = useContext(MetadataViewContext);
const {externalMetadataSources} = useContext(ExternalMetadataSourceContext);
const {internalMetadataIcon, internalMetadataLabel} = useContext(InternalMetadataSourceContext);
const canViewMetadata = currentUser && currentUser.canViewPublicMetadata && views && views.length > 0;
const askAIConfigured = false;
const {isFeatureEnabled} = useContext(FeaturesContext);
const isLlsSearchEnabled = isFeatureEnabled('LlmSearch');

const handleLlmInputChange = event => {
if (event.keyCode === 13) {
history.push('/ask/?' + queryString.stringify({q: event.target.value}));
}
};

return (
<Grid container spacing={5} className={classes.mainPage} direction="column" justifyContent="flex-start">
Expand Down Expand Up @@ -100,7 +111,7 @@ const DashboardPage = props => {
</Grid>
</Grid>
<Grid item xs={12}>
{askAIConfigured && (
{isLlsSearchEnabled && (
<Paper elevation={3} className={classes.paperContent}>
<Typography className={classes.header} variant="h4" paragraph align="center">
Ask AI
Expand All @@ -114,6 +125,7 @@ const DashboardPage = props => {
placeholder="Type your quetion here..."
variant="outlined"
className={classes.textField}
onKeyDown={event => handleLlmInputChange(event)}
/>
</div>
</Paper>
Expand Down
22 changes: 22 additions & 0 deletions projects/mercury/src/layout/MainMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import classNames from 'classnames';
import {NavLink} from 'react-router-dom';
import {Button, Icon, Stack} from '@mui/material';
import {Search, SavedSearch, Folder, FolderSpecial, OpenInNew, VerifiedUser, Widgets} from '@mui/icons-material';
import ChatIcon from '@mui/icons-material/Chat';
import HomeIcon from '@mui/icons-material/Home';
import FeaturesContext from '../common/contexts/FeaturesContext';
import ServicesContext from '../common/contexts/ServicesContext';
import UserContext from '../users/UserContext';
import {isAdmin} from '../users/userUtils';
Expand Down Expand Up @@ -63,6 +65,9 @@ const MainMenu = ({open, classes}) => {
const {externalMetadataSources} = useContext(ExternalMetadataSourceContext);
const {internalMetadataIcon, internalMetadataLabel} = useContext(InternalMetadataSourceContext);
const {views} = useContext(MetadataViewContext);
const {isFeatureEnabled} = useContext(FeaturesContext);
const useLlmSearch = isFeatureEnabled('LlmSearch');

// eslint-disable-next-line no-template-curly-in-string
const interpolate = s => s.replace('${username}', currentUser.username);
return (
Expand Down Expand Up @@ -111,6 +116,23 @@ const MainMenu = ({open, classes}) => {
>
{open && 'Collections'}
</Button>
{useLlmSearch && (
<Button
variant="outlined"
size="small"
className={classNames(
classes.mainMenuButton,
!open && classes.mainMenuButtonSmall,
pathname.startsWith('/search') && classes.mainMenuButtonSelected
)}
key="search"
component={NavLink}
to="/ask"
startIcon={<ChatIcon />}
>
{open && 'Chat'}
</Button>
)}
{externalStorages &&
externalStorages.map(storage => (
<Button
Expand Down
45 changes: 26 additions & 19 deletions projects/mercury/src/layout/__tests__/MainMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,43 @@ import ServicesContext from '../../common/contexts/ServicesContext';
import UserContext from '../../users/UserContext';
import ExternalStoragesContext from '../../external-storage/ExternalStoragesContext';
import ExternalMetadataSourceContext from '../../metadata/metadata-sources/ExternalMetadataSourceContext';
import FeaturesContext from '../../common/contexts/FeaturesContext';
import InternalMetadataSourceContext from '../../metadata/metadata-sources/InternalMetadataSourceContext';
import MetadataViewContext from '../../metadata/views/MetadataViewContext';
import MainMenu from '../MainMenu';
import {DEFAULT_METADATA_VIEW_MENU_LABEL} from '../../constants';
import theme from '../../App.theme';

const mockFeatureContext = {
isFeatureEnabled: jest.fn()
};

describe('MainMenu', () => {
const setup = (user, services, externalStorages, externalMetadataSources, internalMetadata, views) => {
return render(
<ThemeProvider theme={theme}>
<Router>
<ServicesContext.Provider value={{services}}>
<UserContext.Provider value={{currentUser: user}}>
<ExternalStoragesContext.Provider value={{externalStorages}}>
<ExternalMetadataSourceContext.Provider value={{externalMetadataSources}}>
<InternalMetadataSourceContext.Provider
value={{
internalMetadataIcon: internalMetadata.icon,
internalMetadataLabel:
internalMetadata.label || DEFAULT_METADATA_VIEW_MENU_LABEL
}}
>
<MetadataViewContext.Provider value={{views}}>
<MainMenu open />
</MetadataViewContext.Provider>
</InternalMetadataSourceContext.Provider>
</ExternalMetadataSourceContext.Provider>
</ExternalStoragesContext.Provider>
</UserContext.Provider>
</ServicesContext.Provider>
<FeaturesContext.Provider value={mockFeatureContext}>
<ServicesContext.Provider value={{services}}>
<UserContext.Provider value={{currentUser: user}}>
<ExternalStoragesContext.Provider value={{externalStorages}}>
<ExternalMetadataSourceContext.Provider value={{externalMetadataSources}}>
<InternalMetadataSourceContext.Provider
value={{
internalMetadataIcon: internalMetadata.icon,
internalMetadataLabel:
internalMetadata.label || DEFAULT_METADATA_VIEW_MENU_LABEL
}}
>
<MetadataViewContext.Provider value={{views}}>
<MainMenu open />
</MetadataViewContext.Provider>
</InternalMetadataSourceContext.Provider>
</ExternalMetadataSourceContext.Provider>
</ExternalStoragesContext.Provider>
</UserContext.Provider>
</ServicesContext.Provider>
</FeaturesContext.Provider>
</Router>
</ThemeProvider>
);
Expand Down
Loading

0 comments on commit 7b32e79

Please sign in to comment.