15f2a11162
- reasoningmode: 新增正文边界识别(结构行 + 前置空行)与流式 PartialFeed: 分步叙述按行拼接显示,正文开始时只输出正文,卡片更新即刷新清掉推理区 - dingtalk: 事件流与流式回调统一改走 PartialFeed - qa: 推理执行的最终答案在入库/投递前去掉步骤叙述(快速模式行为不变) 语料回归:生产 118 条内建智能推理答案中 106 条识别出正文边界(被隐藏的 均为 59-164 字过渡句),12 条无推理的问候类答案保持原样;go vet 与 go test ./... 全绿。
58 lines
2.1 KiB
Go
58 lines
2.1 KiB
Go
package dingtalk
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"gitea.zheromiku.top/Weknora/dobotai-platform/internal/reasoningmode"
|
|
)
|
|
|
|
func TestDecorateReasoningPartialMarksReasoningFromFirstChunk(t *testing.T) {
|
|
got := decorateReasoningPartial("部分答案", string(reasoningmode.ExecutionReasoning))
|
|
want := "【智能推理模式】\n\n部分答案"
|
|
if got != want {
|
|
t.Fatalf("got=%q want=%q", got, want)
|
|
}
|
|
}
|
|
|
|
func TestDecorateReasoningPartialLeavesQuickAnswerUnchanged(t *testing.T) {
|
|
if got := decorateReasoningPartial("快速答案", string(reasoningmode.ExecutionQuick)); got != "快速答案" {
|
|
t.Fatalf("got=%q", got)
|
|
}
|
|
}
|
|
|
|
func TestReasoningStreamingShowsStepsLineByLineThenDropsThemForBody(t *testing.T) {
|
|
execution := string(reasoningmode.ExecutionReasoning)
|
|
first := "我先确认一下设备的型号和手册。"
|
|
second := "手册里有关节扭矩表,让我核对一下。"
|
|
body := "## CR20V 关节电机最大旋转扭矩\n\n| 关节 | 扭矩 |"
|
|
feed := reasoningmode.NewPartialFeed(execution)
|
|
|
|
if got, want := decorateReasoningPartial(feed.OnAnswer(first), execution), "【智能推理模式】\n\n"+first; got != want {
|
|
t.Fatalf("step1 got=%q want=%q", got, want)
|
|
}
|
|
feed.StepBoundary()
|
|
if got, want := decorateReasoningPartial(feed.OnAnswer(first+second), execution), "【智能推理模式】\n\n"+first+"\n\n"+second; got != want {
|
|
t.Fatalf("step2 got=%q want=%q", got, want)
|
|
}
|
|
answer := first + second + "\n\n" + body
|
|
if got, want := decorateReasoningPartial(feed.OnAnswer(answer), execution), "【智能推理模式】\n\n"+body; got != want {
|
|
t.Fatalf("refresh got=%q want=%q", got, want)
|
|
}
|
|
got := feed.OnAnswer(answer + "\n| J1 | 98 N·m |")
|
|
if strings.Contains(got, first) || !strings.Contains(got, "J1") {
|
|
t.Fatalf("reasoning must stay hidden while the body streams, got=%q", got)
|
|
}
|
|
}
|
|
|
|
func TestQuickStreamingKeepsAccumulatedAnswer(t *testing.T) {
|
|
feed := reasoningmode.NewPartialFeed(string(reasoningmode.ExecutionQuick))
|
|
if got := feed.OnAnswer("快速答案"); got != "快速答案" {
|
|
t.Fatalf("got=%q", got)
|
|
}
|
|
feed.StepBoundary()
|
|
if got := feed.OnAnswer("快速答案追加"); got != "快速答案追加" {
|
|
t.Fatalf("got=%q", got)
|
|
}
|
|
}
|