Skip to content

Commit

Permalink
Enhance search functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
neel1996 committed Aug 31, 2023
1 parent fa3426b commit 49888be
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 7 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/app/api/search/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const search = async (query) => {
});

const { text: content } = await paraphraseChain.call({
rawContent: closestMatch.chunk_content
rawContent: closestMatch.chunk_content.slice(0, 6000)
});

const { answer, error: chainError } = await sequentialPipeline({
Expand Down
3 changes: 1 addition & 2 deletions src/app/chat/components/ChatElements/ChatItem.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import format from 'date-fns/format';
import React, { memo, useEffect } from 'react';

import CodeBlock from '@/app/CodeBlock';
import { Face6, SmartToy } from '@mui/icons-material';
import { Box, Card, Grid, Icon, ListItem, Typography } from '@mui/material';

import CodeBlock from './CodeBlock';

export default memo(function ChatItem({
rowPosition,
style,
Expand Down
31 changes: 31 additions & 0 deletions src/app/chat/layout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Inter } from 'next/font/google';
import { Suspense } from 'react';

import Loading from '../loading';

const inter = Inter({ subsets: ['latin'] });

export const metadata = {
title: 'Chat with your docs',
description: 'App to chat with docs'
};

export default function RootLayout({ children }) {
return (
<html lang="en">
<head>
<script
type="text/javascript"
id="MathJax-script"
async
src="https://cdn.jsdelivr.net/npm/mathjax@3.2.1/es5/tex-mml-chtml.js"
></script>
</head>
<body className={inter.className}>
<div>
<Suspense fallback={<Loading />}>{children}</Suspense>
</div>
</body>
</html>
);
}
8 changes: 6 additions & 2 deletions src/app/layout.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Inter } from 'next/font/google';
import { Suspense } from 'react';

import './globals.css';
import Loading from './loading';

const inter = Inter({ subsets: ['latin'] });

export const metadata = {
title: 'Just a doc QA bot!',
title: 'Search your docs',
description: 'App to chat with docs'
};

Expand All @@ -20,7 +22,9 @@ export default function RootLayout({ children }) {
src="https://cdn.jsdelivr.net/npm/mathjax@3.2.1/es5/tex-mml-chtml.js"
></script>
</head>
<body className={inter.className}>{children}</body>
<body className={inter.className}>
<Suspense fallback={<Loading />}>{children}</Suspense>
</body>
</html>
);
}
14 changes: 14 additions & 0 deletions src/app/loading.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use client';

import React from 'react';
import { FallingLines } from 'react-loader-spinner';

import { Backdrop } from '@mui/material';

export default function Loading() {
return (
<Backdrop open={true}>
<FallingLines color="#8b9aee" />
</Backdrop>
);
}
29 changes: 27 additions & 2 deletions src/app/search/ResultBox.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,34 @@
import React from 'react';
import React, { useEffect } from 'react';

import { PushPin } from '@mui/icons-material';
import { Box, Grid, Typography } from '@mui/material';

import CodeBlock from '../CodeBlock';

export default function ResultBox({ answer }) {
useEffect(() => {
if (typeof window?.MathJax !== 'undefined') {
window.MathJax = {
...window.MathJax,
tex: {
inlineMath: [
['$', '$'],
['\\(', '\\)']
],
packages: { '[+]': ['mhchem', 'color'] },
color: {
padding: '5px',
borderWidth: '2px'
}
},
loader: { load: ['[tex]/mhchem', '[tex]/color'] }
};

window.MathJax.typesetClear();
window.MathJax.typesetPromise();
}
}, []);

return (
<Box
sx={{
Expand Down Expand Up @@ -42,7 +67,7 @@ export default function ResultBox({ answer }) {
}
}}
>
{answer}
<CodeBlock message={answer} />
</Typography>
</Box>
</Box>
Expand Down

0 comments on commit 49888be

Please sign in to comment.