Skip to content

Commit

Permalink
ENH: Adding the AI summary to the table itself
Browse files Browse the repository at this point in the history
  • Loading branch information
Hina Shah committed Mar 11, 2024
1 parent 109719f commit f0603aa
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions src/pages/answer/resultsTable/AttributesTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import React, {
import Button from '@material-ui/core/Button';
import { blue } from '@material-ui/core/colors';
import resultsUtils from '~/utils/results';
import Popover from '~/components/Popover';
import GPTContext from '~/context/gpt';

const headerStyles = { fontWeight: 'bold', backgroundColor: '#eee' };
Expand Down Expand Up @@ -43,8 +42,6 @@ const PublicationLinkCell = ({ value, aiJSON }) => {

const { enabled } = useContext(GPTContext);
const [aiSummaryData, setAISummaryData] = useState('');
const [popoverOpen, setPopoverOpen] = useState(false);
const [popoverPosition, setPopoverPosition] = useState({ x: 0, y: 0 });

const GPTSummaryButton = withStyles((theme) => ({
root: {
Expand All @@ -61,6 +58,7 @@ const PublicationLinkCell = ({ value, aiJSON }) => {
const publicationsArr = resultsUtils.getPublications(inJSON.edge);
const sentenceRes = resultsUtils.getSentences(inJSON.edge);
// setAnchorEl(spanRef.current);
console.log(publicationsArr);
const toSendData = {
edge: {
nodes: inJSON.nodes,
Expand All @@ -80,6 +78,7 @@ const PublicationLinkCell = ({ value, aiJSON }) => {
},
},
};
console.log(JSON.stringify(toSendData, null, 2));
const options = {
method: 'POST',
headers: {
Expand All @@ -96,14 +95,12 @@ const PublicationLinkCell = ({ value, aiJSON }) => {
return response.json(); // Parse the JSON in the response ? Or is it a text?
})
.then((data) => {
console.log(data);
setAISummaryData(data);
setPopoverOpen('aiSummary');
setPopoverPosition({ x: event.clientX, y: event.clientY });
inJSON.edge.aisummary = data;
})
.catch((error) => {
setAISummaryData('Error getting response from KG-Summarizer:: ', error);
setPopoverOpen('aiSummary');
setPopoverPosition({ x: event.clientX, y: event.clientY });
});
}

Expand Down Expand Up @@ -153,18 +150,14 @@ const PublicationLinkCell = ({ value, aiJSON }) => {
Get AI Summary
</GPTSummaryButton>
)}
<Popover
open={popoverOpen === 'aiSummary'}
onClose={() => setPopoverOpen(null)}
anchorPosition={{ top: popoverPosition.y, left: popoverPosition.x }}
above
>
<p style={{
margin: '20px', padding: '10px', fontStyle: 'italic', backgroundColor: '#f0f0f0',
}}
> {aiSummaryData}
</p>
</Popover>
{enabled && (aiSummaryData.length > 0) &&
(
<p style={{
margin: '20px', padding: '20px', fontStyle: 'italic', backgroundColor: '#f0f0f0',
}}
> {aiSummaryData}
</p>
)}
</TableCell>
);
};
Expand Down

0 comments on commit f0603aa

Please sign in to comment.