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:
@@ -71,9 +71,7 @@ cdef xmlDoc* _plainFakeRootDoc(xmlDoc* c_base_doc, xmlNode* c_node,
|
||||
return c_base_doc
|
||||
|
||||
c_doc = _copyDoc(c_base_doc, 0) # non recursive!
|
||||
c_new_root = tree.xmlDocCopyNode(c_node, c_doc, 2) if c_doc is not NULL else NULL # non recursive!
|
||||
if c_new_root is NULL:
|
||||
raise MemoryError()
|
||||
c_new_root = tree.xmlDocCopyNode(c_node, c_doc, 2) # non recursive!
|
||||
tree.xmlDocSetRootElement(c_doc, c_new_root)
|
||||
_copyParentNamespaces(c_node, c_new_root)
|
||||
|
||||
@@ -576,10 +574,7 @@ cdef void fixThreadDictNamesForDtd(tree.xmlDtd* c_dtd,
|
||||
_fixThreadDictPtr(&c_element.content.prefix, c_src_dict, c_dict)
|
||||
c_attribute = c_element.attributes
|
||||
while c_attribute:
|
||||
if tree.LIBXML_VERSION < 21500:
|
||||
# libxml2 2.15 no longer stores default values in the dict.
|
||||
# See https://gitlab.gnome.org/GNOME/libxml2/-/commit/24628f25
|
||||
_fixThreadDictPtr(<const_xmlChar**>&c_attribute.defaultValue, c_src_dict, c_dict)
|
||||
_fixThreadDictPtr(&c_attribute.defaultValue, c_src_dict, c_dict)
|
||||
_fixThreadDictPtr(&c_attribute.name, c_src_dict, c_dict)
|
||||
_fixThreadDictPtr(&c_attribute.prefix, c_src_dict, c_dict)
|
||||
_fixThreadDictPtr(&c_attribute.elem, c_src_dict, c_dict)
|
||||
|
||||
Reference in New Issue
Block a user