Skip to content

Commit

Permalink
Adding credibility signals feature
Browse files Browse the repository at this point in the history
Add assistant text classifier UI with html formatting

first commit

added new sagas

starting to add accordion display

Displaying gcloud cred signals

tidied up list of genre, topic, persuasion

added typography

machince generated text service added

fixed subjectivity

displaying subjective sentences

displaying correct subjective sentences

tidied display of credibillity signals

using stored secrets for kinit services

removed classifiers from URL test box

added code for checking logged in for pfc

preventing pfc from being called if not logged in

removing unnnecessary imports

adding subj tooltip and pfc limit

refactored credibility signals

added messages for after logging in

login message and passing text to semantic search as variable

captialised genres

added assistant.json text

moved tooltips out to cardheader

pfc and mgt sagas work after login

typos

added comments

added embedding message

moved credsignals grid to correct card

removed console.log message

removed unnecessary tooltip

log

moved text to assistant.json

tidied code

counting categories in wrapfunc

counting categories in wrapfunc change

counting categories in wrapfunc change

Subjectivty confidence colour blue

refactoring pertech code

refactor for correct persuasion techniques

added/removed comments

updated tooltip text

remove console.log

fixes for persuasion techniques

fixes for subjectivity

edited keyword for semantic search

changed mgt.pred to use keyword
  • Loading branch information
rosannamilner committed Aug 5, 2024
1 parent 52ed9ce commit 50153f3
Show file tree
Hide file tree
Showing 16 changed files with 2,547 additions and 175 deletions.
273 changes: 159 additions & 114 deletions public/locales/en/components/NavItems/tools/Assistant.json

Large diffs are not rendered by default.

26 changes: 24 additions & 2 deletions src/components/NavItems/Assistant/Assistant.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import AssistantSCResults from "./AssistantScrapeResults/AssistantSCResults";
import AssistantTextResult from "./AssistantScrapeResults/AssistantTextResult";
import AssistantUrlSelected from "./AssistantUrlSelected";
import AssistantWarnings from "./AssistantScrapeResults/AssistantWarnings";
import AssistantCredSignals from "./AssistantScrapeResults/AssistantCredibilitySignals";

