Documentation
¶
Overview ¶
Package llmtest 提供剧本化假模型(应用侧测试注入——公开面零 eino 类型, 业务测试不 import eino 即可模拟模型行为)。Stream 每次调用按序消费一个 Turn 的剧本;用尽后回退 Plain 文本。Generate 同剧本取文本。
Index ¶
- func Switch(factories ...llm.ModelFactory) llm.ModelFactory
- type Model
- func (m *Model) CallCount() int
- func (m *Model) Dump() string
- func (m *Model) Factory() llm.ModelFactory
- func (m *Model) Generate(ctx context.Context, input []*schema.Message, _ ...model.Option) (*schema.Message, error)
- func (m *Model) ImagePartsOf(n int) int
- func (m *Model) Inputs() [][]*schema.Message
- func (m *Model) LastInputLen() int
- func (m *Model) LastInputToolResults() []string
- func (m *Model) Stream(ctx context.Context, input []*schema.Message, _ ...model.Option) (*schema.StreamReader[*schema.Message], error)
- type RecCall
- type Recorder
- type ToolCallSpec
- type Turn
- type Usage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Switch ¶
func Switch(factories ...llm.ModelFactory) llm.ModelFactory
Switch 按构造序分派多个 factory(应用层测试的父子模型装配用——引擎按 构造序先建主模型再建子代理/摘要模型,本函数让测试免直引 eino 类型即可 完成分派; factories 依次消费,超界恒回退末位)。
Types ¶
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
Model 剧本假模型(实现 llm.ModelFactory 的返回类型;并发安全)。
func (*Model) Factory ¶
func (m *Model) Factory() llm.ModelFactory
Factory 包成 ModelFactory(直接注入 engine.Options.NewModel)。
func (*Model) ImagePartsOf ¶
ImagePartsOf 第 n 次调用(1 基,0 = 最近一次)全部消息中的 image_url part 数 (多模态链路断言——应用层测试零 eino import 的替代面)。
func (*Model) LastInputToolResults ¶
LastInputToolResults 最近一次输入中 tool 消息内容(react 续答验证)。
type Recorder ¶
type Recorder struct {
// contains filtered or unexported fields
}
Recorder 构造入参记录器(并发安全)——会话内切换生效链测试锚点:断言 「下一次 LLM 交互」的工厂入参即会话快照现值。
func Record ¶
func Record(f llm.ModelFactory) (llm.ModelFactory, *Recorder)
Record 包装 factory 透传并记录每次构造入参(模型 id + effort)。
type ToolCallSpec ¶
ToolCallSpec 工具调用剧本(ID/名称/参数 JSON 字符串)。
type Turn ¶
type Turn struct {
Thinking string
Text string
ToolCalls []ToolCallSpec
// Usage 流末 usage chunk(Prompt/Completion/Total);nil 不发。
Usage *Usage
// Fragments 非空时忽略 ToolCalls:ToolCalls 按分片形态发送(测流式
// 参数增量归并——每项一次 chunk,首片带 ID/Name,续片仅 Args 增量)。
Fragments []ToolCallSpec
// Err 非 nil = 本轮以该错误收流(在发送 Thinking/Text 剧本内容之后注入
// ——模拟流中途断连;Generate 路径同错误直接返回)。网络容错测试锚点:
// 注 llm.ErrIdleTimeout 等可重试错误可驱动引擎重试层。
Err error
}
Turn 单次模型调用剧本:Thinking 与 Text 合成 assistant 消息(思考字段 + 内容字段),ToolCalls 随同消息;三者全空 = 纯文本「已处理。」。