Improve response extraction
This commit is contained in:
@@ -3,8 +3,16 @@ import { MessagesState } from "../state";
|
||||
import { AIMessage, BaseMessage } from "@langchain/core/messages";
|
||||
import { rankExampleTriggerEvents } from "../tools/retreiveExamples";
|
||||
|
||||
function extractTE(text: string) {
|
||||
const match = text.match(/<norm>([\s\S]*?)<\/norm>/);
|
||||
if (!match) throw new Error("Nothing found between <norm> tags");
|
||||
return match[1].trim();
|
||||
}
|
||||
|
||||
|
||||
export const triggerEventSetup: GraphNode<typeof MessagesState> = async (state) => {
|
||||
let nc = state?.messages?.at(-1)?.content ?? "" //keep a copy of normalized trigger event. Again two things, womp womp
|
||||
let raw = state?.messages?.at(-1)?.content ?? "" //keep a copy of normalized trigger event. Again two things, womp womp
|
||||
let nc = extractTE(raw.toString())
|
||||
|
||||
//Now give in-context examples. hopwfully we can self-teach?
|
||||
let similarityResults = await rankExampleTriggerEvents(state.disinformationTitle)
|
||||
|
||||
@@ -3,6 +3,12 @@ import { MessagesState, ProposedTriggerEventArray } from "../state";
|
||||
import { logger } from "../utils/logger";
|
||||
import { jsonrepair } from 'jsonrepair';
|
||||
|
||||
function extractJSON(text: string) {
|
||||
const match = text.match(/<json>([\s\S]*?)<\/json>/);
|
||||
if (!match) throw new Error("No JSON found between <json> tags");
|
||||
return match[1].trim();
|
||||
}
|
||||
|
||||
export const verificationSetup: GraphNode<typeof MessagesState> = async (state) => {
|
||||
if (state.proposedTriggerEvent == undefined) {
|
||||
logger.warn("No trigger events in memory, parsing");
|
||||
@@ -11,7 +17,8 @@ export const verificationSetup: GraphNode<typeof MessagesState> = async (state)
|
||||
|
||||
let repaired: string;
|
||||
try {
|
||||
repaired = jsonrepair(genResponse);
|
||||
let extracted = extractJSON(genResponse)
|
||||
repaired = jsonrepair(extracted);
|
||||
} catch (repairErr: any) {
|
||||
logger.error("Failed to repair JSON from LLM response.");
|
||||
logger.error("Original LLM response:\n%s", genResponse);
|
||||
|
||||
@@ -16,4 +16,7 @@ Relevent examples are included in preceeding messages, use these as exact inspir
|
||||
The claim to normalize is:
|
||||
###TITLE###
|
||||
|
||||
Produce no other text other than the condensed claim in inverted commas. Nothing should be around the normalised claim.
|
||||
Produce no other text other than the condensed claim, surrounded <norm></norm>
|
||||
|
||||
For example: BREAKING: the sky is green!
|
||||
Becomes: <norm>The sky is green</norm>
|
||||
@@ -17,10 +17,15 @@ Include a url to a source for your trigger event (not a web search, a specific u
|
||||
Include the date that the event happened ("March 2022" for exmaple)
|
||||
|
||||
Use a JSON format with each entry containing "Event,ReasoningWhyRelevant,SearchQuery,Url,Date".
|
||||
Return ONLY valid JSON.
|
||||
Do not include explanations.
|
||||
Do not wrap in markdown.
|
||||
Do not label where the json is using colons
|
||||
Return ONLY JSON, no extra text. Wrap it like this:
|
||||
<json>
|
||||
[
|
||||
{
|
||||
"Event": "Example"
|
||||
...
|
||||
}
|
||||
]
|
||||
</json>
|
||||
|
||||
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.
|
||||
@@ -32,4 +37,6 @@ Analysis should only be completed for proposed events that would graner >0.7 poi
|
||||
|
||||
Since URLs change frequently, use tools to retreive up to date informaiton everytime, provided examples or existing knowledge will be wrong or out of date.
|
||||
|
||||
Remember to return just json enclosed by <json></json>
|
||||
|
||||
Lets go through it step by step
|
||||
Reference in New Issue
Block a user