Documentation
¶
Index ¶
- type MockConfigWatcher
- type MockLLM
- func (m *MockLLM) Debug(format string, args ...interface{})
- func (m *MockLLM) Generate(ctx context.Context, prompt *gollm.Prompt, opts ...llm.GenerateOption) (string, error)
- func (m *MockLLM) GenerateWithSchema(ctx context.Context, prompt *gollm.Prompt, schema interface{}, ...) (string, error)
- func (m *MockLLM) GetLogLevel() gollm.LogLevel
- func (m *MockLLM) GetLogger() utils.Logger
- func (m *MockLLM) GetModel() string
- func (m *MockLLM) GetPromptJSONSchema(opts ...gollm.SchemaOption) ([]byte, error)
- func (m *MockLLM) GetProvider() string
- func (m *MockLLM) NewPrompt(text string) *gollm.Prompt
- func (m *MockLLM) SetEndpoint(endpoint string)
- func (m *MockLLM) SetLogLevel(level gollm.LogLevel)
- func (m *MockLLM) SetOllamaEndpoint(endpoint string) error
- func (m *MockLLM) SetOption(key string, value interface{})
- func (m *MockLLM) SetSystemPrompt(prompt string, cacheType llm.CacheType)
- func (m *MockLLM) SupportsJSONSchema() bool
- func (m *MockLLM) UpdateLogLevel(level gollm.LogLevel)
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 ¶
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 ¶
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 ¶
GetLogLevel returns a default log level. Tests can rely on this consistent behavior.
func (*MockLLM) GetLogger ¶
GetLogger returns nil as we don't need logging in tests. Real implementation would return a logger instance.
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 ¶
GetProvider returns the mock provider name
func (*MockLLM) NewPrompt ¶
NewPrompt creates a simple prompt with user role. This provides consistent prompt creation for tests.
func (*MockLLM) SetEndpoint ¶
SetEndpoint is a no-op in the mock. Real implementation would configure the API endpoint.
func (*MockLLM) SetLogLevel ¶
SetLogLevel is a no-op in the mock. Real implementation would change logging behavior.
func (*MockLLM) SetOllamaEndpoint ¶
SetOllamaEndpoint is a no-op in the mock. Real implementation would configure Ollama endpoint.
func (*MockLLM) SetOption ¶
SetOption is a no-op in the mock. Real implementation would configure LLM options.
func (*MockLLM) SetSystemPrompt ¶
SetSystemPrompt is a no-op in the mock. Real implementation would set a system-level prompt.
func (*MockLLM) SupportsJSONSchema ¶
SupportsJSONSchema returns true to indicate schema support. This allows testing schema-related functionality.
func (*MockLLM) UpdateLogLevel ¶
UpdateLogLevel is a no-op in the mock. Real implementation would change logging behavior.