Help us shape the future of Go! Take the 2026 Go Developer Survey

llmtest

package
v0.18.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 7 Imported by: 1

Documentation

Overview

Package llmtest eino ChatModel/Provider 的脚本化测试桩——llm/reflection/router 等包的测试共用(此前四份手写桩已漂移出两种耗尽语义与多种记录口径)。 只进测试二进制,不进任何生产依赖图。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToolCall

func ToolCall(name, arguments string) []schema.ToolCall

ToolCall 便捷构造单工具调用条目(name/arguments JSON)。

Types

type Model

type Model struct {
	Script     []Resp
	RepeatLast bool
	// StreamContent Stream 路径返回的单块内容(空 = "桩不支持流式")。
	StreamContent string

	// 断言面(测试读取)。
	FirstInput string   // 最近一次 Generate 的首条消息文本
	LastInput  string   // 最近一次 Generate 的末条消息文本
	Inputs     []string // 每次 Generate 的末条消息文本(调用序历史)
	// Heads 每次调用的首条消息文本(首条通常是 system 提示词——按调用序断言用)。
	Heads []string
	// Flats 每次调用的全部消息按 "role:content" 扁平拼接(多 system 消息共存的
	// 提示词组装断言用)。
	Flats []string
	Calls int
	// contains filtered or unexported fields
}

Model 脚本化 BaseChatModel 测试桩(并发安全)。

  • Script 按调用序消费;RepeatLast=true 时耗尽后重复末条(重试/降级链测试: 持续错误才能触发切换),false 时耗尽报错(防桩被多调——脚本写漏立即可见);
  • FirstInput/LastInput 记录每次 Generate 的首/末消息文本(提示词断言用);
  • StreamContent 非空时 Stream 返回该内容的单块流,空则报错(多数测试桩 不需要流式路径);
  • Calls 为 Generate+Stream 总调用数。

func (*Model) Generate

func (m *Model) Generate(_ context.Context, in []*schema.Message, _ ...model.Option) (*schema.Message, error)

Generate 按 Script 依次响应。

func (*Model) Stream

Stream 按同一脚本响应(Generate/Stream 共享调用序):条目带 ToolCalls 时 发带工具调用的消息,否则发 Content。StreamContent 非空时优先恒定内容 (简洁的单内容流场景)。

type Provider

type Provider struct {
	// Label Name() 返回值(字段不能与接口方法 Name() 同名)。
	Label      string
	ModelValue model.BaseChatModel
	CtxTokens  int
	MaxOut     int
	// Costs CostPer1KTokens 返回值 [prompt, completion]。
	Costs [2]float64
	// Timeout AttemptTimeout 返回值(>0 时生效;Resilient 单次尝试限时测试用)。
	Timeout time.Duration
}

Provider llm.Provider 接口的测试实现(Resilient 降级链测试用)。

func NewScriptedProvider

func NewScriptedProvider(name string, script ...Resp) *Provider

NewScriptedProvider 便捷构造:name + 脚本(耗尽重复末条——降级链测试依赖 持续错误触发切换),窗口 128k / 输出 4096 / 成本 0.001|0.002。

func (*Provider) AttemptTimeout

func (p *Provider) AttemptTimeout() time.Duration

AttemptTimeout 可选能力(llm.timeoutProvider 接口;0=不限)。

func (*Provider) ContextTokens

func (p *Provider) ContextTokens() int

func (*Provider) CostPer1KTokens

func (p *Provider) CostPer1KTokens() (float64, float64)

func (*Provider) MaxOutputTokens

func (p *Provider) MaxOutputTokens() int

func (*Provider) Model

func (p *Provider) Model() model.BaseChatModel

func (*Provider) ModelName

func (p *Provider) ModelName() string

func (*Provider) Name

func (p *Provider) Name() string

type Resp

type Resp struct {
	Content      string // 响应文本(Err 非空时忽略)
	Err          error  // 非空时本次调用返回该错误
	FinishReason string // 非空时填入 ResponseMeta(截断重试等场景断言用)
	// Prompt/Completion 非零时填入 ResponseMeta.Usage(真实 usage 记账断言用)。
	Prompt     int
	Completion int
	// ToolCalls 附带的工具调用(tool-calling 协议桩:adk planexecute 的
	// plan/respond 工具调用形态)。
	ToolCalls []schema.ToolCall
}

Resp 单次调用的脚本条目(Generate 与 Stream 共按序消费)。

type ToolModel

type ToolModel struct {
	*Model
	// ToolTag WithTools 派生副本的 Content 后缀(区分派生前后的响应)。
	ToolTag string
}

ToolModel 带 WithTools 派生能力的桩(ADK 绑工具路径的降级语义测试用; Model 本身不实现 ToolCallingChatModel——不支持绑定的场景直接用 Model)。

func (*ToolModel) WithTools

func (t *ToolModel) WithTools(_ []*schema.ToolInfo) (model.ToolCallingChatModel, error)

WithTools 返回带 ToolTag 标记的派生副本(脚本与状态共享父桩)。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL