docs(comments): 注释中文化 · internal/runtime/model + internal/services/backthink(54 文件,纯替换)
- 只翻注释/文档字符串:`go/scanner` 剥注释后按 token 序列+literal 逐 token 比对,**54/54 文件 SAME**;
改动文件总行数与 HEAD 漂移 = 0(严格 1:1,无合并/拆行)
- 裁决编号与 design 节号逐字保留(03.4.1/03.4.2/03.4.3/14.4.1/14.4.5/07.4.2-4、design/04 §3.1/§3.2 等);
`chat_template_kwargs` / `enable_thinking` / `reasoning_effort` / `thinking:{type}` 字段名与形状说明未动
- 存疑译法(已登记):`persona` 在叙事语境用「角色」、标识符语境保留 `persona`(仓库既有模块本身混用);
`rung`→「级」;`provider` 存在「提供商/提供者」两种落笔(可按需一键统一)
- 复核:build/vet 绿 + 两包测试绿;gofmt 干净;残留英文注释 0 条
- 既有存量(未修,只报告):`model/anthropic_test.go` 612 行 >500;`applyAnthropicEvent` 115 行 >80
This commit is contained in:
1 parent
f5cf117482
commit
3dc1232bc2
54 files changed
+1923
-1923
No files matched your search
@@ -11,20 +11,20 @@ import (
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/config"
|
||||
)
|
||||
|
||||
// captureLog returns a logger writing text records into a buffer, plus the
|
||||
// buffer, so a test can assert the WARN an adapter emits.
|
||||
// captureLog 返回一个把文本记录写进缓冲的日志器,外加那个
|
||||
// 缓冲,好让测试能断言适配器发出的 WARN。
|
||||
func captureLog() (*slog.Logger, *bytes.Buffer) {
|
||||
buf := &bytes.Buffer{}
|
||||
return slog.New(slog.NewTextHandler(buf, &slog.HandlerOptions{Level: slog.LevelDebug})), buf
|
||||
}
|
||||
|
||||
// boolPtr is a convenience for the tri-state Thinking.Enable.
|
||||
// boolPtr 是三态 Thinking.Enable 的便利构造。
|
||||
func boolPtr(v bool) *bool { return &v }
|
||||
|
||||
// TestAnthropicChat_ThinkingBudgetLeavesRoomForTheAnswer is the design/04 §3.2
|
||||
// red line: a budget large enough to eat max_tokens must not be sent as-is —
|
||||
// the adapter raises max_tokens so thinking and the visible answer both fit, and
|
||||
// it logs the adjustment (never a silent rewrite).
|
||||
// TestAnthropicChat_ThinkingBudgetLeavesRoomForTheAnswer 就是 design/04 §3.2
|
||||
// 的红线:大到能吃光 max_tokens 的预算不得照原样发送——
|
||||
// 适配器会抬高 max_tokens,让思考与可见答案都放得下,
|
||||
// 并记录这次调整(绝不是一次静默改写)。
|
||||
func TestAnthropicChat_ThinkingBudgetLeavesRoomForTheAnswer(t *testing.T) {
|
||||
t.Parallel()
|
||||
ch := make(chan anthropicCaptured, 1)
|
||||
@@ -35,8 +35,8 @@ func TestAnthropicChat_ThinkingBudgetLeavesRoomForTheAnswer(t *testing.T) {
|
||||
WithAnthropicLogger(log))
|
||||
|
||||
const budget = 4096
|
||||
// max_tokens equals the budget: without the guard the whole budget would be
|
||||
// consumed by thinking and the answer would come back empty.
|
||||
// max_tokens 恰好等于预算:没有这道守护,整个预算会被
|
||||
// 思考吃光,答案将空着返回。
|
||||
if _, err := ad.Chat(context.Background(), Request{
|
||||
Model: "claude-test",
|
||||
Messages: []Message{TextMessage(RoleUser, "hi")},
|
||||
@@ -69,9 +69,9 @@ func TestAnthropicChat_ThinkingBudgetLeavesRoomForTheAnswer(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestAnthropicChat_ThinkingBudgetBelowMaxTokensUnchanged pins the non-saturated
|
||||
// case: when the caller's max_tokens already leaves room, it is sent untouched
|
||||
// and the budget stays strictly below it.
|
||||
// TestAnthropicChat_ThinkingBudgetBelowMaxTokensUnchanged 钉住未饱和
|
||||
// 的情形:调用方的 max_tokens 本已留出空间时,它原样发送,
|
||||
// 而预算严格低于它。
|
||||
func TestAnthropicChat_ThinkingBudgetBelowMaxTokensUnchanged(t *testing.T) {
|
||||
t.Parallel()
|
||||
ch := make(chan anthropicCaptured, 1)
|
||||
@@ -104,8 +104,8 @@ func TestAnthropicChat_ThinkingBudgetBelowMaxTokensUnchanged(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestAnthropicChat_ThinkingDisabledOmitsField asserts the explicit off switch
|
||||
// sends no thinking directive at all (Anthropic treats a missing field as off).
|
||||
// TestAnthropicChat_ThinkingDisabledOmitsField 断言显式关闭开关
|
||||
// 完全不发送 thinking 指令(Anthropic 把字段缺失视为关闭)。
|
||||
func TestAnthropicChat_ThinkingDisabledOmitsField(t *testing.T) {
|
||||
t.Parallel()
|
||||
ch := make(chan anthropicCaptured, 1)
|
||||
@@ -124,8 +124,8 @@ func TestAnthropicChat_ThinkingDisabledOmitsField(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestAnthropicChat_ThinkingBudgetRaisedToProtocolMinimum asserts a budget below
|
||||
// the API minimum is raised (sending it as-is would 400) and reported.
|
||||
// TestAnthropicChat_ThinkingBudgetRaisedToProtocolMinimum 断言低于
|
||||
// API 最小值的预算会被抬高(照发会 400)并上报。
|
||||
func TestAnthropicChat_ThinkingBudgetRaisedToProtocolMinimum(t *testing.T) {
|
||||
t.Parallel()
|
||||
ch := make(chan anthropicCaptured, 1)
|
||||
@@ -151,8 +151,8 @@ func TestAnthropicChat_ThinkingBudgetRaisedToProtocolMinimum(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestOpenAIChat_ReasoningEffortPassthrough asserts a supported tier on a known
|
||||
// provider is forwarded verbatim, with no warning.
|
||||
// TestOpenAIChat_ReasoningEffortPassthrough 断言已知提供商上的
|
||||
// 受支持档位被原样转发,且不发出警告。
|
||||
func TestOpenAIChat_ReasoningEffortPassthrough(t *testing.T) {
|
||||
t.Parallel()
|
||||
ch := make(chan capturedRequest, 1)
|
||||
@@ -175,10 +175,10 @@ func TestOpenAIChat_ReasoningEffortPassthrough(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestOpenAIChat_ReasoningEffortAliasMappedForDeepSeek asserts a DeepSeek
|
||||
// compatibility alias is normalized to the tier the service applies (medium →
|
||||
// high per the official mapping table) and reported, never graded down to a
|
||||
// weaker tier of our own choosing.
|
||||
// TestOpenAIChat_ReasoningEffortAliasMappedForDeepSeek 断言 DeepSeek 的
|
||||
// 兼容别名被归一化为服务采用的档位(按官方映射表 medium →
|
||||
// high)并上报,绝不按我们自己挑的
|
||||
// 更弱档位降级。
|
||||
func TestOpenAIChat_ReasoningEffortAliasMappedForDeepSeek(t *testing.T) {
|
||||
t.Parallel()
|
||||
ch := make(chan capturedRequest, 1)
|
||||
@@ -204,9 +204,9 @@ func TestOpenAIChat_ReasoningEffortAliasMappedForDeepSeek(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestOpenAIChat_ReasoningEffortDroppedForUnknownProvider asserts an
|
||||
// unrecognized provider/model leaves the request untouched and reports the
|
||||
// ignored field (design/04 §3.2: never silently ineffective).
|
||||
// TestOpenAIChat_ReasoningEffortDroppedForUnknownProvider 断言无法识别的
|
||||
// 提供商/模型会让请求保持不动,并上报被
|
||||
// 忽略的字段(design/04 §3.2:绝不静默失效)。
|
||||
func TestOpenAIChat_ReasoningEffortDroppedForUnknownProvider(t *testing.T) {
|
||||
t.Parallel()
|
||||
ch := make(chan capturedRequest, 1)
|
||||
@@ -233,10 +233,10 @@ func TestOpenAIChat_ReasoningEffortDroppedForUnknownProvider(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestOpenAIChat_QwenEnableThinkingReportedNotForwarded documents the deliberate
|
||||
// choice for the Qwen3 hard switch: the OpenAI-compatible protocol has no
|
||||
// portable wire shape for enable_thinking, so this version reports it and leaves
|
||||
// the request byte-identical instead of guessing a shape that could 400.
|
||||
// TestOpenAIChat_QwenEnableThinkingReportedNotForwarded 记录了针对 Qwen3
|
||||
// 硬开关的刻意选择:OpenAI 兼容协议没有 enable_thinking 的
|
||||
// 可移植线格式,所以本版本上报它,并让请求
|
||||
// 逐字节保持原样,而不是去猜一个可能导致 400 的形状。
|
||||
func TestOpenAIChat_QwenEnableThinkingReportedNotForwarded(t *testing.T) {
|
||||
t.Parallel()
|
||||
ch := make(chan capturedRequest, 1)
|
||||
@@ -277,9 +277,9 @@ func TestOpenAIChat_QwenEnableThinkingReportedNotForwarded(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestOpenAIChat_ThinkingBudgetReportedIgnored asserts a token budget (an
|
||||
// Anthropic-style directive) is reported as unmappable on an OpenAI-compatible
|
||||
// endpoint rather than silently dropped.
|
||||
// TestOpenAIChat_ThinkingBudgetReportedIgnored 断言 token 预算
|
||||
// (Anthropic 风格的指令)在 OpenAI 兼容端点上会被上报为
|
||||
// 无法映射,而不是被静默丢弃。
|
||||
func TestOpenAIChat_ThinkingBudgetReportedIgnored(t *testing.T) {
|
||||
t.Parallel()
|
||||
ch := make(chan capturedRequest, 1)
|
||||
@@ -305,8 +305,8 @@ func TestOpenAIChat_ThinkingBudgetReportedIgnored(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestAnthropicChatStream_ThinkingBudgetLeavesRoomForTheAnswer runs the same
|
||||
// red-line check on the streaming path, which builds its own request body.
|
||||
// TestAnthropicChatStream_ThinkingBudgetLeavesRoomForTheAnswer 在流式
|
||||
// 路径上跑同一条红线检查,该路径会自建请求体。
|
||||
func TestAnthropicChatStream_ThinkingBudgetLeavesRoomForTheAnswer(t *testing.T) {
|
||||
t.Parallel()
|
||||
ch := make(chan anthropicCaptured, 1)
|
||||
@@ -337,8 +337,8 @@ func TestAnthropicChatStream_ThinkingBudgetLeavesRoomForTheAnswer(t *testing.T)
|
||||
}
|
||||
}
|
||||
|
||||
// TestReasoningVendorFor_Classification locks the vendor detection the whitelist
|
||||
// depends on, including the fallback to the base URL.
|
||||
// TestReasoningVendorFor_Classification 锁住白名单所依赖的厂商
|
||||
// 检测,包括回退到 base URL 的那条路径。
|
||||
func TestReasoningVendorFor_Classification(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
Reference in new issue
Block a user