Documentation
¶
Overview ¶
Package testutil provides test utilities for goai. Source: ai-sdk/packages/ai/src/test/mock-language-model-v3.ts
Index ¶
- func AssertResultWarning(t *testing.T, warnings []stream.Warning, want stream.Warning)
- func AssertWarning(t *testing.T, warnings []stream.Warning, want stream.Warning)
- func CollectStream(t *testing.T, ch <-chan stream.Event, err error) []stream.Event
- func FindFirstStartEvent(t *testing.T, events []stream.Event) *stream.StartEvent
- func MockErrorResponse(err error) []stream.Event
- func MockReasoningResponse(reasoningText, text string, usage stream.Usage) []stream.Event
- func MockStreamedTextResponse(chunks []string, usage stream.Usage) []stream.Event
- func MockTextResponse(text string, usage stream.Usage) []stream.Event
- func MockTextWithToolCallResponse(text, toolCallID, toolName string, input any, usage stream.Usage) []stream.Event
- func MockToolCallResponse(toolCallID, toolName string, input any, usage stream.Usage) []stream.Event
- func MockUsage(promptTokens, completionTokens int) stream.Usage
- type MockEmbeddingModel
- func (m *MockEmbeddingModel) Dimensions() int
- func (m *MockEmbeddingModel) Embed(ctx context.Context, opts model.EmbedCallOptions) (*model.EmbedResult, error)
- func (m *MockEmbeddingModel) ID() string
- func (m *MockEmbeddingModel) MaxEmbeddingsPerCall() int
- func (m *MockEmbeddingModel) Provider() string
- type MockEmbeddingModelOptions
- type MockImageModel
- type MockImageModelOptions
- type MockLanguageModel
- type MockLanguageModelOptions
- type MockSpeechModel
- type MockSpeechModelOptions
- type MockTranscriptionModel
- type MockTranscriptionModelOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertResultWarning ¶
AssertResultWarning is an alias for AssertWarning, named to match non-language-model result types (ImageResult.Warnings, etc.).
func AssertWarning ¶
AssertWarning fails the test if warnings does not contain want. Matches on Type + Feature + Message; Details is ignored.
func CollectStream ¶
CollectStream drains a stream channel into a slice.
func FindFirstStartEvent ¶
FindFirstStartEvent returns the first StartEvent in events. Fails the test if no StartEvent is present.
func MockErrorResponse ¶
MockErrorResponse creates events for an error response.
func MockReasoningResponse ¶
MockReasoningResponse creates events for a response with reasoning.
func MockStreamedTextResponse ¶
MockStreamedTextResponse creates events for a streamed text response with multiple chunks.
func MockTextResponse ¶
MockTextResponse creates events for a simple text response.
func MockTextWithToolCallResponse ¶
func MockTextWithToolCallResponse(text, toolCallID, toolName string, input any, usage stream.Usage) []stream.Event
MockTextWithToolCallResponse creates events for a response with both text and tool call.
Types ¶
type MockEmbeddingModel ¶
type MockEmbeddingModel struct {
DoEmbedFunc func(ctx context.Context, opts model.EmbedCallOptions) (*model.EmbedResult, error)
DoEmbedCalls []model.EmbedCallOptions
EmbedResponse *model.EmbedResult
// contains filtered or unexported fields
}
MockEmbeddingModel is a mock implementation of EmbeddingModel for testing.
func NewMockEmbeddingModel ¶
func NewMockEmbeddingModel(opts MockEmbeddingModelOptions) *MockEmbeddingModel
NewMockEmbeddingModel creates a new mock embedding model.
func (*MockEmbeddingModel) Dimensions ¶
func (m *MockEmbeddingModel) Dimensions() int
func (*MockEmbeddingModel) Embed ¶
func (m *MockEmbeddingModel) Embed(ctx context.Context, opts model.EmbedCallOptions) (*model.EmbedResult, error)
func (*MockEmbeddingModel) ID ¶
func (m *MockEmbeddingModel) ID() string
func (*MockEmbeddingModel) MaxEmbeddingsPerCall ¶
func (m *MockEmbeddingModel) MaxEmbeddingsPerCall() int
func (*MockEmbeddingModel) Provider ¶
func (m *MockEmbeddingModel) Provider() string
type MockEmbeddingModelOptions ¶
type MockEmbeddingModelOptions struct {
ID string
Provider string
Dimensions int
MaxEmbeddingsPerCall int
DoEmbedFunc func(ctx context.Context, opts model.EmbedCallOptions) (*model.EmbedResult, error)
EmbedResponse *model.EmbedResult
}
MockEmbeddingModelOptions configures the mock embedding model.
type MockImageModel ¶
type MockImageModel struct {
DoGenerateFunc func(ctx context.Context, opts model.ImageCallOptions) (*model.ImageResult, error)
DoGenerateCalls []model.ImageCallOptions
GenerateResponse *model.ImageResult
// contains filtered or unexported fields
}
MockImageModel is a mock implementation of ImageModel for testing.
func NewMockImageModel ¶
func NewMockImageModel(opts MockImageModelOptions) *MockImageModel
NewMockImageModel creates a new mock image model.
func (*MockImageModel) Generate ¶
func (m *MockImageModel) Generate(ctx context.Context, opts model.ImageCallOptions) (*model.ImageResult, error)
func (*MockImageModel) ID ¶
func (m *MockImageModel) ID() string
func (*MockImageModel) MaxImagesPerCall ¶
func (m *MockImageModel) MaxImagesPerCall() int
func (*MockImageModel) Provider ¶
func (m *MockImageModel) Provider() string
type MockImageModelOptions ¶
type MockImageModelOptions struct {
ID string
Provider string
MaxImagesPerCall int
DoGenerateFunc func(ctx context.Context, opts model.ImageCallOptions) (*model.ImageResult, error)
GenerateResponse *model.ImageResult
}
MockImageModelOptions configures the mock image model.
type MockLanguageModel ¶
type MockLanguageModel struct {
// DoStreamFunc is called for each Stream call. If set, takes precedence over StreamResponses.
DoStreamFunc func(ctx context.Context, options *stream.CallOptions) (<-chan stream.Event, error)
// StreamResponses is a list of responses to return in sequence.
// Each call to Stream returns the next response.
StreamResponses [][]stream.Event
// DoStreamCalls records all calls to Stream for assertions.
DoStreamCalls []*stream.CallOptions
// contains filtered or unexported fields
}
MockLanguageModel is a mock implementation of LanguageModel for testing. It mirrors ai-sdk's MockLanguageModelV4.
func NewMockLanguageModel ¶
func NewMockLanguageModel(opts MockLanguageModelOptions) *MockLanguageModel
NewMockLanguageModel creates a new mock language model.
func (*MockLanguageModel) ID ¶
func (m *MockLanguageModel) ID() string
func (*MockLanguageModel) Provider ¶
func (m *MockLanguageModel) Provider() string
func (*MockLanguageModel) Stream ¶
func (m *MockLanguageModel) Stream(ctx context.Context, options *stream.CallOptions) (<-chan stream.Event, error)
type MockLanguageModelOptions ¶
type MockLanguageModelOptions struct {
// ID is the model identifier. Defaults to "mock-model-id".
ID string
// Provider is the provider identifier. Defaults to "mock-provider".
Provider string
// DoStreamFunc is called for each Stream call.
// If set, takes precedence over StreamResponse/StreamResponses.
DoStreamFunc func(ctx context.Context, options *stream.CallOptions) (<-chan stream.Event, error)
// StreamResponse is a single response to return for all Stream calls.
// Use StreamResponses for multiple sequential responses.
StreamResponse []stream.Event
// StreamResponses is a list of responses to return in sequence.
// Takes precedence over StreamResponse.
StreamResponses [][]stream.Event
}
MockLanguageModelOptions configures the mock language model.
type MockSpeechModel ¶
type MockSpeechModel struct {
DoGenerateFunc func(ctx context.Context, opts model.SpeechCallOptions) (*model.SpeechResult, error)
DoGenerateCalls []model.SpeechCallOptions
GenerateResponse *model.SpeechResult
// contains filtered or unexported fields
}
MockSpeechModel is a mock implementation of SpeechModel for testing.
func NewMockSpeechModel ¶
func NewMockSpeechModel(opts MockSpeechModelOptions) *MockSpeechModel
NewMockSpeechModel creates a new mock speech model.
func (*MockSpeechModel) Generate ¶
func (m *MockSpeechModel) Generate(ctx context.Context, opts model.SpeechCallOptions) (*model.SpeechResult, error)
func (*MockSpeechModel) ID ¶
func (m *MockSpeechModel) ID() string
func (*MockSpeechModel) Provider ¶
func (m *MockSpeechModel) Provider() string
type MockSpeechModelOptions ¶
type MockSpeechModelOptions struct {
ID string
Provider string
DoGenerateFunc func(ctx context.Context, opts model.SpeechCallOptions) (*model.SpeechResult, error)
GenerateResponse *model.SpeechResult
}
MockSpeechModelOptions configures the mock speech model.
type MockTranscriptionModel ¶
type MockTranscriptionModel struct {
DoTranscribeFunc func(ctx context.Context, opts model.TranscribeCallOptions) (*model.TranscriptionResult, error)
DoTranscribeCalls []model.TranscribeCallOptions
TranscribeResponse *model.TranscriptionResult
// contains filtered or unexported fields
}
MockTranscriptionModel is a mock implementation of TranscriptionModel for testing.
func NewMockTranscriptionModel ¶
func NewMockTranscriptionModel(opts MockTranscriptionModelOptions) *MockTranscriptionModel
NewMockTranscriptionModel creates a new mock transcription model.
func (*MockTranscriptionModel) ID ¶
func (m *MockTranscriptionModel) ID() string
func (*MockTranscriptionModel) Provider ¶
func (m *MockTranscriptionModel) Provider() string
func (*MockTranscriptionModel) Transcribe ¶
func (m *MockTranscriptionModel) Transcribe(ctx context.Context, opts model.TranscribeCallOptions) (*model.TranscriptionResult, error)
type MockTranscriptionModelOptions ¶
type MockTranscriptionModelOptions struct {
ID string
Provider string
DoTranscribeFunc func(ctx context.Context, opts model.TranscribeCallOptions) (*model.TranscriptionResult, error)
TranscribeResponse *model.TranscriptionResult
}
MockTranscriptionModelOptions configures the mock transcription model.