import {
cleanAssistantState,
Expand Down Expand Up @@ -52,6 +53,13 @@ const Assistant = () => {

//third party check states
const neResult = useSelector((state) => state.assistant.neResultCategory);
const newsFramingResult = useSelector(
(state) => state.assistant.newsFramingResult,
);
const newsGenreResult = useSelector(
(state) => state.assistant.newsGenreResult,
);
const hpResult = useSelector((state) => state.assistant.hpResult);

// source credibility
const positiveSourceCred = useSelector(
Expand Down Expand Up @@ -79,6 +87,13 @@ const Assistant = () => {
(state) => state.assistant.dbkfMediaMatchFail,
);
const neFailState = useSelector((state) => state.assistant.neFail);
const newsFramingFailState = useSelector(
(state) => state.assistant.newsFramingFail,
);
const newsGenreFailState = useSelector(
(state) => state.assistant.newsGenreFail,
);
// const mtFailState = useSelector(state => state.assistant.mtFail)

//local state
const [formInput, setFormInput] = useState(inputUrl);
Expand Down Expand Up @@ -163,7 +178,9 @@ const Assistant = () => {
{scFailState ||
dbkfTextFailState ||
dbkfMediaFailState ||
neFailState ? (
neFailState ||
newsFramingFailState ||
newsGenreFailState ? (
<Grid item xs>
<AssistantCheckStatus />
</Grid>
Expand Down Expand Up @@ -233,12 +250,17 @@ const Assistant = () => {
<AssistantLinkResult />
</Grid>
) : null}

{text ? (
<Grid item xs={12}>
<AssistantCredSignals />
</Grid>
) : null}
</Grid>
</Card>
</Grid>
</Grid>
</div>
);
};

export default Assistant;
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,166 @@ export default function assistantApiCalls() {
return result.data;
};

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;
};

const callSubjectivityService = async (text) => {
const result = await axios.post(assistantEndpoint + "dw/subjectivity", {
content: text,
});

return result.data;
};

const callPrevFactChecksService = async (text) => {
return await callAsyncWithNumRetries(
MAX_NUM_RETRIES,
async () => {
const result = await axios.get(
assistantEndpoint +
"kinit/prev-fact-checks" +
"?text=" +
encodeURIComponent(text), // max URL length is 2048 characters
);
return result.data;
},
(numTries) => {
console.log(
"Could not connect to previous fact checks service, tries " +
(numTries + 1) +
"/" +
MAX_NUM_RETRIES,
);
},
);
};

const callMachineGeneratedTextService = async (text) => {
return await callAsyncWithNumRetries(
MAX_NUM_RETRIES,
async () => {
const result = await axios.get(
assistantEndpoint +
"kinit/machine-generated-text" +
"?text=" +
encodeURIComponent(text), // max URL length is 2048 characters
);
return result.data;
},
(numTries) => {
console.log(
"Could not connect to machine generated text service, tries " +
(numTries + 1) +
"/" +
MAX_NUM_RETRIES,
);
},
);
};

return {
callAssistantScraper,
callSourceCredibilityService,
callNamedEntityService,
callOcrService,
callOcrScriptService,
callNewsFramingService,
callNewsGenreService,
callPersuasionService,
callSubjectivityService,
callPrevFactChecksService,
callMachineGeneratedTextService,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,29 @@ const AssistantCheckStatus = () => {
const neTitle = keyword("ne_title");
const neFailState = useSelector((state) => state.assistant.neFail);

const newsFramingTitle = "news topic";
const newsFramingFailState = useSelector(
(state) => state.assistant.newsFramingFail
);

const newsGenreTitle = "news genre";
const newsGenreFailState = useSelector(
(state) => state.assistant.newsGenreFail
);

const persuasionTitle = "persuasion";
const persuasionFailState = useSelector(
(state) => state.assistant.persuasionFail
);

const failStates = [
{ title: scTitle, failed: scFailState },
{ title: dbkfMediaTitle, failed: dbkfMediaFailState },
{ title: dbkfTextTitle, failed: dbkfTextFailState },
{ title: neTitle, failed: neFailState },
{ title: newsFramingTitle, failed: newsFramingFailState },
{ title: newsGenreTitle, failed: newsGenreFailState },
{ title: persuasionTitle, failed: persuasionFailState },
];

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,28 +139,30 @@ const ExtractedSourceCredibilityDBKFDialog = ({
? sourceCredibilityResults.map((value, key) => (
<Accordion key={key}>
<AccordionSummary expandIcon={<ExpandMoreIcon />}>
{sourceCredibilityResults[
key
].credibilityScope.includes("/") ? (
<Typography color={trafficLightColor}>
{` ${keyword("this")}`}
{getUrlTypeFromCredScope(
value.credibilityScope,
)}
{` ${keyword(
"source_credibility_warning_account",
)} ${" "}${value.credibilitySource}`}
</Typography>
) : sourceCredibilityResults[key]
.credibilityScope ? (
<Typography color={trafficLightColor}>
{` ${keyword(
"source_cred_popup_header_domain",
)} ${
sourceCredibilityResults[key]
.credibilitySource
} `}
</Typography>
{sourceCredibilityResults[key] ? (
sourceCredibilityResults[
key
].credibilityScope.includes("/") ? (
<Typography color={trafficLightColor}>
{` ${keyword("this")}`}
{getUrlTypeFromCredScope(
value.credibilityScope,
)}
{` ${keyword(
"source_credibility_warning_account",
)} ${" "}${value.credibilitySource}`}
</Typography>
) : sourceCredibilityResults[key]
.credibilityScope ? (
<Typography color={trafficLightColor}>
{` ${keyword(
"source_cred_popup_header_domain",
)} ${
sourceCredibilityResults[key]
.credibilitySource
} `}
</Typography>
) : null
) : null}
</AccordionSummary>

Expand Down
Loading

0 comments on commit 50153f3

Please sign in to comment.