feat(agent): scrape linked pages to ground answers in real content
Adds `_fetch_page_content()`, which downloads a URL with a browser-like User-Agent and uses BeautifulSoup with the lxml parser to strip scripts, navigation, and other non-content markup, returning up to 3000 characters of readable text. The response validator now also compares generated replies against this scraped text, flagging named entities and claims that do not appear in the retrieved page content. Dependencies: adds beautifulsoup4==4.12.3 and pins lxml==5.3.0 for parser compatibility.
This commit is contained in:
@@ -6,9 +6,8 @@ cdef extern from "lxml-version.h":
|
||||
cdef char* LXML_VERSION_STRING
|
||||
|
||||
cdef extern from "libxml/xmlversion.h":
|
||||
const char* xmlParserVersion
|
||||
int LIBXML_VERSION
|
||||
|
||||
cdef const_char* xmlParserVersion
|
||||
cdef int LIBXML_VERSION
|
||||
|
||||
cdef extern from "libxml/xmlstring.h" nogil:
|
||||
ctypedef unsigned char xmlChar
|
||||
@@ -142,7 +141,7 @@ cdef extern from "libxml/tree.h" nogil:
|
||||
XML_ATTRIBUTE_NMTOKENS= 8
|
||||
XML_ATTRIBUTE_ENUMERATION= 9
|
||||
XML_ATTRIBUTE_NOTATION= 10
|
||||
|
||||
|
||||
ctypedef enum xmlAttributeDefault:
|
||||
XML_ATTRIBUTE_NONE= 1
|
||||
XML_ATTRIBUTE_REQUIRED= 2
|
||||
@@ -289,7 +288,7 @@ cdef extern from "libxml/tree.h" nogil:
|
||||
xmlDtd* intSubset
|
||||
xmlDtd* extSubset
|
||||
int properties
|
||||
|
||||
|
||||
ctypedef struct xmlAttr:
|
||||
void* _private
|
||||
xmlElementType type
|
||||
@@ -308,7 +307,7 @@ cdef extern from "libxml/tree.h" nogil:
|
||||
const_xmlChar* name
|
||||
xmlAttr* attr
|
||||
xmlDoc* doc
|
||||
|
||||
|
||||
ctypedef struct xmlBuffer
|
||||
|
||||
ctypedef struct xmlBuf # new in libxml2 2.9
|
||||
@@ -319,14 +318,14 @@ cdef extern from "libxml/tree.h" nogil:
|
||||
int error
|
||||
|
||||
const_xmlChar* XML_XML_NAMESPACE
|
||||
|
||||
|
||||
cdef void xmlFreeDoc(xmlDoc* cur)
|
||||
cdef void xmlFreeDtd(xmlDtd* cur)
|
||||
cdef void xmlFreeNode(xmlNode* cur)
|
||||
cdef void xmlFreeNsList(xmlNs* ns)
|
||||
cdef void xmlFreeNs(xmlNs* ns)
|
||||
cdef void xmlFree(void* buf)
|
||||
|
||||
|
||||
cdef xmlNode* xmlNewNode(xmlNs* ns, const_xmlChar* name)
|
||||
cdef xmlNode* xmlNewDocText(xmlDoc* doc, const_xmlChar* content)
|
||||
cdef xmlNode* xmlNewDocComment(xmlDoc* doc, const_xmlChar* content)
|
||||
@@ -438,7 +437,7 @@ cdef extern from "libxml/xmlIO.h":
|
||||
cdef xmlOutputBuffer* xmlOutputBufferCreateIO(
|
||||
xmlOutputWriteCallback iowrite,
|
||||
xmlOutputCloseCallback ioclose,
|
||||
void * ioctx,
|
||||
void * ioctx,
|
||||
xmlCharEncodingHandler* encoder) nogil
|
||||
cdef xmlOutputBuffer* xmlOutputBufferCreateFile(
|
||||
stdio.FILE* file, xmlCharEncodingHandler* encoder) nogil
|
||||
@@ -472,11 +471,14 @@ cdef extern from "libxml/globals.h" nogil:
|
||||
cdef int xmlThrDefKeepBlanksDefaultValue(int onoff)
|
||||
cdef int xmlThrDefLineNumbersDefaultValue(int onoff)
|
||||
cdef int xmlThrDefIndentTreeOutput(int onoff)
|
||||
|
||||
|
||||
cdef extern from "libxml/xmlmemory.h" nogil:
|
||||
cdef void* xmlMalloc(size_t size)
|
||||
cdef int xmlMemBlocks()
|
||||
cdef int xmlMemUsed()
|
||||
cdef void xmlMemDisplay(stdio.FILE* file)
|
||||
cdef void xmlMemDisplayLast(stdio.FILE* file, long num_bytes)
|
||||
cdef void xmlMemShow(stdio.FILE* file, int count)
|
||||
|
||||
cdef extern from "etree_defs.h" nogil:
|
||||
cdef bint _isElement(xmlNode* node)
|
||||
|
||||
Reference in New Issue
Block a user