Use explicit IDs in configuration source builders
This commit is contained in:
20
profiles.go
20
profiles.go
@@ -2,12 +2,15 @@ package promptkit
|
||||
|
||||
import "go.maximumdirect.net/configkit"
|
||||
|
||||
// ProfileConfig is a presence-aware convenience value for a keyed execution
|
||||
// ProfileConfig is a presence-aware convenience value for an identified execution
|
||||
// profile. Nil fields are omitted; non-nil pointers preserve zero and blank
|
||||
// values. A nil ExtraParams map is omitted; a non-nil empty map supplies an
|
||||
// empty mapping, not a clear operation. Raw ConfigKit Mapping inputs can
|
||||
// express explicit null. ProfileConfig has no stable JSON representation.
|
||||
// Extends, when supplied, names a sibling profile in the same resource list.
|
||||
type ProfileConfig struct {
|
||||
// ID is the local profile identity within its resource list.
|
||||
ID string
|
||||
Extends, Backend, Endpoint, Model *string
|
||||
Temperature, TopP *float64
|
||||
MaxTokens, TimeoutSeconds *int
|
||||
@@ -17,17 +20,18 @@ type ProfileConfig struct {
|
||||
ExtraParams map[string]any
|
||||
}
|
||||
|
||||
// ProfileSource creates a labeled ConfigKit mapping from keyed profile values.
|
||||
// ProfileSource creates a labeled ConfigKit mapping containing profile records
|
||||
// in caller order. IDs are explicit and duplicates are left for loading to reject.
|
||||
// It encodes fields without validating them; NewEngine validates the final
|
||||
// effective configuration after all selected source layers are combined.
|
||||
// Mapping captures a copy of supported input values at creation; unsupported
|
||||
// values fail when the source is loaded.
|
||||
func ProfileSource(label string, profiles map[string]ProfileConfig) configkit.Source {
|
||||
definitions := make(map[string]any, len(profiles))
|
||||
for id, config := range profiles {
|
||||
fields := make(map[string]any)
|
||||
func ProfileSource(label string, profiles []ProfileConfig) configkit.Source {
|
||||
definitions := make([]any, 0, len(profiles))
|
||||
for _, config := range profiles {
|
||||
fields := map[string]any{"id": config.ID}
|
||||
if config.Extends != nil {
|
||||
fields["extends"] = *config.Extends
|
||||
fields["extends"] = map[string]any{"id": *config.Extends}
|
||||
}
|
||||
if config.Backend != nil {
|
||||
fields["backend"] = *config.Backend
|
||||
@@ -65,7 +69,7 @@ func ProfileSource(label string, profiles map[string]ProfileConfig) configkit.So
|
||||
if config.ExtraParams != nil {
|
||||
fields["extra_params"] = providerMapForMapping(config.ExtraParams)
|
||||
}
|
||||
definitions[id] = fields
|
||||
definitions = append(definitions, fields)
|
||||
}
|
||||
return configkit.Mapping(label, map[string]any{"profiles": definitions})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user