testutil

package
v1.3.9 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package testutil 提供各包测试共享的 mock:脚本式 Provider、 阻塞 Provider、echo 工具与响应构造器。 仅 module 内部可用,避免在每个测试文件里重复定义。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Call

func Call(id, name string, args string) types.ToolCall

Call 构造一个工具调用。

func Text

func Text(s string) *types.ModelResponse

Text 构造纯文本响应。

func ToolCalls

func ToolCalls(calls ...types.ToolCall) *types.ModelResponse

ToolCalls 构造携带工具调用的响应。

Types

type BlockingProvider

type BlockingProvider struct{ Release chan struct{} }

BlockingProvider 阻塞直到 Release 关闭或 ctx 取消。

func NewBlocking

func NewBlocking() *BlockingProvider

func (*BlockingProvider) Invoke

type EchoTool

type EchoTool struct{}

EchoTool 回显参数的通用工具。

func (EchoTool) ArgsSchema

func (EchoTool) ArgsSchema() json.RawMessage

func (EchoTool) Description

func (EchoTool) Description() string

func (EchoTool) Invoke

func (EchoTool) Invoke(_ context.Context, args json.RawMessage) (string, error)

func (EchoTool) Name

func (EchoTool) Name() string

type ScriptedProvider

type ScriptedProvider struct {
	Script []*types.ModelResponse
	Calls  int
}

ScriptedProvider 按脚本顺序返回响应,超出脚本返回空响应(loop 自然结束)。 同时实现 ModelProvider 与 StreamProvider,流式时逐字符发 chunk。

func Scripted

func Scripted(resps ...*types.ModelResponse) *ScriptedProvider

func (*ScriptedProvider) Invoke

func (*ScriptedProvider) Stream

Jump to

Keyboard shortcuts

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