mocks

package
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MockConfigWatcher added in v0.0.16

type MockConfigWatcher struct {
	// contains filtered or unexported fields
}

MockConfigWatcher provides a testable implementation of config.Watcher

func NewMockConfigWatcher added in v0.0.16

func NewMockConfigWatcher(cfg *config.Config) *MockConfigWatcher

NewMockConfigWatcher creates a new MockConfigWatcher initialized with the provided config

func (*MockConfigWatcher) Close added in v0.0.16

func (m *MockConfigWatcher) Close() error

Close implements config.Watcher

func (*MockConfigWatcher) GetCurrentConfig added in v0.0.16

func (m *MockConfigWatcher) GetCurrentConfig() *config.Config

GetCurrentConfig implements config.Watcher

func (*MockConfigWatcher) Subscribe added in v0.0.16

func (m *MockConfigWatcher) Subscribe() <-chan *config.Config

Subscribe implements config.Watcher

func (*MockConfigWatcher) UpdateConfig added in v0.0.16

func (m *MockConfigWatcher) UpdateConfig(cfg *config.Config)

UpdateConfig is a test helper that simulates configuration changes

type MockLLM

type MockLLM struct {
	GenerateFunc func(context.Context, *gollm.Prompt) (string, error)
	DebugFunc    func(string, ...interface{})
	Provider     string // Provider name for testing
	Model        string // Model name for testing
}

MockLLM implements a mock LLM for testing purposes. It provides a flexible way to simulate LLM behavior in tests without making actual API calls.

Key features: 1. Configurable response generation through GenerateFunc 2. Debug logging capture through DebugFunc 3. Default implementations for all interface methods

Example usage:

mockLLM := NewMockLLM(func(ctx context.Context, prompt *gollm.Prompt) (string, error) {
    return "mocked response", nil
})

func NewMockLLM

func NewMockLLM(generateFunc func(context.Context, *gollm.Prompt) (string, error)) *MockLLM

NewMockLLM creates a new MockLLM with optional generate function. If generateFunc is nil, Generate will return empty string with no error.

func NewMockLLMWithConfig added in v0.0.8

func NewMockLLMWithConfig(provider, model string, generateFunc func(context.Context, *gollm.Prompt) (string, error)) *MockLLM

NewMockLLMWithConfig creates a new MockLLM with specific provider and model names

func (*MockLLM) Debug

func (m *MockLLM) Debug(format string, args ...interface{})

Debug captures debug messages if DebugFunc is provided. This allows tests to verify logging behavior if needed.

func (*MockLLM) Generate

func (m *MockLLM) Generate(ctx context.Context, prompt *gollm.Prompt, opts ...llm.GenerateOption) (string, error)

Generate implements the core LLM functionality. It uses the provided GenerateFunc if available, otherwise returns empty string. The opts parameter is ignored in the mock to simplify testing.

func (*MockLLM) GenerateWithSchema

func (m *MockLLM) GenerateWithSchema(ctx context.Context, prompt *gollm.Prompt, schema interface{}, opts ...llm.GenerateOption) (string, error)

GenerateWithSchema uses the standard Generate function. Schema validation is not performed in the mock.

func (*MockLLM) GetLogLevel

func (m *MockLLM) GetLogLevel() gollm.LogLevel

GetLogLevel returns a default log level. Tests can rely on this consistent behavior.

func (*MockLLM) GetLogger

func (m *MockLLM) GetLogger() utils.Logger

GetLogger returns nil as we don't need logging in tests. Real implementation would return a logger instance.

func (*MockLLM) GetModel

func (m *MockLLM) GetModel() string

GetModel returns the mock model name

func (*MockLLM) GetPromptJSONSchema

func (m *MockLLM) GetPromptJSONSchema(opts ...gollm.SchemaOption) ([]byte, error)

GetPromptJSONSchema returns a minimal valid JSON schema. This is useful for testing schema validation without complex schemas.

func (*MockLLM) GetProvider

func (m *MockLLM) GetProvider() string

GetProvider returns the mock provider name

func (*MockLLM) NewPrompt

func (m *MockLLM) NewPrompt(text string) *gollm.Prompt

NewPrompt creates a simple prompt with user role. This provides consistent prompt creation for tests.

func (*MockLLM) SetEndpoint

func (m *MockLLM) SetEndpoint(endpoint string)

SetEndpoint is a no-op in the mock. Real implementation would configure the API endpoint.

func (*MockLLM) SetLogLevel

func (m *MockLLM) SetLogLevel(level gollm.LogLevel)

SetLogLevel is a no-op in the mock. Real implementation would change logging behavior.

func (*MockLLM) SetOllamaEndpoint

func (m *MockLLM) SetOllamaEndpoint(endpoint string) error

SetOllamaEndpoint is a no-op in the mock. Real implementation would configure Ollama endpoint.

func (*MockLLM) SetOption

func (m *MockLLM) SetOption(key string, value interface{})

SetOption is a no-op in the mock. Real implementation would configure LLM options.

func (*MockLLM) SetSystemPrompt

func (m *MockLLM) SetSystemPrompt(prompt string, cacheType llm.CacheType)

SetSystemPrompt is a no-op in the mock. Real implementation would set a system-level prompt.

func (*MockLLM) SupportsJSONSchema

func (m *MockLLM) SupportsJSONSchema() bool

SupportsJSONSchema returns true to indicate schema support. This allows testing schema-related functionality.

func (*MockLLM) UpdateLogLevel

func (m *MockLLM) UpdateLogLevel(level gollm.LogLevel)

UpdateLogLevel is a no-op in the mock. Real implementation would change logging behavior.

Jump to

Keyboard shortcuts

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