Files
Cyrene_v2/internal/runtime/model/adapter.go
T
AskaEth 3dc1232bc2
CI / Backend (build / vet / test / cross-compile) (push) Has been cancelled
CI / Frontend (tsc + vite build) (push) Has been cancelled
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
2026-10-04 16:27:54 +08:00

45 lines
2.0 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package model
import (
"context"
"errors"
)
// model 包返回的错误。向外传递时一律用 %w 包装,
// 以便调用方既能按类别判定,又能保留底层原因。
var (
// 无法解析出任何模型名时返回 ErrNoModel。
ErrNoModel = errors.New("model: no model configured")
// 降级链没有任何步骤时返回 ErrNoSteps。
ErrNoSteps = errors.New("model: empty fallback chain")
// 提供商请求失败(网络、状态码、解码)或降级链的
// 每一步都失败时,返回 ErrUpstream。
ErrUpstream = errors.New("model: upstream request failed")
// 请求无法编码为线格式时返回 ErrBadRequest。
ErrBadRequest = errors.New("model: invalid request")
// 流在完成前就结束时返回 ErrStream。
ErrStream = errors.New("model: stream closed before completion")
)
// Recorder 在一次成功完成的 LLM 调用之后接收 CallRecord。
// 它由各适配器调用,好让运行时(M9 监控/前端)收集用量,
// 而不必与任何存储后端耦合。
type Recorder func(CallRecord)
// Adapter 抽象单个 LLM 提供商。各实现面向具体厂商,
// 但都说归一化的 Request/Response 词汇;降级 Chain 或
// Router 都能组合它们,无需知道每个背后是哪家提供商。
type Adapter interface {
// Name 返回提供商/适配器的稳定标识。
Name() string
// Chat 执行一次非流式补全并返回完整响应。
Chat(ctx context.Context, req Request, opts Options) (Response, error)
// ChatStream 通过 onEvent 流出结构化事件,并返回聚合后的
// 响应(提供商上报用量时一并带上)。onEvent 可为 nil,
// 此时仍照常聚合、只是丢弃事件。提供商支持的每个片段
// 都被成对包裹(text_start/delta/end、tool_call_start/delta/end),
// 消费者因此可以独立渲染各片段;适配器尚无法区分的片段
// 以 text_delta 事件投递。
ChatStream(ctx context.Context, req Request, onEvent func(StreamEvent)) (Response, error)
}