mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 07:30:05 +08:00
What happens while the answer is still being written. Prose that shared a
round with a tool call vanished into the trace, a truncated generation read as
the model deciding it had finished, and local indexing sat on the event loop
everything else needed.
- DSML tool calls are stripped from the stream incrementally instead of
all-or-nothing. Once a round's content channel showed markup, the rest of it
was diverted to the thinking channel, so any prose around the call left the
answer. DSMLStreamFilter suppresses only the envelope and the invoke blocks;
text before, between and after streams and persists (turn_runtime carries
answer_visible rounds into the assembled answer). An incomplete invoke is
released verbatim by flush, and a 512-char ceiling stops a stray `<` in
ordinary prose from making the live stream wait for a closing bracket.
- DSML parameter decoding consults the declared schema. DeepSeek marks
essentially every parameter string="true", arrays and objects included, so a
container argument reached the tool as a string of JSON. A parameter the
schema types array/object is parsed when the payload actually matches; the
provider's string contract still wins elsewhere. The catalog is kept when a
provider rejects native `tools` and the loop falls back to DSML — exactly
when the parser needs it.
- The round budget is three stages: exploration, a bounded settlement window
(MAX_SETTLEMENT_ROUNDS, tools still available so an already-started
interaction can finish), then one tool-less hard finish. A `length` finish is
an incomplete generation, not a decision to stop: the visible prefix is kept
and a continuation requested, under the same upper bound of exploration + 4.
- Resident memory across the process tree, at GET /api/v1/system/memory and in
the settings strip. runtime/memory_probe.py walks the tree; psutil is
imported lazily with a /proc fallback, so a missing wheel costs the strip and
not the app, and non-admins get {available: false}. The strip drops
LLM/Embedding/Search, which restated what the Models and Chat pages own.
- Local LightRAG indexing runs on a worker thread's own event loop.
RAG-Anything's local backends do synchronous graph merging and JSON
serialization inside async methods, stalling unrelated API and LLM work;
OwnerLoopBridge forwards LLM, vision and embedding calls back to the
request's loop with a copy of the caller's contextvars.
- Mastery works from the persisted question. learning/pending.py projects a
PendingQuestion into the public contract (prompt, type, label/body map) with
the expected answer server-side; ask_user renders that instead of display
data the model re-authored, and registration validates the quiz shape rather
than silently accepting a contradictory one.
- Connected KBs answer honestly about local files (empty listing, explicit 409
where a local file is required) instead of resolving a raw/ directory that
does not exist. resolve_public_output_path replaces is_public_output_path so
the new request-scoped /api/outputs endpoint authorizes and resolves in one
operation and fails closed with no request user. Visualize iframes measure
body content so they shrink as well as grow, and the chat page's model list
is fetched once behind a single-flight hook.
test_forced_finish_still_reports_the_tools_the_turn_carried asserted the old
two-stage budget (exhausted exploration = the next call is the tool-less
finish); it now drives through settlement to reach the real hard finish. Also
syncs the README prose, all ten translations, and the release-notes archive.
97 lines
2.4 KiB
TypeScript
97 lines
2.4 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import {
|
|
collectNarrationCallIds,
|
|
isNarrationMarker,
|
|
recomputeAnswerContent,
|
|
} from "../lib/stream";
|
|
import type { StreamEvent } from "../lib/unified-ws";
|
|
|
|
function event(
|
|
type: StreamEvent["type"],
|
|
content: string,
|
|
metadata: Record<string, unknown>,
|
|
): StreamEvent {
|
|
return {
|
|
type,
|
|
source: "chat",
|
|
stage: "responding",
|
|
content,
|
|
metadata,
|
|
session_id: "session-1",
|
|
turn_id: "turn-1",
|
|
seq: 1,
|
|
timestamp: 0,
|
|
};
|
|
}
|
|
|
|
test("ordinary narration is removed from answer content", () => {
|
|
const events = [
|
|
event("content", "Searching.", {
|
|
call_id: "round-1",
|
|
call_kind: "agent_loop_round",
|
|
}),
|
|
event("progress", "", {
|
|
call_id: "round-1",
|
|
trace_kind: "call_status",
|
|
call_state: "complete",
|
|
call_role: "narration",
|
|
}),
|
|
];
|
|
|
|
assert.deepEqual([...collectNarrationCallIds(events)], ["round-1"]);
|
|
assert.equal(isNarrationMarker(events[1]), true);
|
|
assert.equal(recomputeAnswerContent(events), "");
|
|
});
|
|
|
|
test("clean prose surrounding a DSML call remains answer-visible", () => {
|
|
const events = [
|
|
event("content", "Great job! Choose the next topic.", {
|
|
call_id: "round-dsml",
|
|
call_kind: "agent_loop_round",
|
|
}),
|
|
event("progress", "", {
|
|
call_id: "round-dsml",
|
|
trace_kind: "call_status",
|
|
call_state: "complete",
|
|
call_role: "narration",
|
|
answer_visible: true,
|
|
}),
|
|
];
|
|
|
|
assert.deepEqual([...collectNarrationCallIds(events)], []);
|
|
assert.equal(isNarrationMarker(events[1]), false);
|
|
assert.equal(
|
|
recomputeAnswerContent(events),
|
|
"Great job! Choose the next topic.",
|
|
);
|
|
});
|
|
|
|
test("token-limit continuation replays the exact visible answer", () => {
|
|
const events = [
|
|
event("content", "Part one. ", {
|
|
call_id: "round-part-1",
|
|
call_kind: "agent_loop_round",
|
|
}),
|
|
event("progress", "", {
|
|
call_id: "round-part-1",
|
|
trace_kind: "call_status",
|
|
call_state: "complete",
|
|
call_role: "narration",
|
|
answer_visible: true,
|
|
}),
|
|
event("content", "Part two.", {
|
|
call_id: "round-part-2",
|
|
call_kind: "agent_loop_round",
|
|
}),
|
|
event("progress", "", {
|
|
call_id: "round-part-2",
|
|
trace_kind: "call_status",
|
|
call_state: "complete",
|
|
call_role: "finish",
|
|
}),
|
|
];
|
|
|
|
assert.equal(recomputeAnswerContent(events), "Part one. Part two.");
|
|
});
|