mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-11-07 21:52:20 +01:00
* fix(llm): keep reasoning out of answers when thinking is off Small-budget utility calls on reasoning models spend every token on reasoning, and llm_call then returned reasoning_content as the answer. Web search extraction sent that text to SearXNG as the query, which found nothing, and session titles fell back as unusable. Treat thinking_mode="off" as "only the answer": non-streaming calls now return empty instead of substituting reasoning, matching the streaming path. Callers that do not turn thinking off keep the existing fallback. Turn thinking off for search query extraction, session titles without a configured effort, scheduled task names, and deep research classification, and strip inline think blocks from the extracted query. * fix(routing): require computer task wording for named hosts "on <word>" and "from <word>" counted as a named computer on their own, so "Who is Jensen Huang from NVIDIA?" and "What happened on Monday?" routed to shell tools and the workspace toolset. A target now only counts next to wording that describes work on a machine, such as "check disk usage on gpu-box" or "copy the logs from gpu-box". The intent classifier and the agent loop's local computer check share the pattern. * fix(chat): resolve follow-up references in web search queries Query extraction only saw the latest message, so "Does he work with Lisa Su?" lost who "he" was. Include the last four turns, capped per turn, and instruct the model to use them only to resolve references. Incognito turns do not use saved session history. * test(llm): stop reasoning fallback tests hanging in isolation The module replaced src.agent_tools and core.database with MagicMock before importing agent_loop. strip_tool_blocks then returned a mock, and _strip_think_blocks looped forever because a mock's find() never returns -1. This hung whenever the file ran alone or first on a worker. Import the real modules instead. * test(search): remove extra blank line at EOF --------- Co-authored-by: Alexandre Teixeira <general@alexandreteixeira.dev>
115 lines
3.6 KiB
Python
115 lines
3.6 KiB
Python
"""Regression tests for issue #1341 — deep research used the model's
|
|
training-cutoff year (e.g. "best Python tutorials 2025") because the
|
|
query-generation and planning prompts never told the LLM the current date.
|
|
|
|
The chat/agent path already injects "Today is ..." (src/agent_loop.py); deep
|
|
research had no equivalent. These tests pin that the current year now reaches
|
|
the LLM at both the planning and query-generation steps, without needing a live
|
|
LLM or DB.
|
|
"""
|
|
import asyncio
|
|
from datetime import datetime
|
|
|
|
from src.deep_research import (
|
|
DeepResearcher,
|
|
current_date_context,
|
|
RESEARCH_PLAN_PROMPT,
|
|
)
|
|
|
|
|
|
def _this_year() -> str:
|
|
return datetime.now().astimezone().strftime("%Y")
|
|
|
|
|
|
def test_current_date_context_names_the_real_year():
|
|
ctx = current_date_context()
|
|
assert _this_year() in ctx
|
|
# It must actively steer the model away from training-data years.
|
|
assert "training data" in ctx.lower()
|
|
|
|
|
|
def test_generate_queries_prompt_carries_the_current_year():
|
|
# Build without the heavy __init__; _generate_queries only needs these.
|
|
r = DeepResearcher.__new__(DeepResearcher)
|
|
r.research_plan = ""
|
|
r.queries_used = set()
|
|
|
|
seen = {}
|
|
|
|
async def _fake_llm(messages, **kwargs):
|
|
seen["prompt"] = messages[0]["content"]
|
|
return '["python tutorials", "python guides"]'
|
|
|
|
r._llm = _fake_llm
|
|
|
|
queries = asyncio.run(r._generate_queries("best python tutorials", "", 1))
|
|
|
|
assert queries # sanity: the JSON array parsed
|
|
# The fix: the real current year is in the prompt the LLM actually sees.
|
|
assert _this_year() in seen["prompt"]
|
|
|
|
|
|
def test_plan_prompt_carries_the_current_year():
|
|
r = DeepResearcher.__new__(DeepResearcher)
|
|
|
|
seen = {}
|
|
|
|
async def _fake_llm(messages, **kwargs):
|
|
seen["prompt"] = messages[0]["content"]
|
|
return "{}"
|
|
|
|
r._llm = _fake_llm
|
|
|
|
asyncio.run(r._create_plan("what changed this year"))
|
|
|
|
assert _this_year() in seen["prompt"]
|
|
# The base template itself stays year-agnostic; the year comes from the
|
|
# prepended context, proving the wiring (not a hard-coded prompt edit).
|
|
assert _this_year() not in RESEARCH_PLAN_PROMPT
|
|
|
|
|
|
def test_generate_queries_falls_back_to_original_question_when_model_returns_empty():
|
|
r = DeepResearcher.__new__(DeepResearcher)
|
|
r.research_plan = ""
|
|
r.queries_used = set()
|
|
r._progress = None
|
|
|
|
async def _fake_llm(messages, **kwargs):
|
|
return ""
|
|
|
|
r._llm = _fake_llm
|
|
|
|
queries = asyncio.run(r._generate_queries("latest AI news", "", 1))
|
|
|
|
assert queries == [
|
|
"latest AI news",
|
|
"latest AI news fact check",
|
|
"latest AI news reliable sources",
|
|
]
|
|
|
|
|
|
def test_small_model_detection_uses_parameter_size_in_model_title():
|
|
assert DeepResearcher._looks_like_small_local_model("Qwen-0.5B-Instruct")
|
|
assert DeepResearcher._looks_like_small_local_model("model-9B")
|
|
assert DeepResearcher._looks_like_small_local_model("model-10B")
|
|
assert not DeepResearcher._looks_like_small_local_model("model-11B")
|
|
|
|
|
|
def test_category_classification_turns_thinking_off(monkeypatch):
|
|
"""Reasoning lists every category name, which would defeat the label scan."""
|
|
sent = {}
|
|
|
|
async def fake_call(**kwargs):
|
|
sent.update(kwargs)
|
|
return "product"
|
|
|
|
monkeypatch.setattr("src.llm_core.llm_call_async", fake_call)
|
|
r = DeepResearcher.__new__(DeepResearcher)
|
|
r.llm_endpoint = "http://x"
|
|
r.llm_model = "m"
|
|
r.llm_headers = {}
|
|
|
|
assert asyncio.run(r._classify_category("Best ThinkPad to buy?")) == "product"
|
|
assert sent["thinking_mode"] == "off"
|
|
assert sent["max_tokens"] == 20
|