Skip to content

Commit

Permalink
edits for PR
Browse files Browse the repository at this point in the history
  • Loading branch information
rosannamilner committed Aug 6, 2024
2 parents b6dace8 + 18238ff commit 2be7cd6
Show file tree
Hide file tree
Showing 16 changed files with 1,152 additions and 262 deletions.
76 changes: 61 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@mui/icons-material": "^5.14.12",
"@mui/lab": "^5.0.0-alpha.147",
"@mui/material": "^5.14.12",
"@mui/x-data-grid": "^7.9.0",
"@mui/x-date-pickers": "^6.16.1",
"@reduxjs/toolkit": "^1.9.7",
"@types/chrome": "^0.0.266",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,96 @@ export default function assistantApiCalls() {
);
};

const MAX_NUM_RETRIES = 3;

/**
* Calls an async function that throws an exception when it fails, will retry for numMaxRetries
* @param numMaxRetries Number of times the function will be retried
* @param asyncFunc The async function to call
* @param errorFunc Called when asyncFunc throws an error when there are additional retries
* @returns {Promise<*>} Output of asyncFunc
*/
async function callAsyncWithNumRetries(
numMaxRetries,
asyncFunc,
errorFunc = null,
) {
for (let retryCount = 0; retryCount < numMaxRetries; retryCount++) {
try {
return await asyncFunc();
} catch (e) {
if (retryCount + 1 >= MAX_NUM_RETRIES) {
throw e;
} else {
if (errorFunc) errorFunc(retryCount, e);
}
}
}
}

const callNewsFramingService = async (text) => {
return await callAsyncWithNumRetries(
MAX_NUM_RETRIES,
async () => {
const result = await axios.post(
assistantEndpoint + "gcloud/news-framing-clfr",
{ text: text },
);
return result.data;
},
(numTries) => {
console.log(
"Could not connect to news framing service, tries " +
(numTries + 1) +
"/" +
MAX_NUM_RETRIES,
);
},
);
};

const callNewsGenreService = async (text) => {
return await callAsyncWithNumRetries(
MAX_NUM_RETRIES,
async () => {
const result = await axios.post(
assistantEndpoint + "gcloud/news-genre-clfr",
{ text: text },
);
return result.data;
},
(numTries) => {
console.log(
"Could not connect to news genre service, tries " +
(numTries + 1) +
"/" +
MAX_NUM_RETRIES,
);
},
);
};

const callPersuasionService = async (text) => {
return await callAsyncWithNumRetries(
MAX_NUM_RETRIES,
async () => {
const result = await axios.post(
assistantEndpoint + "gcloud/persuasion-span-clfr",
{ text: text },
);
return result.data;
},
(numTries) => {
console.log(
"Could not connect to persuasion service, tries " +
(numTries + 1) +
"/" +
MAX_NUM_RETRIES,
);
},
);
};

const callOcrScriptService = async () => {
const result = await axios.get(assistantEndpoint + "gcloud/ocr-scripts");
return result.data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,34 +85,34 @@ function treeMapToElementsRecursive(
if ("span" in treeElem) {
const span = treeElem.span;
if (spanHighlightIndices === null) {
// console.log("No span highlight: ", text.substring(span.start, span.end));
console.log("No span highlight: ", text.substring(span.start, span.end));
childElems.push(text.substring(span.start, span.end));
} else {
// console.log("Span highlight: ", text.substring(span.start, span.end));
console.log("Span highlight: ", text.substring(span.start, span.end));
let currentIndex = span.start;
for (let i = 0; i < spanHighlightIndices.length; i++) {
const hSpan = spanHighlightIndices[i];
// console.log(
// "Matching span",
// span.start,
// span.end,
// hSpan.indices[0],
// hSpan.indices[1],
// );
console.log(
"Matching span",
span.start,
span.end,
hSpan.indices[0],
hSpan.indices[1],
);
const hSpanStart = hSpan.indices[0];
const hSpanEnd = hSpan.indices[1];
if (
(span.start <= hSpanStart && hSpanStart <= span.end) ||
(span.start <= hSpanEnd && hSpanEnd <= span.end)
) {
// //If there's an overlap
// console.log(
// "Found lapping span ",
// span.start,
// span.end,
// hSpanStart,
// hSpanEnd,
// );
//If there's an overlap
console.log(
"Found lapping span ",
span.start,
span.end,
hSpanStart,
hSpanEnd,
);

// If span doesn't start before the current index
if (hSpanStart > currentIndex) {
Expand All @@ -123,7 +123,7 @@ function treeMapToElementsRecursive(
hSpanStart < span.start ? span.start : hSpanStart;
const boundedEnd = hSpanEnd > span.end ? span.end : hSpanEnd;
if (wrapFunc) {
// console.log("Wrapping: ", text.substring(boundedStart, boundedEnd));
console.log("Wrapping: ", text.substring(boundedStart, boundedEnd));
childElems.push(
wrapFunc(
text.substring(boundedStart, boundedEnd),
Expand Down Expand Up @@ -161,7 +161,6 @@ function treeMapToElementsRecursive(
),
);
}

return React.createElement(treeElem.tag, null, childElems);
}

Expand Down
3 changes: 2 additions & 1 deletion src/components/NavItems/tools/Alltools/ToolsMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ import { useSelector } from "react-redux";
import { useNavigate } from "react-router-dom";
import { i18nLoadNamespace } from "components/Shared/Languages/i18nLoadNamespace";
import { Audiotrack } from "@mui/icons-material";
import { ROLES, tools, TOOLS_CATEGORIES } from "../../../../constants/tools";
import { tools, TOOLS_CATEGORIES } from "../../../../constants/tools";
import { ROLES } from "../../../../constants/roles";

function TabPanel(props) {
const { children, value, index, ...other } = props;
Expand Down
Loading

0 comments on commit 2be7cd6

Please sign in to comment.