48 lines
1.3 KiB
Go
48 lines
1.3 KiB
Go
package profile
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
|
|
"gitea.maximumdirect.net/eric/promptkit/internal/domain"
|
|
)
|
|
|
|
// NormalizeAndValidateDefinition normalizes and validates one source-local
|
|
// profile definition without resolving a base profile.
|
|
func NormalizeAndValidateDefinition(profile *domain.ExecutionProfile) error {
|
|
if profile == nil {
|
|
return errors.New("profile is required")
|
|
}
|
|
|
|
profile.ID = strings.TrimSpace(profile.ID)
|
|
profile.BaseProfileID = strings.TrimSpace(profile.BaseProfileID)
|
|
profile.BackendID = strings.TrimSpace(profile.BackendID)
|
|
profile.Endpoint = strings.TrimSpace(profile.Endpoint)
|
|
|
|
if profile.ID == "" {
|
|
return errors.New("id is required")
|
|
}
|
|
if profile.Endpoint != "" {
|
|
endpoint, err := domain.NormalizeOpenAICompatibleBaseEndpoint(profile.Endpoint)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
profile.Endpoint = endpoint
|
|
}
|
|
if profile.BaseProfileID == "" {
|
|
if profile.BackendID == "" && profile.Endpoint == "" {
|
|
return errors.New("backend or endpoint is required")
|
|
}
|
|
if strings.TrimSpace(profile.Model) == "" {
|
|
return errors.New("model is required")
|
|
}
|
|
}
|
|
|
|
return domain.ValidateExecutionTargetSettings(domain.ExecutionTarget{
|
|
Temperature: profile.Temperature,
|
|
MaxTokens: profile.MaxTokens,
|
|
TopP: profile.TopP,
|
|
TimeoutSeconds: profile.TimeoutSeconds,
|
|
})
|
|
}
|