Refactor: split prompt definition from execution settings and migrate run contracts to prompt_* + execution_target
This commit is contained in:
@@ -13,9 +13,9 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
ErrProfileNotFound = errors.New("prompt profile not found")
|
||||
ErrProfileNotFound = errors.New("prompt definition not found")
|
||||
ErrInvalidYAML = errors.New("invalid YAML format")
|
||||
ErrInvalidProfile = errors.New("invalid profile configuration")
|
||||
ErrInvalidProfile = errors.New("invalid prompt definition configuration")
|
||||
)
|
||||
|
||||
type filesystemRepository struct {
|
||||
@@ -26,9 +26,9 @@ func NewFilesystemRepository(dir string) Repository {
|
||||
return &filesystemRepository{dir: dir}
|
||||
}
|
||||
|
||||
func (r *filesystemRepository) GetProfile(ctx context.Context, id string, version string) (*domain.PromptProfile, error) {
|
||||
func (r *filesystemRepository) GetPromptDefinition(ctx context.Context, id string, version string) (*domain.PromptDefinition, error) {
|
||||
if strings.TrimSpace(id) == "" {
|
||||
return nil, fmt.Errorf("%w: profile id is required", ErrInvalidProfile)
|
||||
return nil, fmt.Errorf("%w: prompt id is required", ErrInvalidProfile)
|
||||
}
|
||||
|
||||
files, err := os.ReadDir(r.dir)
|
||||
@@ -53,7 +53,7 @@ func (r *filesystemRepository) GetProfile(ctx context.Context, id string, versio
|
||||
return nil, fmt.Errorf("failed to read profile file %s: %w", file.Name(), err)
|
||||
}
|
||||
|
||||
var prof domain.PromptProfile
|
||||
var prof domain.PromptDefinition
|
||||
decoder := yaml.NewDecoder(bytes.NewReader(data))
|
||||
decoder.KnownFields(true)
|
||||
if err := decoder.Decode(&prof); err != nil {
|
||||
@@ -77,22 +77,33 @@ func (r *filesystemRepository) GetProfile(ctx context.Context, id string, versio
|
||||
return nil, ErrProfileNotFound
|
||||
}
|
||||
|
||||
func validateProfile(p *domain.PromptProfile) error {
|
||||
func validateProfile(p *domain.PromptDefinition) error {
|
||||
if p.ID == "" {
|
||||
return errors.New("profile id is required")
|
||||
return errors.New("prompt id is required")
|
||||
}
|
||||
if p.Version == "" {
|
||||
return errors.New("profile version is required")
|
||||
return errors.New("prompt version is required")
|
||||
}
|
||||
if len(p.Templates) == 0 {
|
||||
return errors.New("at least one prompt template message is required")
|
||||
}
|
||||
if len(p.Inputs) == 0 {
|
||||
return errors.New("at least one prompt input is required")
|
||||
}
|
||||
for i, input := range p.Inputs {
|
||||
if strings.TrimSpace(input.Name) == "" {
|
||||
return fmt.Errorf("input %d has empty name", i)
|
||||
}
|
||||
}
|
||||
for i, t := range p.Templates {
|
||||
if !isValidMessageRole(t.Role) {
|
||||
return fmt.Errorf("template message %d has invalid role %q", i, t.Role)
|
||||
}
|
||||
if t.Content == "" {
|
||||
return fmt.Errorf("template message %d is missing content", i)
|
||||
if strings.TrimSpace(t.Content) == "" && strings.TrimSpace(t.ContentFile) == "" {
|
||||
return fmt.Errorf("template message %d must provide content or content_file", i)
|
||||
}
|
||||
if strings.TrimSpace(t.Content) != "" && strings.TrimSpace(t.ContentFile) != "" {
|
||||
return fmt.Errorf("template message %d cannot set both content and content_file", i)
|
||||
}
|
||||
}
|
||||
if !isValidOutputFormat(p.OutputFormat) {
|
||||
@@ -107,17 +118,9 @@ func validateProfile(p *domain.PromptProfile) error {
|
||||
if p.Validation.ValidationMode == domain.ValidationJSONSchema && strings.TrimSpace(p.Validation.SchemaPath) == "" {
|
||||
return errors.New("validation.schema_path is required when validation_mode is json_schema")
|
||||
}
|
||||
if p.ModelDefaults.TimeoutSeconds < 0 {
|
||||
return errors.New("model_defaults.timeout_seconds must be greater than or equal to 0")
|
||||
}
|
||||
if p.Validation.Format != "" && p.Validation.Format != p.OutputFormat {
|
||||
return fmt.Errorf("validation format %q does not match output format %q", p.Validation.Format, p.OutputFormat)
|
||||
}
|
||||
for i, input := range p.ExpectedInputs {
|
||||
if strings.TrimSpace(input) == "" {
|
||||
return fmt.Errorf("expected input %d has empty name", i)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user