Skip to content

Commit

Permalink
Merge pull request #634 from AFP-Medialab/assistant/long-article-issue
Browse files Browse the repository at this point in the history
Long article issue and fixes
  • Loading branch information
Sallaa authored Nov 4, 2024
2 parents 7b446ee + 2778e7b commit fa80621
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,6 @@ export default function assistantApiCalls() {
return namedEntityResult.data;
};

const callSourceCredibilityService = async (urlList) => {
if (urlList.length === 0) return null;

let urls = urlList.join(" ");

const result = await axios.post(
assistantEndpoint + "gcloud/source-credibility",
{ text: urls },
);

return result.data;
};

const callOcrService = async (data, script, mode) => {
const result = await axios.post(assistantEndpoint + "gcloud/ocr", {
text: data,
Expand Down Expand Up @@ -102,7 +89,32 @@ export default function assistantApiCalls() {
}
}
}

const callSourceCredibilityService = async (urlList) => {
return await callAsyncWithNumRetries(
MAX_NUM_RETRIES,
async () => {
if (urlList.length === 0) return null;

let urls = urlList.join(" ");

const result = await axios.post(
assistantEndpoint + "gcloud/source-credibility",
{ text: urls },
);
return result.data;
},
(numTries) => {
console.log(
"Could not connect to source credibility service, tries " +
(numTries + 1) +
"/" +
MAX_NUM_RETRIES,
);
},
);
};

const callNewsFramingService = async (text) => {
return await callAsyncWithNumRetries(
MAX_NUM_RETRIES,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,22 @@ const AssistantCheckStatus = () => {
(state) => state.assistant.newsGenreFail,
);

const persuasionTitle = keyword("persuasion_techniques");
const persuasionTitle = keyword("persuasion_techniques_title");
const persuasionFailState = useSelector(
(state) => state.assistant.persuasionFail,
);

const subjectivityTitle = keyword("subjectivity");
const subjectivityTitle = keyword("subjectivity_title");
const subjectivityFailState = useSelector(
(state) => state.assistant.subjectivityFail,
);

const prevFactChecksTitle = keyword("previous_fact_checks");
const prevFactChecksTitle = keyword("previous_fact_checks_title");
const prevFactChecksFailState = useSelector(
(state) => state.assistant.prevFactChecksFail,
);

const machineGeneratedTextTitle = keyword("machine_generated_text");
const machineGeneratedTextTitle = keyword("machine_generated_text_title");
const machineGeneratedTextFailState = useSelector(
(state) => state.assistant.machineGeneratedTextFail,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const AssistantCredSignals = () => {
const textHtmlMap = useSelector((state) => state.assistant.urlTextHtmlMap);

// news framing (topic)
const newsFramingTitle = keyword("news_framing");
const newsFramingTitle = keyword("news_framing_title");
const newsFramingResult = useSelector(
(state) => state.assistant.newsFramingResult,
);
Expand All @@ -122,7 +122,7 @@ const AssistantCredSignals = () => {
);

// news genre
const newsGenreTitle = keyword("news_genre");
const newsGenreTitle = keyword("news_genre_title");
const newsGenreResult = useSelector(
(state) => state.assistant.newsGenreResult,
);
Expand All @@ -133,7 +133,7 @@ const AssistantCredSignals = () => {
const newsGenreFail = useSelector((state) => state.assistant.newsGenreFail);

// persuasion techniques
const persuasionTitle = keyword("persuasion_techniques");
const persuasionTitle = keyword("persuasion_techniques_title");
const persuasionResult = useSelector(
(state) => state.assistant.persuasionResult,
);
Expand All @@ -144,7 +144,7 @@ const AssistantCredSignals = () => {
const persuasionFail = useSelector((state) => state.assistant.persuasionFail);

// subjectivity
const subjectivityTitle = keyword("subjectivity");
const subjectivityTitle = keyword("subjectivity_title");
const subjectivityResult = useSelector(
(state) => state.assistant.subjectivityResult,
);
Expand All @@ -159,7 +159,7 @@ const AssistantCredSignals = () => {
);

// previous fact checks
const prevFactChecksTitle = keyword("previous_fact_checks");
const prevFactChecksTitle = keyword("previous_fact_checks_title");
const prevFactChecksResult = useSelector(
(state) => state.assistant.prevFactChecksResult,
);
Expand All @@ -182,7 +182,7 @@ const AssistantCredSignals = () => {
const navigate = useNavigate();

// machine generated text
const machineGeneratedTextTitle = keyword("machine_generated_text");
const machineGeneratedTextTitle = keyword("machine_generated_text_title");
const machineGeneratedTextResult = useSelector(
(state) => state.assistant.machineGeneratedTextResult,
);
Expand Down
19 changes: 14 additions & 5 deletions src/redux/sagas/assistantSaga.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,8 @@ function* handlePersuasionCall(action) {
}
}

//const SERVER_TIMEOUT_LIMIT = 6000;

function* handleSubjectivityCall(action) {
if (action.type === "CLEAN_STATE") return;

Expand All @@ -445,7 +447,11 @@ function* handleSubjectivityCall(action) {
if (text) {
yield put(setSubjectivityDetails(null, true, false, false));

const result = yield call(assistantApi.callSubjectivityService, text);
const result = yield call(
assistantApi.callSubjectivityService,
text,
//text.substring(0, SERVER_TIMEOUT_LIMIT),
);

yield put(setSubjectivityDetails(result, false, true, false));
}
Expand All @@ -454,6 +460,8 @@ function* handleSubjectivityCall(action) {
}
}

const URL_BUFFER_LIMIT = 6000;

function* handlePrevFactChecksCall(action) {
if (action.type === "CLEAN_STATE") return;

Expand All @@ -466,7 +474,10 @@ function* handlePrevFactChecksCall(action) {
if (text && role.includes("BETA_TESTER")) {
yield put(setPrevFactChecksDetails(null, true, false, false));

const result = yield call(assistantApi.callPrevFactChecksService, text);
const result = yield call(
assistantApi.callPrevFactChecksService,
text.substring(0, URL_BUFFER_LIMIT),
);

yield put(
setPrevFactChecksDetails(result.fact_checks, false, true, false),
Expand All @@ -484,16 +495,14 @@ function* handleMachineGeneratedTextCall(action) {
const text = yield select((state) => state.assistant.urlText);

// this prevents the call from happening if not correct user status

//yield take("SET_SCRAPED_DATA"); // wait until linkList has been created
const role = yield select((state) => state.userSession.user.roles);

if (text && role.includes("BETA_TESTER")) {
yield put(setMachineGeneratedTextDetails(null, true, false, false));

const result = yield call(
assistantApi.callMachineGeneratedTextService,
text,
text.substring(0, URL_BUFFER_LIMIT),
);

yield put(setMachineGeneratedTextDetails(result, false, true, false));
Expand Down

0 comments on commit fa80621

Please sign in to comment.