Upgrade PromptKit and assemble native configuration sources
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
configkit "gitea.maximumdirect.net/eric/ConfigKit"
|
||||
"gitea.maximumdirect.net/eric/promptkit"
|
||||
)
|
||||
|
||||
@@ -121,13 +122,13 @@ func (i *PromptKitProfileInspector) InspectProfile(ctx context.Context, profileI
|
||||
}, nil
|
||||
}
|
||||
|
||||
func promptKitProfileSourceEngineOptions(cfg PromptKitProfileSourceConfig) (PromptKitProfileSourceConfig, []promptkit.Option, error) {
|
||||
func promptKitProfileConfigurationSources(cfg PromptKitProfileSourceConfig) (PromptKitProfileSourceConfig, promptkit.ConfigurationSources, error) {
|
||||
source := PromptKitProfileSourceConfig{
|
||||
ProfileDir: strings.TrimSpace(cfg.ProfileDir),
|
||||
ProfileFile: strings.TrimSpace(cfg.ProfileFile),
|
||||
}
|
||||
if source.ProfileDir != "" && source.ProfileFile != "" {
|
||||
return PromptKitProfileSourceConfig{}, nil, fmt.Errorf("PromptKit profile_dir and profile_file are mutually exclusive")
|
||||
return PromptKitProfileSourceConfig{}, promptkit.ConfigurationSources{}, fmt.Errorf("PromptKit profile_dir and profile_file are mutually exclusive")
|
||||
}
|
||||
if cfg.LocalBackend != nil {
|
||||
localBackend := *cfg.LocalBackend
|
||||
@@ -135,12 +136,31 @@ func promptKitProfileSourceEngineOptions(cfg PromptKitProfileSourceConfig) (Prom
|
||||
source.LocalBackend = &localBackend
|
||||
}
|
||||
|
||||
var options []promptkit.Option
|
||||
var underlays []configkit.Underlay
|
||||
if source.ProfileFile != "" {
|
||||
options = append(options, promptkit.WithProfileFile(source.ProfileFile))
|
||||
underlays = append(underlays, configkit.Underlay{Inputs: []configkit.Input{{
|
||||
Source: configkit.File(source.ProfileFile),
|
||||
Imports: true,
|
||||
}}})
|
||||
} else if source.ProfileDir != "" {
|
||||
inputs, err := promptkit.DirectoryInputs(source.ProfileDir)
|
||||
if err != nil {
|
||||
return PromptKitProfileSourceConfig{}, promptkit.ConfigurationSources{}, fmt.Errorf("select PromptKit profile directory: %w", err)
|
||||
}
|
||||
for index := range inputs {
|
||||
inputs[index].Imports = true
|
||||
}
|
||||
if len(inputs) != 0 {
|
||||
underlays = append(underlays, configkit.Underlay{Inputs: inputs})
|
||||
}
|
||||
}
|
||||
if source.LocalBackend != nil {
|
||||
options = append(options, PromptKitLocalBackendOption(*source.LocalBackend))
|
||||
backend := promptkit.LocalBackend(source.LocalBackend.Endpoint, source.LocalBackend.ConcurrencyLimit)
|
||||
underlays = append(underlays, configkit.Underlay{Inputs: []configkit.Input{{
|
||||
Source: promptkit.BackendSource("notarius-local-backend", map[string]promptkit.BackendConfig{
|
||||
promptkit.BackendLocal: backend,
|
||||
}),
|
||||
}}})
|
||||
}
|
||||
return source, options, nil
|
||||
return source, promptkit.ConfigurationSources{Underlays: underlays}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user