Cut over public engine construction to ConfigKit sources
This commit is contained in:
121
profiles.go
121
profiles.go
@@ -1,64 +1,71 @@
|
||||
package promptkit
|
||||
|
||||
import (
|
||||
"gitea.maximumdirect.net/eric/promptkit/internal/domain"
|
||||
)
|
||||
import "gitea.maximumdirect.net/eric/ConfigKit"
|
||||
|
||||
// OpenAICompatibleProfile returns an in-memory Profile for an OpenAI-compatible
|
||||
// chat-completions endpoint. A non-blank BaseProfileID permits its target
|
||||
// fields to be inherited when the profile is selected or inspected.
|
||||
//
|
||||
// It does not register global state, maintain a model catalog, or resolve
|
||||
// credentials. If APIKeyRequired is true, callers satisfy it with
|
||||
// RunRequest.APIKey or an explicit request ExecutionTargetOverride.APIKeyEnv.
|
||||
// Raw API keys do not belong in profiles.
|
||||
//
|
||||
// The function copies the ExtraParams map itself but does not recursively copy
|
||||
// nested values. Validation and a deep copy occur when NewEngine applies a
|
||||
// WithProfiles option containing the returned Profile.
|
||||
func OpenAICompatibleProfile(cfg OpenAICompatibleProfileConfig) Profile {
|
||||
return Profile{
|
||||
ID: cfg.ID,
|
||||
BaseProfileID: cfg.BaseProfileID,
|
||||
BackendID: cfg.BackendID,
|
||||
Endpoint: cfg.Endpoint,
|
||||
Model: cfg.Model,
|
||||
Temperature: cfg.Temperature,
|
||||
MaxTokens: cfg.MaxTokens,
|
||||
TopP: cfg.TopP,
|
||||
TimeoutSeconds: cfg.TimeoutSeconds,
|
||||
ServiceTier: cfg.ServiceTier,
|
||||
ReasoningEffort: cfg.ReasoningEffort,
|
||||
APIKeyRequired: cfg.APIKeyRequired,
|
||||
ExtraParams: copyShallowAnyMap(cfg.ExtraParams),
|
||||
}
|
||||
// ProfileConfig is a presence-aware convenience value for a keyed 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.
|
||||
type ProfileConfig struct {
|
||||
Extends, Backend, Endpoint, Model *string
|
||||
Temperature, TopP *float64
|
||||
MaxTokens, TimeoutSeconds *int
|
||||
ServiceTier, ReasoningEffort *string
|
||||
APIKeyEnv *string
|
||||
APIKeyRequired *bool
|
||||
ExtraParams map[string]any
|
||||
}
|
||||
|
||||
func copyShallowAnyMap(src map[string]any) map[string]any {
|
||||
if src == nil {
|
||||
return nil
|
||||
}
|
||||
out := make(map[string]any, len(src))
|
||||
for k, v := range src {
|
||||
out[k] = v
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func toDomainProfile(publicProfile Profile) domain.ExecutionProfile {
|
||||
return domain.ExecutionProfile{
|
||||
ID: publicProfile.ID,
|
||||
BaseProfileID: publicProfile.BaseProfileID,
|
||||
BackendID: publicProfile.BackendID,
|
||||
Endpoint: publicProfile.Endpoint,
|
||||
Model: publicProfile.Model,
|
||||
Temperature: publicProfile.Temperature,
|
||||
MaxTokens: publicProfile.MaxTokens,
|
||||
TopP: publicProfile.TopP,
|
||||
TimeoutSeconds: publicProfile.TimeoutSeconds,
|
||||
ServiceTier: publicProfile.ServiceTier,
|
||||
ReasoningEffort: publicProfile.ReasoningEffort,
|
||||
APIKeyRequired: publicProfile.APIKeyRequired,
|
||||
ExtraParams: publicProfile.ExtraParams,
|
||||
// ProfileSource creates a labeled ConfigKit mapping from keyed profile values.
|
||||
// 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)
|
||||
if config.Extends != nil {
|
||||
fields["extends"] = *config.Extends
|
||||
}
|
||||
if config.Backend != nil {
|
||||
fields["backend"] = *config.Backend
|
||||
}
|
||||
if config.Endpoint != nil {
|
||||
fields["endpoint"] = *config.Endpoint
|
||||
}
|
||||
if config.Model != nil {
|
||||
fields["model"] = *config.Model
|
||||
}
|
||||
if config.Temperature != nil {
|
||||
fields["temperature"] = *config.Temperature
|
||||
}
|
||||
if config.TopP != nil {
|
||||
fields["top_p"] = *config.TopP
|
||||
}
|
||||
if config.MaxTokens != nil {
|
||||
fields["max_tokens"] = *config.MaxTokens
|
||||
}
|
||||
if config.TimeoutSeconds != nil {
|
||||
fields["timeout_seconds"] = *config.TimeoutSeconds
|
||||
}
|
||||
if config.ServiceTier != nil {
|
||||
fields["service_tier"] = *config.ServiceTier
|
||||
}
|
||||
if config.ReasoningEffort != nil {
|
||||
fields["reasoning_effort"] = *config.ReasoningEffort
|
||||
}
|
||||
if config.APIKeyEnv != nil {
|
||||
fields["api_key_env"] = *config.APIKeyEnv
|
||||
}
|
||||
if config.APIKeyRequired != nil {
|
||||
fields["api_key_required"] = *config.APIKeyRequired
|
||||
}
|
||||
if config.ExtraParams != nil {
|
||||
fields["extra_params"] = providerMapForMapping(config.ExtraParams)
|
||||
}
|
||||
definitions[id] = fields
|
||||
}
|
||||
return configkit.Mapping(label, map[string]any{"profiles": definitions})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user