Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cbaab3d251 |
@@ -9,7 +9,7 @@ export function createModelNode(tools: any, promptPath: string): GraphNode<typeo
|
|||||||
const sysPrompt = await hydratePrompt(promptPath, state);
|
const sysPrompt = await hydratePrompt(promptPath, state);
|
||||||
|
|
||||||
const model = new ChatOpenAI({
|
const model = new ChatOpenAI({
|
||||||
model: "gpt-5.4-mini"
|
model: "gpt-5-mini"
|
||||||
});
|
});
|
||||||
const modelWithTools = model.bindTools(Object.values(tools));
|
const modelWithTools = model.bindTools(Object.values(tools));
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import { GraphNode } from "@langchain/langgraph";
|
import { GraphNode } from "@langchain/langgraph";
|
||||||
import { MessagesState, ProposedTriggerEventArray } from "../state";
|
import { MessagesState, ProposedTriggerEventArray } from "../state";
|
||||||
import { logger } from "../utils/logger";
|
import { logger } from "../utils/logger";
|
||||||
import { jsonrepair } from 'jsonrepair'
|
import { queryScraper } from "../tools/webSearch";
|
||||||
|
import { rankAndDisplayData } from "../tools/triggerEventTools";
|
||||||
|
|
||||||
export const verificationSetup: GraphNode<typeof MessagesState> = async (state) => {
|
export const verificationSetup: GraphNode<typeof MessagesState> = async (state) => {
|
||||||
//this is kinda doing two things, but having two nodes for it seems overkill
|
//this is kinda doing two things, but having two nodes for it seems overkill
|
||||||
@@ -10,10 +11,7 @@ export const verificationSetup: GraphNode<typeof MessagesState> = async (state)
|
|||||||
logger.warn("No trigger events in memory, parsing")
|
logger.warn("No trigger events in memory, parsing")
|
||||||
|
|
||||||
let genResponse = state.messages.at(-1)?.content.toString() ?? "";
|
let genResponse = state.messages.at(-1)?.content.toString() ?? "";
|
||||||
|
const parsed = ProposedTriggerEventArray.parse(JSON.parse(genResponse));
|
||||||
const repaired = jsonrepair(genResponse);
|
|
||||||
|
|
||||||
const parsed = ProposedTriggerEventArray.parse(JSON.parse(repaired));
|
|
||||||
|
|
||||||
for (let i = 0; i < parsed.length; i++) {
|
for (let i = 0; i < parsed.length; i++) {
|
||||||
const search = parsed[i].SearchQuery
|
const search = parsed[i].SearchQuery
|
||||||
|
|||||||
Generated
-10
@@ -20,7 +20,6 @@
|
|||||||
"dotenv": "^17.2.3",
|
"dotenv": "^17.2.3",
|
||||||
"exponential-backoff": "^3.1.3",
|
"exponential-backoff": "^3.1.3",
|
||||||
"fs": "^0.0.1-security",
|
"fs": "^0.0.1-security",
|
||||||
"jsonrepair": "^3.13.3",
|
|
||||||
"langchain": "^1.2.14",
|
"langchain": "^1.2.14",
|
||||||
"selenium-webdriver": "^4.40.0",
|
"selenium-webdriver": "^4.40.0",
|
||||||
"tldts": "^7.0.23",
|
"tldts": "^7.0.23",
|
||||||
@@ -2076,15 +2075,6 @@
|
|||||||
"integrity": "sha512-ZClg6AaYvamvYEE82d3Iyd3vSSIjQ+odgjaTzRuO3s7toCdFKczob2i0zCh7JE8kWn17yvAWhUVxvqGwUalsRA==",
|
"integrity": "sha512-ZClg6AaYvamvYEE82d3Iyd3vSSIjQ+odgjaTzRuO3s7toCdFKczob2i0zCh7JE8kWn17yvAWhUVxvqGwUalsRA==",
|
||||||
"license": "ISC"
|
"license": "ISC"
|
||||||
},
|
},
|
||||||
"node_modules/jsonrepair": {
|
|
||||||
"version": "3.13.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/jsonrepair/-/jsonrepair-3.13.3.tgz",
|
|
||||||
"integrity": "sha512-BTznj0owIt2CBAH/LTo7+1I5pMvl1e1033LRl/HUowlZmJOIhzC0zbX5bxMngLkfT4WnzPP26QnW5wMr2g9tsQ==",
|
|
||||||
"license": "ISC",
|
|
||||||
"bin": {
|
|
||||||
"jsonrepair": "bin/cli.js"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/jszip": {
|
"node_modules/jszip": {
|
||||||
"version": "3.10.1",
|
"version": "3.10.1",
|
||||||
"resolved": "https://registry.npmjs.org/jszip/-/jszip-3.10.1.tgz",
|
"resolved": "https://registry.npmjs.org/jszip/-/jszip-3.10.1.tgz",
|
||||||
|
|||||||
@@ -24,7 +24,6 @@
|
|||||||
"dotenv": "^17.2.3",
|
"dotenv": "^17.2.3",
|
||||||
"exponential-backoff": "^3.1.3",
|
"exponential-backoff": "^3.1.3",
|
||||||
"fs": "^0.0.1-security",
|
"fs": "^0.0.1-security",
|
||||||
"jsonrepair": "^3.13.3",
|
|
||||||
"langchain": "^1.2.14",
|
"langchain": "^1.2.14",
|
||||||
"selenium-webdriver": "^4.40.0",
|
"selenium-webdriver": "^4.40.0",
|
||||||
"tldts": "^7.0.23",
|
"tldts": "^7.0.23",
|
||||||
|
|||||||
@@ -3,10 +3,9 @@ Once the information has been created as below, a dataset can be created to feed
|
|||||||
|
|
||||||
There is a false disinformation claim circulating:
|
There is a false disinformation claim circulating:
|
||||||
###NTITLE###
|
###NTITLE###
|
||||||
Produce up-to 5 specific "trigger events" that happened that could have led to the spread of this disinformation.
|
Produce up-to 5 specific events that happened that have led to the spread of this disinformation.
|
||||||
|
|
||||||
Remember the time frame of the disinformation campaign: ###CDATE###
|
Remember the time frame of the disinformation campaign: ###CDATE###
|
||||||
Include no information or events that would not have been available at the time.
|
|
||||||
|
|
||||||
Produce no more text other than the json.
|
Produce no more text other than the json.
|
||||||
|
|
||||||
@@ -14,20 +13,8 @@ Include a concise but specific search query that can be looked up on a search en
|
|||||||
|
|
||||||
Include a url to a source for your trigger event (not a web search, a specific url from a reputuable source). Do not use OAI cite, include url as text in response.
|
Include a url to a source for your trigger event (not a web search, a specific url from a reputuable source). Do not use OAI cite, include url as text in response.
|
||||||
|
|
||||||
Include the date that the event happened ("March 2022" for exmaple)
|
Use a JSON format with each entry containing "Event,ReasoningWhyRelevant,SearchQuery,Url".
|
||||||
|
|
||||||
Use a JSON format with each entry containing "Event,ReasoningWhyRelevant,SearchQuery,Url,Date".
|
|
||||||
|
|
||||||
Multiple tool invocations should be requested at once, if applicable.
|
Multiple tool invocations should be requested at once, if applicable.
|
||||||
Use your abilities to look between the lines and produce some insightful analysis, thinking both short and long term.
|
|
||||||
|
|
||||||
Events will be reordered as part of processing, each statement must stand alone
|
The preceeding messages act as examples of previous responses to potentially ficitonal events and scores given.
|
||||||
|
|
||||||
The preceeding messages act as examples of previous responses to potentially ficitonal events and scores given.
|
|
||||||
Analysis should only be completed for proposed events that would graner >0.7 points
|
|
||||||
|
|
||||||
First, consider a range of directions in which the proposed disinformation could have been influenced by.
|
|
||||||
Then, research these directions in turn, using the tools at hand.
|
|
||||||
Finally, refine your proposed "trigger event" until it is specific, quantifiable and backed up by evidence.
|
|
||||||
|
|
||||||
Lets go through it step by step
|
|
||||||
@@ -9,7 +9,6 @@ export const ProposedTriggerEvent = z.object({
|
|||||||
ReasoningWhyRelevant: z.string(),
|
ReasoningWhyRelevant: z.string(),
|
||||||
SearchQuery: z.string(),
|
SearchQuery: z.string(),
|
||||||
Url: z.url(),
|
Url: z.url(),
|
||||||
Date: z.string(),
|
|
||||||
context: z.string().optional(),
|
context: z.string().optional(),
|
||||||
score: z.number().optional()
|
score: z.number().optional()
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -15,8 +15,6 @@ const CACHE_PATH = "../data/csv.cache.json";
|
|||||||
|
|
||||||
const JSONL_PATH = "../data/input.jsonl"
|
const JSONL_PATH = "../data/input.jsonl"
|
||||||
|
|
||||||
const BM25_MIN_DOCS = 3;
|
|
||||||
|
|
||||||
type EmbeddingCache = {
|
type EmbeddingCache = {
|
||||||
rawtexts: string[];
|
rawtexts: string[];
|
||||||
cleantexts: string[];
|
cleantexts: string[];
|
||||||
@@ -289,20 +287,8 @@ async function embedText(text: string): Promise<number[]> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function buildBM25(texts: string[]) {
|
function buildBM25(texts: string[]) {
|
||||||
let paddedTexts = texts;
|
logger.info("Building BM25 index (%s docs)...", texts.length);
|
||||||
|
|
||||||
if (texts.length < BM25_MIN_DOCS) {
|
|
||||||
const needed = BM25_MIN_DOCS - texts.length;
|
|
||||||
logger.error(
|
|
||||||
"Corpus too small for BM25 (%s docs, need %s+), padding with %s dummy doc(s)",
|
|
||||||
texts.length,
|
|
||||||
BM25_MIN_DOCS,
|
|
||||||
needed
|
|
||||||
);
|
|
||||||
paddedTexts = [...texts, ...Array(needed).fill("placeholder dummy document")];
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info("Building BM25 index (%s docs)...", paddedTexts.length);
|
|
||||||
const bm25 = bm25Factory();
|
const bm25 = bm25Factory();
|
||||||
|
|
||||||
bm25.defineConfig({
|
bm25.defineConfig({
|
||||||
@@ -316,7 +302,7 @@ function buildBM25(texts: string[]) {
|
|||||||
nlp.tokens.removeWords,
|
nlp.tokens.removeWords,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
paddedTexts.forEach((text, i) => {
|
texts.forEach((text, i) => {
|
||||||
bm25.addDoc({ text }, i);
|
bm25.addDoc({ text }, i);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+20
-80
@@ -1,92 +1,32 @@
|
|||||||
import { Builder, Browser } from "selenium-webdriver";
|
import { Builder, Browser } from "selenium-webdriver";
|
||||||
import firefox from "selenium-webdriver/firefox";
|
import firefox from "selenium-webdriver/firefox";
|
||||||
import { backOff } from "exponential-backoff";
|
|
||||||
import { logger } from "../utils/logger";
|
|
||||||
|
|
||||||
export async function extractWebpageContent(url: string): Promise<string[]> {
|
export async function extractWebpageContent(url: string) : Promise<string[]>{
|
||||||
try {
|
|
||||||
const response = await backOff(async () => {
|
|
||||||
return await extractWebpageContentWorker(url);
|
|
||||||
}, {
|
|
||||||
numOfAttempts: 5,
|
|
||||||
startingDelay: 500,
|
|
||||||
timeMultiple: 2,
|
|
||||||
jitter: "full",
|
|
||||||
maxDelay: 50000,
|
|
||||||
});
|
|
||||||
return response;
|
|
||||||
} catch (err: any) {
|
|
||||||
logger.error(`Failed out of retry loop for URL "${url}", returning placeholder to pipeline`);
|
|
||||||
return ["API EXCEPTION"];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function extractWebpageContentWorker(url: string): Promise<string[]> {
|
|
||||||
let driver;
|
|
||||||
try {
|
|
||||||
const options = new firefox.Options();
|
const options = new firefox.Options();
|
||||||
options.addArguments("--headless");
|
options.addArguments("--headless");
|
||||||
driver = await new Builder()
|
|
||||||
.forBrowser(Browser.FIREFOX)
|
|
||||||
.setFirefoxOptions(options)
|
|
||||||
.build();
|
|
||||||
} catch (err: any) {
|
|
||||||
const desc = `Failed to launch Firefox driver: ${err.message}`;
|
|
||||||
logger.error(desc);
|
|
||||||
throw new Error(desc);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
let driver = await new Builder().forBrowser(Browser.FIREFOX).setFirefoxOptions(options).build()
|
||||||
try {
|
try {
|
||||||
await driver.get(url);
|
await driver.get(url)
|
||||||
} catch (err: any) {
|
await driver.wait(async () => {
|
||||||
const desc = `Failed to navigate to URL "${url}": ${err.message}`;
|
return await driver.executeScript(
|
||||||
logger.error(desc);
|
"return document.readyState === 'complete'"
|
||||||
throw new Error(desc);
|
);
|
||||||
}
|
}, 5000);
|
||||||
|
|
||||||
try {
|
const readableText = await driver.executeScript(
|
||||||
await driver.wait(async () => {
|
"return document.body.innerText;"
|
||||||
return await driver.executeScript(
|
) as string;
|
||||||
"return document.readyState === 'complete'"
|
|
||||||
);
|
|
||||||
}, 5000);
|
|
||||||
} catch (err: any) {
|
|
||||||
logger.error(`Page load timed out for "${url}", attempting to read partial content: ${err.message}`);
|
|
||||||
// do not throw, attempt to read
|
|
||||||
}
|
|
||||||
|
|
||||||
let readableText: string;
|
const filteredLines = readableText
|
||||||
try {
|
.split(/\r?\n/)
|
||||||
readableText = await driver.executeScript(
|
.map(line => line.trim())
|
||||||
"return document.body.innerText;"
|
.filter(line => line.split(/\s+/).length > 1);
|
||||||
) as string;
|
|
||||||
} catch (err: any) {
|
return filteredLines;
|
||||||
const desc = `Failed to extract page text from "${url}": ${err.message}`;
|
} finally {
|
||||||
logger.error(desc);
|
await driver.quit()
|
||||||
throw new Error(desc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const filteredLines = readableText
|
|
||||||
.split(/\r?\n/)
|
|
||||||
.map(line => line.trim())
|
|
||||||
.filter(line => line.split(/\s+/).length > 1);
|
|
||||||
|
|
||||||
if (filteredLines.length === 0) {
|
|
||||||
const desc = `No content extracted from "${url}"`;
|
|
||||||
logger.error(desc);
|
|
||||||
throw new Error(desc);
|
|
||||||
}
|
|
||||||
|
|
||||||
return filteredLines;
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
await driver.quit();
|
|
||||||
} catch (err: any) {
|
|
||||||
logger.error(`Failed to quit Firefox driver cleanly: ${err.message}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// console.log(await extractWebpageContent("https://www.bbc.co.uk/news/live/c74wd01egvyt"))
|
//console.log(await extractWebpageContent("https://www.bbc.co.uk/news/live/c74wd01egvyt"))
|
||||||
// console.log(await extractWebpageContent("https://badcertificate.int.jeynes.uk/"))
|
|
||||||
@@ -118,7 +118,7 @@ async function processRecord(record: any): Promise<ResultRecord> {
|
|||||||
input: buildAgentInput(record),
|
input: buildAgentInput(record),
|
||||||
streamMode: "values",
|
streamMode: "values",
|
||||||
config: {
|
config: {
|
||||||
recursion_limit: 100
|
recursion_limit: 50
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user