docs(comments): 注释中文化 · internal/runtime/multimodal(21 文件,纯替换)
CI / Backend (build / vet / test / cross-compile) (push) Has been cancelled
CI / Frontend (tsc + vite build) (push) Has been cancelled

- 只翻注释/文档字符串,代码零变化:go/scanner 词法流比对 21 文件 token+字面量全等,增删行数 1:1(467/467)
- 刻意保留非散文英文:JSON Schema description、工具 Description() 返回值、adapter prompt、API 路径与命令示例、环境变量名
- 逐行确认代码前缀未变,未触碰其他模块
This commit is contained in:
AskaEth committed 2026-10-04 12:28:16 +08:00
1 parent b9e042d07d
commit b0fbb8bc0d
21 files changed
+467 -467

No files matched your search

+39 -39
View File
@@ -1,67 +1,67 @@
package vision
// Assessment is the model's own confidence in reading an image.
// Assessment 是模型对自己读图结果的置信度。
type Assessment string
const (
// AssessmentUnknown means the model reported no self-assessment.
// AssessmentUnknown 表示模型未给出自评。
AssessmentUnknown Assessment = "unknown"
// AssessmentGood means the model is confident in its read.
// AssessmentGood 表示模型对自己的读图结果有信心。
AssessmentGood Assessment = "good"
// AssessmentPoor means the model judged its recognition as poor.
// AssessmentPoor 表示模型判定自己的识别效果差。
AssessmentPoor Assessment = "poor"
)
// ModelInfo describes the main model's vision capability.
// ModelInfo 描述主模型的视觉能力。
type ModelInfo struct {
// Name identifies the model.
// Name 标识模型。
Name string
// SupportsVision reports whether the model accepts image input.
// SupportsVision 报告模型是否接受图像输入。
SupportsVision bool
// SelfAssessment is the model's own confidence for the current image.
// It drives the layer-2 tool route when SupportsVision is true.
// SelfAssessment 是模型对当前图像的自评置信度。
// 当 SupportsVision 为真时,它决定是否走第二层工具路由。
SelfAssessment Assessment
}
// DecisionKind is the chosen layered route.
// DecisionKind 是选定的分层路由。
type DecisionKind string
const (
// KindMain routes the image to the main model with the image in context.
// KindMain 把图像连同上下文一起交给主模型。
KindMain DecisionKind = "main"
// KindVisionTool routes to a dedicated vision tool, returning only the tool
// result so the image never occupies main-model context.
// KindVisionTool 路由到专用视觉工具,只返回工具
// 结果,使图像不占用主模型上下文。
KindVisionTool DecisionKind = "vision_tool"
// KindOCRTool routes to an OCR tool, returning only the extracted text.
// KindOCRTool 路由到 OCR 工具,只返回抽取出的文字。
KindOCRTool DecisionKind = "ocr_tool"
// KindUnsupported means no route can process the image.
// KindUnsupported 表示没有任何路由能处理该图像。
KindUnsupported DecisionKind = "unsupported"
)
// Decision is the outcome of a routing call.
// Decision 是一次路由调用的结果。
type Decision struct {
// Kind is the chosen route.
// Kind 是选定的路由。
Kind DecisionKind
// Tool names the vision or OCR tool to invoke, set when Kind is a tool route.
// Tool 指名要调用的视觉或 OCR 工具,当 Kind 为工具路由时设置。
Tool string
// Reason is a human-readable explanation for observability and logs.
// Reason 是便于可观测与日志的人类可读说明。
Reason string
}
// RouteRequest carries routing hints from the caller on top of the model info.
// RouteRequest 携带调用方在模型信息之外给出的路由提示。
type RouteRequest struct {
// TextPrimary reports that the user indicated the image is mainly text, so
// an OCR tool is preferred over a general vision model.
// TextPrimary 表示用户指出图像以文字为主,因此
// 优先使用 OCR 工具而非通用视觉模型。
TextPrimary bool
// MainSelfAssessedPoor is set when the main model has already judged its own
// read of the image as poor, requesting a vision/OCR tool route.
// MainSelfAssessedPoor 在主模型已自评读图效果
// 较差、请求走 vision/OCR 工具路由时置位。
MainSelfAssessedPoor bool
}
// RouterOption configures a Router.
// RouterOption 配置 Router。
type RouterOption func(*Router)
// WithVisionTool binds the name of the registered vision-understanding tool.
// WithVisionTool 绑定已注册的图像理解工具名。
func WithVisionTool(name string) RouterOption {
return func(r *Router) {
if name != "" {
@@ -70,7 +70,7 @@ func WithVisionTool(name string) RouterOption {
}
}
// WithOCRTool binds the name of the registered OCR tool.
// WithOCRTool 绑定已注册的 OCR 工具名。
func WithOCRTool(name string) RouterOption {
return func(r *Router) {
if name != "" {
@@ -79,15 +79,15 @@ func WithOCRTool(name string) RouterOption {
}
}
// Router implements the layered vision routing policy. It does no I/O; the
// caller uses the returned Decision to dispatch the request.
// Router 实现分层视觉路由策略。它不做任何 I/O;调用方
// 用返回的 Decision 去派发请求。
type Router struct {
visionTool string
ocrTool string
}
// NewRouter builds a Router. Unknown (empty) tool names leave the corresponding
// route unavailable, so the router degrades to KindMain or KindUnsupported.
// NewRouter 构造 Router。未知(空)的工具名会让对应
// 路由不可用,于是路由器降级为 KindMain 或 KindUnsupported。
func NewRouter(opts ...RouterOption) *Router {
r := &Router{}
for _, o := range opts {
@@ -96,21 +96,21 @@ func NewRouter(opts ...RouterOption) *Router {
return r
}
// Route picks a layered route for an image request given the target model info
// and caller hints. The order is: the main model directly when it can see and
// has not self-assessed poorly (layer 1); otherwise a vision or OCR tool whose
// result replaces the image in context (layers 2 and 3); otherwise
// KindUnsupported when nothing can process the image.
// Route 依据目标模型信息与调用方提示,为一次图像请求
// 选出分层路由。顺序为:主模型能看图且
// 未自评较差时直接用它(第一层);否则用能替换
// 上下文中图像的视觉或 OCR 工具(第二、三层);再否则
// 没有任何东西能处理该图像时给出 KindUnsupported。
func (r *Router) Route(target ModelInfo, req RouteRequest) Decision {
poor := target.SelfAssessment == AssessmentPoor || req.MainSelfAssessedPoor
// Layer 1: the main model accepts images and is confident, so use it first.
// 第一层:主模型接受图像且自信,优先使用它。
if target.SupportsVision && !poor {
return Decision{
Kind: KindMain,
Reason: "main model supports vision and is confident; use it directly",
}
}
// OCR is preferred when the user says the image is mostly text.
// 用户说明图像以文字为主时优先 OCR。
if req.TextPrimary && r.ocrTool != "" {
return Decision{Kind: KindOCRTool, Tool: r.ocrTool, Reason: "image is mainly text; route to OCR"}
}
@@ -120,7 +120,7 @@ func (r *Router) Route(target ModelInfo, req RouteRequest) Decision {
if r.ocrTool != "" {
return Decision{Kind: KindOCRTool, Tool: r.ocrTool, Reason: "route to OCR tool"}
}
// No tool is bound. A sighted main model remains the only option.
// 未绑定任何工具。能看图的主模型仍是唯一选择。
if target.SupportsVision {
return Decision{Kind: KindMain, Reason: "no vision/OCR tool bound; keep image with main model"}
}