mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-10-23 15:22:20 +02:00
require domain evidence for official source shortcut
This commit is contained in:
@@ -3251,17 +3251,7 @@ def web_source_links(raw, *, max_items=1, prefer_official=False, query=''):
|
|||||||
host == domain or host.endswith('.' + domain)
|
host == domain or host.endswith('.' + domain)
|
||||||
for domain in official_domains
|
for domain in official_domains
|
||||||
)
|
)
|
||||||
direct_document = bool(re.search(
|
if query_host_match:
|
||||||
r'\.(?:pdf|docx?|xlsx?|pptx?)(?:$|[?#])', row[1], re.I,
|
|
||||||
))
|
|
||||||
query_tokens_in_url = any(
|
|
||||||
token in row[1].casefold()
|
|
||||||
for token in query_tokens
|
|
||||||
if len(token) >= 4
|
|
||||||
)
|
|
||||||
if query_host_match or (
|
|
||||||
not official_domains and direct_document and query_tokens_in_url
|
|
||||||
):
|
|
||||||
primary.append(row)
|
primary.append(row)
|
||||||
rows = primary
|
rows = primary
|
||||||
links = []
|
links = []
|
||||||
@@ -5185,10 +5175,14 @@ async def stream_preview(*, endpoint_url, model, messages, headers, turn_contrac
|
|||||||
and requested_web_source_links(direct_user_text)
|
and requested_web_source_links(direct_user_text)
|
||||||
):
|
):
|
||||||
requested_links = requested_web_link_limit(direct_user_text)
|
requested_links = requested_web_link_limit(direct_user_text)
|
||||||
|
official_requested = bool(re.search(r'\bofficial\b', direct_user_text, re.I))
|
||||||
|
known_official_domains = official_domains_for_text(
|
||||||
|
direct_user_text + ' ' + str(args.get('query', ''))
|
||||||
|
)
|
||||||
source_links = web_source_links(
|
source_links = web_source_links(
|
||||||
output,
|
output,
|
||||||
max_items=requested_links or 1,
|
max_items=requested_links or 1,
|
||||||
prefer_official=bool(re.search(r'\bofficial\b', direct_user_text, re.I)),
|
prefer_official=official_requested,
|
||||||
query=args.get('query', ''),
|
query=args.get('query', ''),
|
||||||
)
|
)
|
||||||
source_only_request = not re.search(
|
source_only_request = not re.search(
|
||||||
@@ -5203,7 +5197,7 @@ async def stream_preview(*, endpoint_url, model, messages, headers, turn_contrac
|
|||||||
link for _, link in source_links[:requested_links]
|
link for _, link in source_links[:requested_links]
|
||||||
)
|
)
|
||||||
elif (requested_links and not source_links
|
elif (requested_links and not source_links
|
||||||
and re.search(r'\bofficial\b', direct_user_text, re.I)):
|
and official_requested and known_official_domains):
|
||||||
if not official_source_retry_attempted and round_number < round_limit:
|
if not official_source_retry_attempted and round_number < round_limit:
|
||||||
official_source_retry_attempted = True
|
official_source_retry_attempted = True
|
||||||
force_web_search_next_round = True
|
force_web_search_next_round = True
|
||||||
|
|||||||
@@ -2012,7 +2012,7 @@ def test_official_manual_does_not_invent_pdf_requirement():
|
|||||||
assert explicit['query'].endswith('filetype:pdf')
|
assert explicit['query'].endswith('filetype:pdf')
|
||||||
|
|
||||||
|
|
||||||
def test_unknown_official_domain_rejects_reseller_but_accepts_direct_document():
|
def test_unknown_official_domain_cannot_be_proven_by_pdf_suffix():
|
||||||
raw = '''
|
raw = '''
|
||||||
[1] WIKING Miro 4 Wood Burning Stove
|
[1] WIKING Miro 4 Wood Burning Stove
|
||||||
https://scottishstovecentre.co.uk/product/wiking-miro-4/
|
https://scottishstovecentre.co.uk/product/wiking-miro-4/
|
||||||
@@ -2025,11 +2025,9 @@ def test_unknown_official_domain_rejects_reseller_but_accepts_direct_document():
|
|||||||
query='WIKING Miro stove manual official source filetype:pdf',
|
query='WIKING Miro stove manual official source filetype:pdf',
|
||||||
)
|
)
|
||||||
|
|
||||||
assert links == [(
|
assert links == []
|
||||||
'https://www.hwam.com/pub/media/wiking/53-0756_Miro_EN.pdf',
|
# Candidates remain in the full tool output for the model to inspect.
|
||||||
'[Source: WIKING Miro Installation and User Manual]'
|
assert len(web_source_links(raw, max_items=2, query='WIKING Miro')) == 2
|
||||||
'(https://www.hwam.com/pub/media/wiking/53-0756_Miro_EN.pdf)',
|
|
||||||
)]
|
|
||||||
|
|
||||||
|
|
||||||
def test_web_fetch_collapses_single_and_batch_url_fields_without_losing_targets():
|
def test_web_fetch_collapses_single_and_batch_url_fields_without_losing_targets():
|
||||||
@@ -2044,7 +2042,7 @@ def test_web_fetch_collapses_single_and_batch_url_fields_without_losing_targets(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def test_manual_locator_prefers_manufacturer_link_and_requests_one_result():
|
def test_manual_locator_requests_one_result_but_needs_manufacturer_evidence():
|
||||||
from src.clean_agent_preview import (
|
from src.clean_agent_preview import (
|
||||||
requested_web_link_limit, requested_web_source_links, web_source_links,
|
requested_web_link_limit, requested_web_source_links, web_source_links,
|
||||||
)
|
)
|
||||||
@@ -2061,12 +2059,7 @@ def test_manual_locator_prefers_manufacturer_link_and_requests_one_result():
|
|||||||
assert requested_web_link_limit(prompt) == 1
|
assert requested_web_link_limit(prompt) == 1
|
||||||
assert web_source_links(
|
assert web_source_links(
|
||||||
raw, max_items=1, prefer_official=True, query=prompt,
|
raw, max_items=1, prefer_official=True, query=prompt,
|
||||||
) == [
|
) == []
|
||||||
(
|
|
||||||
'https://www.hwam.com/media/wiking/miro-en.pdf',
|
|
||||||
'[Source: WIKING Miro English manual PDF](https://www.hwam.com/media/wiking/miro-en.pdf)',
|
|
||||||
)
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def test_preview_allows_only_reversible_client_local_ui_control():
|
def test_preview_allows_only_reversible_client_local_ui_control():
|
||||||
|
|||||||
Reference in New Issue
Block a user