Documentation
¶
Overview ¶
Package steerlooptest provides a scripted chat model and a recording tool executor for testing code built on steerloop without calling a provider.
Index ¶
- func ToolCall(id, name, arguments string) schema.ToolCall
- type Chunk
- type ExecutedCall
- type Handler
- type RecordingExecutor
- type ScriptedModel
- func (m *ScriptedModel) BoundTools() [][]*schema.ToolInfo
- func (m *ScriptedModel) CallCount() int
- func (m *ScriptedModel) Calls() [][]*schema.Message
- func (m *ScriptedModel) Generate(ctx context.Context, msgs []*schema.Message, opts ...model.Option) (*schema.Message, error)
- func (m *ScriptedModel) LastMessages() []*schema.Message
- func (m *ScriptedModel) LastOptions() *model.Options
- func (m *ScriptedModel) Stream(ctx context.Context, msgs []*schema.Message, opts ...model.Option) (*schema.StreamReader[*schema.Message], error)
- func (m *ScriptedModel) WithTools(tools []*schema.ToolInfo) (model.ToolCallingChatModel, error)
- type Step
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ExecutedCall ¶
ExecutedCall is one tool call seen by a RecordingExecutor.
type Handler ¶
type Handler func(ctx context.Context, msgs []*schema.Message, opts ...model.Option) (*schema.Message, error)
Handler replaces the script for a call when set on a ScriptedModel.
type RecordingExecutor ¶
type RecordingExecutor struct {
// contains filtered or unexported fields
}
RecordingExecutor is a tool executor that records every call and answers with a handler. It satisfies steerloop.ToolExecutor.
func NewRecordingExecutor ¶
func NewRecordingExecutor(handler func(ctx context.Context, name, args string) (string, error)) *RecordingExecutor
NewRecordingExecutor returns an executor that answers with handler. A nil handler answers "result from <tool>".
func (*RecordingExecutor) CallCount ¶
func (e *RecordingExecutor) CallCount() int
CallCount returns the number of tool calls made.
func (*RecordingExecutor) CalledTools ¶
func (e *RecordingExecutor) CalledTools() []string
CalledTools returns the names of the tools called, in order.
func (*RecordingExecutor) Calls ¶
func (e *RecordingExecutor) Calls() []ExecutedCall
Calls returns every tool call, in order.
func (*RecordingExecutor) ExecuteTool ¶
func (e *RecordingExecutor) ExecuteTool(ctx context.Context, name string, arguments string) (string, error)
ExecuteTool records the call and runs the handler.
type ScriptedModel ¶
type ScriptedModel struct {
// Handler, when set, answers every call instead of the script.
Handler Handler
// contains filtered or unexported fields
}
ScriptedModel is an Eino ToolCallingChatModel that plays Steps in order. When the script runs out the last step repeats. It records every call.
func NewScriptedModel ¶
func NewScriptedModel(steps ...Step) *ScriptedModel
NewScriptedModel returns a model that plays steps.
func (*ScriptedModel) BoundTools ¶
func (m *ScriptedModel) BoundTools() [][]*schema.ToolInfo
BoundTools returns the tool lists passed to WithTools, in order.
func (*ScriptedModel) CallCount ¶
func (m *ScriptedModel) CallCount() int
CallCount returns the number of model calls made.
func (*ScriptedModel) Calls ¶
func (m *ScriptedModel) Calls() [][]*schema.Message
Calls returns the messages of every call, in order.
func (*ScriptedModel) Generate ¶
func (m *ScriptedModel) Generate(ctx context.Context, msgs []*schema.Message, opts ...model.Option) (*schema.Message, error)
Generate returns the next step as one message.
func (*ScriptedModel) LastMessages ¶
func (m *ScriptedModel) LastMessages() []*schema.Message
LastMessages returns the messages of the most recent call.
func (*ScriptedModel) LastOptions ¶
func (m *ScriptedModel) LastOptions() *model.Options
LastOptions returns the options of the most recent call, resolved into Eino's common option set.
func (*ScriptedModel) Stream ¶
func (m *ScriptedModel) Stream(ctx context.Context, msgs []*schema.Message, opts ...model.Option) (*schema.StreamReader[*schema.Message], error)
Stream returns the next step as a stream. A step with Chunks is sent chunk by chunk with its delays; any other step is sent as a single chunk.
func (*ScriptedModel) WithTools ¶
func (m *ScriptedModel) WithTools(tools []*schema.ToolInfo) (model.ToolCallingChatModel, error)
WithTools records the tools and returns the same model.
type Step ¶
type Step struct {
// Content is the assistant text.
Content string
// ToolCalls are the tool calls the assistant makes.
ToolCalls []schema.ToolCall
// Err, when set, is returned instead of a message.
Err error
// Delay is waited before anything is returned.
Delay time.Duration
// Chunks, when set, replaces Content on the streaming path: each chunk is
// sent after its own delay. ToolCalls ride on the last chunk.
Chunks []Chunk
// Usage, when set, is reported as the token usage of the reply.
Usage *schema.TokenUsage
}
Step is what the scripted model returns for one call.
func LoadScript ¶
LoadScript reads a JSON script file into steps for NewScriptedModel.
func ParseScript ¶
ParseScript decodes a JSON script. Tool call arguments may be a JSON object or a string holding JSON. Unknown fields are rejected so a typo is not silently ignored.