Skip to content

Commit

Permalink
CLEANUP and STYLE
Browse files Browse the repository at this point in the history
  • Loading branch information
Hina Shah committed Feb 5, 2024
1 parent f8a6772 commit 7a4e168
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 85 deletions.
32 changes: 9 additions & 23 deletions src/pages/answer/resultsTable/AttributesTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ const PublicationLinkCell = ({ value, aiJSON }) => {
const [popoverOpen, setPopoverOpen] = useState(false);
const [popoverPosition, setPopoverPosition] = useState({ x: 0, y: 0 });

// const [anchorEl, setAnchorEl] = useState(null);
// const spanRef = useRef();

const GPTSummaryButton = withStyles((theme) => ({
root: {
marginLeft: 'auto',
Expand All @@ -64,8 +61,6 @@ const PublicationLinkCell = ({ value, aiJSON }) => {
const publicationsArr = resultsUtils.getPublications(inJSON.edge);
const sentenceRes = resultsUtils.getSentences(inJSON.edge);
// setAnchorEl(spanRef.current);
console.log('FROM GPT SUMMARY FUNC, publications: ', publicationsArr);
console.log('FROM GPT SUMMARY FUNC, sentence: ', sentenceRes);
const toSendData = {
edge: {
nodes: inJSON.nodes,
Expand All @@ -85,8 +80,6 @@ const PublicationLinkCell = ({ value, aiJSON }) => {
},
},
};
console.log('CLICKED FROM GPU SUMMARY FUNC');
console.log(JSON.stringify(toSendData, null, 2));
const options = {
method: 'POST',
headers: {
Expand All @@ -96,34 +89,24 @@ const PublicationLinkCell = ({ value, aiJSON }) => {
};
const kgsummarizerurl = 'https://kg-summarizer.apps.renci.org/summarize/edge';
await fetch(kgsummarizerurl, options)
.then(response => {
.then((response) => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json(); // Parse the JSON in the response ? Or is it a text?
})
.then(data => {
console.log('KG SUMMARIZER Success:', data);
.then((data) => {
setAISummaryData(data);
setPopoverOpen('aiSummary');
setPopoverPosition({ x: event.clientX, y: event.clientY });
console.log(event.target);
})
.catch(error => {
setAISummaryData('Error getting response from KG-Summarizer');
.catch((error) => {
setAISummaryData('Error getting response from KG-Summarizer:: ', error);
setPopoverOpen('aiSummary');
setPopoverPosition({ x: event.clientX, y: event.clientY });
console.error('KG SUMMARIZER Error:', error);
});
}

// function handlePopoverClose() {
// setAnchorEl(null);
// setPopoverOpen(null);
// }
// const open = Boolean(anchorEl);
// const id = open ? "simple-popover" : undefined;

return (
<TableCell>
<ul style={{ padding: 0, margin: 0, listStyleType: 'none' }}>
Expand Down Expand Up @@ -166,7 +149,6 @@ const PublicationLinkCell = ({ value, aiJSON }) => {
onGPTSummary(event, aiJSON);
}}
variant="outlined"
// aria-describedby={id}
>
Get AI Summary
</GPTSummaryButton>
Expand All @@ -177,7 +159,11 @@ const PublicationLinkCell = ({ value, aiJSON }) => {
anchorPosition={{ top: popoverPosition.y, left: popoverPosition.x }}
above
>
<div> {aiSummaryData} </div>
<p style={{
margin: '20px', padding: '10px', fontStyle: 'italic', backgroundColor: '#f0f0f0',
}}
> {aiSummaryData}
</p>
</Popover>
</TableCell>
);
Expand Down
62 changes: 0 additions & 62 deletions src/pages/answer/useAnswerStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ export default function useAnswerStore() {
Object.values(analysis.edge_bindings).forEach((edgeBindings) => {
edgeBindings.forEach((binding) => {
const kgEdge = message.knowledge_graph.edges[binding.id];
//DEL console.log('--- TRYING TO WRITE STUFF FOR EDGE ID: ', binding.id);
//DEL console.log(JSON.stringify(kgEdge, null, 2));
edgesJSON[binding.id] = kgEdge || 'Unknown';
if (kgEdge) {
const graphEdge = {
Expand All @@ -144,73 +142,13 @@ export default function useAnswerStore() {
const objectNode = message.knowledge_graph.nodes[kgEdge.object];
const edgeKey = `${subjectNode.name || kgEdge.subject} ${stringUtils.displayPredicate(kgEdge.predicate)} ${objectNode.name || kgEdge.object}`;
publications[edgeKey] = resultsUtils.getPublications(kgEdge);
//DEL console.log(publications[edgeKey]);
// TODO: The following block should only happen if ChatGPT mode is on.
if (publications[edgeKey].length > 0) {
// Create the edge json object
const thisEdgeJson = {
nodes: nodesJSON,
edge: {
subject: kgEdge.subject,
object: kgEdge.object,
predicate: kgEdge.predicate,
publications: publications[edgeKey],
sentences: resultsUtils.getSentences(kgEdge),
},
};
// DEL console.log('Found one ore more publication!');
// DEL console.log(JSON.stringify(thisEdgeJson, null, 2));
// Send edge graph to kg-summarizer
const kgsummarizerurl = 'https://kg-summarizer.apps.renci.org/summarize/edge';
const toSendData = {
edge: thisEdgeJson,
parameters: {
llm: {
gpt_model: 'gpt-3.5-turbo',
temperature: 0,
system_prompt: '',
},
},
};
console.log('***** RIGHT BEFORE ITERATIVE KGSUMMARIZER');
console.log(JSON.stringify(toSendData, null, 2));
const options = {
method: 'POST',
headers: {
'Content-type': 'application/json',
},
body: JSON.stringify(toSendData),
};
// TODO: Add a metadata object to the original edgeJSON as GPT Summary
fetch(kgsummarizerurl, options)
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json(); // Parse the JSON in the response ? Or is it a text?
})
.then(data => {
console.log('KG SUMMARIZER Success:', data);
kgEdge.GPTSummary = data;
// Do something with the response data
})
.catch(error => {
console.error('KG SUMMARIZER Error:', error);
// Handle errors
});
}
}
});
});
});
setSelectedResult({ nodes, edges });
setSelectedRowId(rowId);
setMetaData(publications);
// TODO: If there are more than one publications, call chatgpt endpoint here?
console.log('*** NODES :::');
console.log(JSON.stringify(nodes, null, 2));
console.log('*** EDGES :::');
console.log(JSON.stringify(edgesJSON, null, 2));
// store full result JSON
setResultJSON({ knowledge_graph: { nodes: nodesJSON, edges: edgesJSON }, result: row });
}
Expand Down

0 comments on commit 7a4e168

Please sign in to comment.