Documentation
¶
Overview ¶
Package config contains the data models representing the structure of configuration and task definition files for the MindTrial application. It provides configuration management and handles loading and validation of application settings, provider configurations, and task definitions from YAML files.
Index ¶
- Constants
- Variables
- func CleanIfNotBlank(filePath string) string
- func IsNotBlank(value string) bool
- func MakeAbs(baseDirPath string, filePath string) string
- func OnceWithContext[T any](f func(context.Context) (T, error)) func(context.Context) (T, error)
- func ResolveFileNamePattern(pattern string, timeRef time.Time) string
- func ResolveFlagOverride(override *bool, parentValue bool) bool
- type AnthropicClientConfig
- type AnthropicModelParams
- type AppConfig
- type ClientConfig
- type Config
- type DeepseekClientConfig
- type DeepseekModelParams
- type GoogleAIClientConfig
- type GoogleAIModelParams
- type ModelParams
- type OpenAIClientConfig
- type OpenAIModelParams
- type ProviderConfig
- type RunConfig
- type Task
- type TaskConfig
- type TaskFile
- func (f *TaskFile) Base64(ctx context.Context) (string, error)
- func (f *TaskFile) Content(ctx context.Context) ([]byte, error)
- func (f *TaskFile) GetDataURL(ctx context.Context) (string, error)
- func (f *TaskFile) SetBasePath(basePath string)
- func (f *TaskFile) TypeValue(ctx context.Context) (string, error)
- func (f *TaskFile) UnmarshalYAML(value *yaml.Node) error
- func (f *TaskFile) Validate() error
- type Tasks
- type URI
- func (u URI) IsLocalFile() bool
- func (u URI) IsRemoteFile() bool
- func (u URI) MarshalYAML() (interface{}, error)
- func (u *URI) Parse(raw string) (err error)
- func (u URI) Path(basePath string) string
- func (u URI) String() string
- func (u URI) URL() *url.URL
- func (u *URI) UnmarshalYAML(value *yaml.Node) error
Constants ¶
const ( // OPENAI identifies the OpenAI provider. OPENAI string = "openai" // GOOGLE identifies the Google AI provider. GOOGLE string = "google" // ANTHROPIC identifies the Anthropic provider. ANTHROPIC string = "anthropic" // DEEPSEEK identifies the Deepseek provider. DEEPSEEK string = "deepseek" )
Variables ¶
var ( // ErrInvalidTaskProperty indicates invalid task definition. ErrInvalidTaskProperty = errors.New("invalid task property") // ErrInvalidURI indicates that the specified URI is invalid or not supported. ErrInvalidURI = errors.New("invalid URI") // ErrDownloadFile indicates that a remote file could not be downloaded. ErrDownloadFile = errors.New("failed to download remote file") // ErrAccessFile indicates that a local file could not be accessed. ErrAccessFile = errors.New("file is not accessible") )
var ErrInvalidConfigProperty = errors.New("invalid configuration property")
ErrInvalidConfigProperty indicates invalid configuration.
Functions ¶
func CleanIfNotBlank ¶
CleanIfNotBlank cleans the given file path if it's not blank. Returns original path if it's blank.
func IsNotBlank ¶
IsNotBlank returns true if the given string contains non-whitespace characters.
func MakeAbs ¶
MakeAbs converts relative file path to absolute using the given base directory. Returns original path if it's already absolute or blank.
func OnceWithContext ¶
OnceWithContext returns a function that invokes f only once regardless of the supplied context. The first call's context is used for execution, and subsequent calls simply return the cached result. This is similar to sync.OnceValues but specifically for functions that need a context.
func ResolveFileNamePattern ¶
ResolveFileNamePattern takes a filename pattern containing time placeholders and returns a string with the placeholders replaced by values from the given time reference. Supported placeholders: {{.Year}}, {{.Month}}, {{.Day}}, {{.Hour}}, {{.Minute}}, {{.Second}}. Returns the original pattern if it cannot be resolved.
func ResolveFlagOverride ¶
ResolveFlagOverride returns override value if not nil, otherwise returns parent value.
Types ¶
type AnthropicClientConfig ¶
type AnthropicClientConfig struct {
// APIKey is the API key for the Anthropic generative models provider.
APIKey string `yaml:"api-key" validate:"required"`
// RequestTimeout specifies the timeout for API requests.
RequestTimeout *time.Duration `yaml:"request-timeout" validate:"omitempty"`
}
AnthropicClientConfig represents Anthropic provider settings.
type AnthropicModelParams ¶
type AnthropicModelParams struct {
// MaxTokens controls the maximum number of tokens available to the model for generating a response.
// This includes the thinking budget for reasoning models.
MaxTokens *int64 `yaml:"max-tokens" validate:"omitempty,min=0"`
// ThinkingBudgetTokens specifies the number of tokens the model can use for its internal reasoning process.
// It must be at least 1024 and less than `MaxTokens`.
// If set, this enables enhanced reasoning capabilities for the model.
ThinkingBudgetTokens *int64 `yaml:"thinking-budget-tokens" validate:"omitempty,min=1024,ltfield=MaxTokens"`
// Temperature controls the randomness or "creativity" of responses.
// Values range from 0.0 to 1.0, with lower values making the output more focused.
// The default value is 1.0.
// It is generally recommended to alter this or `TopP` but not both.
Temperature *float64 `yaml:"temperature" validate:"omitempty,min=0,max=1"`
// TopP controls diversity via nucleus sampling.
// Values range from 0.0 to 1.0, with lower values making the output more focused.
// You usually only need to use `Temperature`.
TopP *float64 `yaml:"top-p" validate:"omitempty,min=0,max=1"`
// TopK limits response tokens to top K options for each token position.
// Higher values allow more diverse outputs by considering more token options.
// You usually only need to use `Temperature`.
TopK *int64 `yaml:"top-k" validate:"omitempty,min=0"`
}
AnthropicModelParams represents Anthropic model-specific settings.
type AppConfig ¶
type AppConfig struct {
// LogFile specifies path to the log file.
LogFile string `yaml:"log-file" validate:"omitempty,filepath"`
// OutputDir specifies directory where results will be saved.
OutputDir string `yaml:"output-dir" validate:"required"`
// OutputBaseName specifies base filename for result files.
OutputBaseName string `yaml:"output-basename" validate:"omitempty,filepath"`
// TaskSource specifies path to the task definitions file.
TaskSource string `yaml:"task-source" validate:"required,filepath"`
// Providers lists configurations for AI providers whose models will be used
// to execute tasks during the trial run.
Providers []ProviderConfig `yaml:"providers" validate:"required,dive"`
}
AppConfig defines application-wide settings.
func (AppConfig) GetProvidersWithEnabledRuns ¶
func (ac AppConfig) GetProvidersWithEnabledRuns() []ProviderConfig
GetProvidersWithEnabledRuns returns providers with their enabled run configurations. If RunConfig.Disabled is nil, the parent ProviderConfig.Disabled value is used instead. Any disabled run configurations are excluded from the results. Providers with no enabled run configurations are excluded from the returned list.
type ClientConfig ¶
type ClientConfig interface{}
ClientConfig is a marker interface for provider-specific configurations.
type Config ¶
type Config struct {
// Config contains application-wide settings.
Config AppConfig `yaml:"config" validate:"required"`
}
Config represents the top-level configuration structure.
type DeepseekClientConfig ¶
type DeepseekClientConfig struct {
// APIKey is the API key for the Deepseek generative models provider.
APIKey string `yaml:"api-key" validate:"required"`
// RequestTimeout specifies the timeout for API requests.
RequestTimeout *time.Duration `yaml:"request-timeout" validate:"omitempty"`
}
DeepseekClientConfig represents Deepseek provider settings.
type DeepseekModelParams ¶
type DeepseekModelParams struct {
// Temperature controls the randomness or "creativity" of the model's outputs.
// Values range from 0.0 to 2.0, with lower values making the output more focused.
// The default value is 1.0.
// Recommended values by use case:
// - 0.0: Coding / Math (best for precise, deterministic outputs)
// - 1.0: Data Cleaning / Data Analysis
// - 1.3: General Conversation / Translation
// - 1.5: Creative Writing / Poetry (more varied and creative outputs)
Temperature *float32 `yaml:"temperature" validate:"omitempty,min=0,max=2"`
// TopP controls diversity via nucleus sampling.
// Values range from 0.0 to 1.0, with lower values making the output more focused.
// You usually only need to use `Temperature`.
TopP *float32 `yaml:"top-p" validate:"omitempty,min=0,max=1"`
// PresencePenalty penalizes new tokens based on whether they appear in the text so far.
// Values range from -2.0 to 2.0, with positive values encouraging the model to use new tokens,
// increasing the model's likelihood to talk about new topics.
// The default value is 0.0.
PresencePenalty *float32 `yaml:"presence-penalty" validate:"omitempty,min=-2,max=2"`
// FrequencyPenalty penalizes new tokens based on their frequency in the text so far.
// Values range from -2.0 to 2.0, with positive values encouraging the model to use less frequent tokens,
// decreasing the model's likelihood to repeat the same line verbatim.
// The default value is 0.0.
FrequencyPenalty *float32 `yaml:"frequency-penalty" validate:"omitempty,min=-2,max=2"`
}
DeepseekModelParams represents Deepseek model-specific settings.
type GoogleAIClientConfig ¶
type GoogleAIClientConfig struct {
// APIKey is the API key for the Google AI generative models provider.
APIKey string `yaml:"api-key" validate:"required"`
}
GoogleAIClientConfig represents Google AI provider settings.
type GoogleAIModelParams ¶
type GoogleAIModelParams struct {
// TextResponseFormat indicates whether to use plain-text response format
// for compatibility with models that do not support JSON.
TextResponseFormat bool `yaml:"text-response-format" validate:"omitempty"`
// Temperature controls the randomness or "creativity" of the model's outputs.
// Values range from 0.0 to 2.0, with lower values making the output more focused and deterministic.
// The default value is typically around 1.0.
Temperature *float32 `yaml:"temperature" validate:"omitempty,min=0,max=2"`
// TopP controls diversity via nucleus sampling.
// Values range from 0.0 to 1.0, with lower values making the output more focused.
// The default value is typically around 1.0.
TopP *float32 `yaml:"top-p" validate:"omitempty,min=0,max=1"`
// TopK limits response tokens to top K options for each token position.
// Higher values allow more diverse outputs by considering more token options.
TopK *int32 `yaml:"top-k" validate:"omitempty,min=0"`
}
GoogleAIModelParams represents Google AI model-specific settings.
type ModelParams ¶
type ModelParams interface{}
ModelParams is a marker interface for model-specific parameters.
type OpenAIClientConfig ¶
type OpenAIClientConfig struct {
// APIKey is the API key for the OpenAI provider.
APIKey string `yaml:"api-key" validate:"required"`
}
OpenAIClientConfig represents OpenAI provider settings.
type OpenAIModelParams ¶
type OpenAIModelParams struct {
// ReasoningEffort controls effort level on reasoning for reasoning models.
// Valid values are: "low", "medium", "high".
ReasoningEffort *string `yaml:"reasoning-effort" validate:"omitempty,oneof=low medium high"`
// TextResponseFormat indicates whether to use plain-text response format
// for compatibility with models that do not support JSON.
TextResponseFormat bool `yaml:"text-response-format" validate:"omitempty"`
// Temperature controls the randomness or "creativity" of the model's outputs.
// Values range from 0.0 to 2.0, with lower values making the output more focused and deterministic.
// The default value is 1.0.
// It is generally recommended to alter this or `TopP` but not both.
Temperature *float32 `yaml:"temperature" validate:"omitempty,min=0,max=2"`
// TopP controls diversity via nucleus sampling.
// Values range from 0.0 to 1.0, with lower values making the output more focused.
// The default value is 1.0.
// It is generally recommended to alter this or `Temperature` but not both.
TopP *float32 `yaml:"top-p" validate:"omitempty,min=0,max=1"`
// PresencePenalty penalizes new tokens based on whether they appear in the text so far.
// Values range from -2.0 to 2.0, with positive values encouraging the model to use new tokens,
// increasing the model's likelihood to talk about new topics.
// The default value is 0.0.
PresencePenalty *float32 `yaml:"presence-penalty" validate:"omitempty,min=-2,max=2"`
// FrequencyPenalty penalizes new tokens based on their frequency in the text so far.
// Values range from -2.0 to 2.0, with positive values encouraging the model to use less frequent tokens,
// decreasing the model's likelihood to repeat the same line verbatim.
// The default value is 0.0.
FrequencyPenalty *float32 `yaml:"frequency-penalty" validate:"omitempty,min=-2,max=2"`
}
OpenAIModelParams represents OpenAI model-specific settings.
type ProviderConfig ¶
type ProviderConfig struct {
// Name specifies unique identifier of the provider.
Name string `yaml:"name" validate:"required,oneof=openai google anthropic deepseek"`
// ClientConfig holds provider-specific client settings.
ClientConfig ClientConfig `yaml:"client-config" validate:"required"`
// Runs lists test run configurations for this provider.
Runs []RunConfig `yaml:"runs" validate:"required,dive"`
// Disabled indicates if all runs should be disabled by default.
Disabled bool `yaml:"disabled" validate:"omitempty"`
}
ProviderConfig defines settings for an AI provider.
func (*ProviderConfig) UnmarshalYAML ¶
func (pc *ProviderConfig) UnmarshalYAML(value *yaml.Node) error
UnmarshalYAML implements custom YAML unmarshaling for ProviderConfig. It handles provider-specific client configuration based on provider name.
type RunConfig ¶
type RunConfig struct {
// Name is a display-friendly identifier shown in results.
Name string `yaml:"name" validate:"required"`
// Model specifies target model's identifier.
Model string `yaml:"model" validate:"required"`
// MaxRequestsPerMinute limits the number of API requests per minute sent to this specific model.
// Value of 0 means no rate limiting will be applied.
MaxRequestsPerMinute int `yaml:"max-requests-per-minute" validate:"omitempty,numeric,min=0"`
// Disabled indicates if this run configuration should be skipped.
// If set, overrides the parent ProviderConfig.Disabled value.
Disabled *bool `yaml:"disabled" validate:"omitempty"`
// ModelParams holds any model-specific configuration parameters.
ModelParams ModelParams `yaml:"model-parameters" validate:"omitempty"`
}
RunConfig defines settings for a single test configuration.
type Task ¶
type Task struct {
// Name is a display-friendly identifier shown in results.
Name string `yaml:"name" validate:"required"`
// Prompt that will be sent to the AI model.
Prompt string `yaml:"prompt" validate:"required"`
// ResponseResultFormat specifies how the AI should format the final answer to the prompt.
ResponseResultFormat string `yaml:"response-result-format" validate:"required"`
// ExpectedResult is the set of accepted valid answers for the prompt.
// All values must follow the ResponseResultFormat precisely.
// Only one needs to match for the response to be considered correct.
ExpectedResult utils.StringSet `yaml:"expected-result" validate:"required"`
// Disabled indicates whether this specific task should be skipped.
// If set, overrides the global TaskConfig.Disabled value.
Disabled *bool `yaml:"disabled" validate:"omitempty"`
// Files is a list of files to be included with the prompt.
// This is primarily used for images but can support other file types
// depending on the provider's capabilities.
Files []TaskFile `yaml:"files" validate:"omitempty,unique=Name,dive"`
}
Task defines a single test case to be executed by AI models.
func (*Task) SetBaseFilePath ¶
SetBaseFilePath sets the base path for all local files in the task. The resolved paths are validated to ensure they are accessible.
type TaskConfig ¶
type TaskConfig struct {
// Tasks is a list of tasks to be executed.
Tasks []Task `yaml:"tasks" validate:"required,dive"`
// Disabled indicates whether all tasks should be disabled by default.
// Individual tasks can override this setting.
Disabled bool `yaml:"disabled" validate:"omitempty"`
}
TaskConfig represents task definitions and global settings.
func (TaskConfig) GetEnabledTasks ¶
func (o TaskConfig) GetEnabledTasks() []Task
GetEnabledTasks returns a filtered list of tasks that are not disabled. If Task.Disabled is nil, the global TaskConfig.Disabled value is used instead.
type TaskFile ¶
type TaskFile struct {
// Name is a unique identifier for the file, used to reference it in prompts.
Name string `yaml:"name" validate:"required"`
// URI is the path or URL to the file.
URI URI `yaml:"uri" validate:"required"`
// Type is the MIME type of the file.
// If not provided, it will be inferred from the file extension or content.
Type string `yaml:"type" validate:"omitempty"`
// contains filtered or unexported fields
}
TaskFile represents a file to be included with a task.
func (*TaskFile) GetDataURL ¶
GetDataURL returns a complete data URL for the file (e.g., "data:image/png;base64,...").
func (*TaskFile) SetBasePath ¶
SetBasePath sets the base path used to resolve relative local paths.
func (*TaskFile) TypeValue ¶
TypeValue returns the MIME type, inferring it if not set, loading content if needed.
func (*TaskFile) UnmarshalYAML ¶
UnmarshalYAML implements custom YAML unmarshaling for TaskFile.
type Tasks ¶
type Tasks struct {
// TaskConfig contains all task definitions and settings.
TaskConfig TaskConfig `yaml:"task-config" validate:"required"`
}
Tasks represents the top-level task configuration structure.
type URI ¶
type URI struct {
// contains filtered or unexported fields
}
URI represents a parsed URI/URL that can be used to reference a file.
func (URI) IsLocalFile ¶
IsLocalFile checks if the URI references a local file.
func (URI) IsRemoteFile ¶
IsRemoteFile checks if the URI references a remote file.
func (URI) MarshalYAML ¶
MarshalYAML implements custom YAML marshaling for URI.
func (*URI) Parse ¶
Parse parses a raw URI string into a structured URI object. It validates that the URI scheme is supported.