|
|
|
|
@@ -22,9 +22,16 @@ type campaign struct {
|
|
|
|
|
Model string `yaml:"model"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type storageConfiguration struct {
|
|
|
|
|
Driver string `yaml:"driver"`
|
|
|
|
|
Location string `yaml:"location"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type appConfiguration struct {
|
|
|
|
|
DefaultCampaign string `yaml:"default_campaign"`
|
|
|
|
|
Campaigns map[string]campaign `yaml:"campaigns"`
|
|
|
|
|
PromptKit promptkit.Settings `yaml:"promptkit"`
|
|
|
|
|
Storage storageConfiguration `yaml:"storage"`
|
|
|
|
|
DefaultCampaign string `yaml:"default_campaign"`
|
|
|
|
|
Campaigns map[string]campaign `yaml:"campaigns"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type inspectionInput struct {
|
|
|
|
|
@@ -95,26 +102,75 @@ func loadApplicationConfig(ctx context.Context, selection ckconfig.Selection, in
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
source := configkit.Mapping("composed application settings", map[string]any{
|
|
|
|
|
"default_campaign": "spring",
|
|
|
|
|
"campaigns": map[string]any{
|
|
|
|
|
"spring": map[string]any{"prompt_id": "briefing", "profile_id": "spring", "model": "spring-model"},
|
|
|
|
|
"autumn": map[string]any{"prompt_id": "briefing", "profile_id": "autumn", "model": "autumn-model"},
|
|
|
|
|
definition := configkit.Definition[appConfiguration]{
|
|
|
|
|
Defaults: func() appConfiguration {
|
|
|
|
|
return appConfiguration{DefaultCampaign: "spring", Storage: storageConfiguration{Driver: "local", Location: "./data"}, Campaigns: map[string]campaign{
|
|
|
|
|
"spring": {PromptID: "briefing", ProfileID: "spring", Model: "spring-model"},
|
|
|
|
|
"autumn": {PromptID: "briefing", ProfileID: "autumn", Model: "autumn-model"},
|
|
|
|
|
}}
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
Resolve: func(value *appConfiguration, resolution *configkit.Resolution) error {
|
|
|
|
|
name, chosen, err := selectedCampaign(*value, commandkit.Supplied[string]{})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
deps := []configkit.Path{configkit.Keys("default_campaign"), configkit.Keys("campaigns", name)}
|
|
|
|
|
profilePath := configkit.Keys("promptkit", "profiles")
|
|
|
|
|
profileFound := false
|
|
|
|
|
for _, profile := range value.PromptKit.Profiles {
|
|
|
|
|
if profile.ID == chosen.ProfileID {
|
|
|
|
|
profileFound = true
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if !profileFound {
|
|
|
|
|
value.PromptKit.Profiles = append(value.PromptKit.Profiles, promptkit.ProfileSettings{ID: chosen.ProfileID, Backend: new("local"), Endpoint: new("https://example.invalid/v1"), Model: new(chosen.Model), ExtraParams: map[string]any{"campaign": name}})
|
|
|
|
|
resolution.RecordNormalization(profilePath, "Selected campaign profile", deps...)
|
|
|
|
|
}
|
|
|
|
|
promptPath := configkit.Keys("promptkit", "prompts")
|
|
|
|
|
for index := range value.PromptKit.Prompts {
|
|
|
|
|
prompt := &value.PromptKit.Prompts[index]
|
|
|
|
|
if prompt.ID != "briefing" {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
if chosen.PromptID != prompt.ID {
|
|
|
|
|
prompt.ID = chosen.PromptID
|
|
|
|
|
resolution.RecordNormalization(promptPath.Index(index).Key("id"), "Selected campaign prompt", deps...)
|
|
|
|
|
}
|
|
|
|
|
if prompt.DefaultProfile == nil {
|
|
|
|
|
prompt.DefaultProfile = new(chosen.ProfileID)
|
|
|
|
|
resolution.RecordDerivedDefault(promptPath.Index(index).Key("default_profile"), "Selected campaign profile", deps...)
|
|
|
|
|
}
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
definition = promptkit.Configure(definition, func(value *appConfiguration) *promptkit.Settings { return &value.PromptKit })
|
|
|
|
|
resources := promptkit.SettingsInput(configkit.Mapping("example resources", map[string]any{
|
|
|
|
|
"collections": map[string]any{"field-notes": map[string]any{
|
|
|
|
|
"release_version": "1",
|
|
|
|
|
"backends": []any{map[string]any{"id": "demo", "endpoint": "https://example.invalid/v1"}},
|
|
|
|
|
"profiles": []any{map[string]any{"id": "assistant", "backend": "field-notes/demo", "model": "example-model"}},
|
|
|
|
|
"prompts": []any{map[string]any{"id": "briefing", "default_profile": "field-notes/assistant", "inputs": []any{map[string]any{"name": "topic", "required": true, "content_type": "text/plain", "description": "Topic to brief"}}, "messages": []any{map[string]any{"role": "user", "content": "Write a concise briefing about {{.topic}}."}}, "output": map[string]any{"format": "text", "validation_mode": "none"}}},
|
|
|
|
|
}},
|
|
|
|
|
"prompts": []any{map[string]any{"id": "briefing", "inputs": []any{map[string]any{"name": "topic", "required": true, "content_type": "text/plain", "description": "Topic to brief"}}, "messages": []any{map[string]any{"role": "user", "content": "Write a concise briefing about {{.topic}}. {{if .mode}}{{input \"notes\"}}{{end}}"}}, "output": map[string]any{"format": "text", "validation_mode": "none"}}},
|
|
|
|
|
"backends": []any{map[string]any{"id": "local", "endpoint": "https://example.invalid/v1"}},
|
|
|
|
|
}))
|
|
|
|
|
source := configkit.NoSource()
|
|
|
|
|
if selection.Config.Set {
|
|
|
|
|
source = configkit.File(selection.Config.Value)
|
|
|
|
|
}
|
|
|
|
|
options := configkit.Options[appConfiguration]{}
|
|
|
|
|
options := configkit.LayeredOptions[appConfiguration]{Definition: definition, Underlays: []configkit.Underlay{promptkit.BundledOpenRouterUnderlay(), {Inputs: []configkit.Input{resources}}}}
|
|
|
|
|
if selection.Overlay.Set {
|
|
|
|
|
options.Overlay = selection.Overlay.Value
|
|
|
|
|
options.Filesystem = &configkit.FilesystemContext{Root: ".", BaseDir: "."}
|
|
|
|
|
options.OverlayFilesystem = &configkit.FilesystemContext{Root: ".", BaseDir: "."}
|
|
|
|
|
}
|
|
|
|
|
if campaignInput.Set {
|
|
|
|
|
options.Overrides = []configkit.Override{{Path: configkit.Keys("default_campaign"), Value: campaignInput.Value, Flag: "--campaign"}}
|
|
|
|
|
}
|
|
|
|
|
options.Overrides = append(options.Overrides, selection.Overrides...)
|
|
|
|
|
result, err := configkit.Load(source, options)
|
|
|
|
|
result, err := configkit.LoadLayered(configkit.Input{Source: source}, options)
|
|
|
|
|
if err == nil && result != nil && cache != nil {
|
|
|
|
|
cache.applications = append(cache.applications, applicationCacheEntry{selection: selection, campaign: campaignInput, result: result})
|
|
|
|
|
}
|
|
|
|
|
@@ -126,48 +182,14 @@ func loadPromptEngine(ctx context.Context, selection ckconfig.Selection, input *
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
name, chosen, err := selectedCampaign(application.Config, input.Campaign)
|
|
|
|
|
if err != nil {
|
|
|
|
|
if _, _, err := selectedCampaign(application.Config, commandkit.Supplied[string]{}); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
engineConfig := configkit.Mapping("campaign "+name, map[string]any{
|
|
|
|
|
"collections": map[string]any{
|
|
|
|
|
"field-notes": map[string]any{
|
|
|
|
|
"release_version": "1",
|
|
|
|
|
"backends": []any{map[string]any{"id": "demo", "endpoint": "https://example.invalid/v1"}},
|
|
|
|
|
"profiles": []any{map[string]any{"id": "assistant", "backend": "field-notes/demo", "model": "example-model"}},
|
|
|
|
|
"prompts": []any{map[string]any{
|
|
|
|
|
"id": "briefing",
|
|
|
|
|
"default_profile": "field-notes/assistant",
|
|
|
|
|
"inputs": []any{map[string]any{"name": "topic", "required": true, "content_type": "text/plain", "description": "Topic to brief"}},
|
|
|
|
|
"messages": []any{map[string]any{"role": "user", "content": "Write a concise briefing about {{.topic}}."}},
|
|
|
|
|
"output": map[string]any{"format": "text", "validation_mode": "none"},
|
|
|
|
|
}},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
"backends": []any{map[string]any{"id": "local", "endpoint": "https://example.invalid/v1"}},
|
|
|
|
|
"profiles": []any{map[string]any{
|
|
|
|
|
"id": chosen.ProfileID,
|
|
|
|
|
"backend": "local",
|
|
|
|
|
"endpoint": "https://example.invalid/v1",
|
|
|
|
|
"model": chosen.Model,
|
|
|
|
|
"extra_params": map[string]any{
|
|
|
|
|
"campaign": name,
|
|
|
|
|
},
|
|
|
|
|
}},
|
|
|
|
|
"prompts": []any{map[string]any{
|
|
|
|
|
"id": chosen.PromptID,
|
|
|
|
|
"default_profile": chosen.ProfileID,
|
|
|
|
|
"inputs": []any{map[string]any{"name": "topic", "required": true, "content_type": "text/plain", "description": "Topic to brief"}},
|
|
|
|
|
"messages": []any{map[string]any{"role": "user", "content": "Write a concise briefing about {{.topic}}. {{if .mode}}{{input \"notes\"}}{{end}}"}},
|
|
|
|
|
"output": map[string]any{"format": "text", "validation_mode": "none"},
|
|
|
|
|
}},
|
|
|
|
|
})
|
|
|
|
|
var client promptkit.LLMClient = &exampleLLMClient{}
|
|
|
|
|
if cache != nil && cache.llmClient != nil {
|
|
|
|
|
client = cache.llmClient
|
|
|
|
|
}
|
|
|
|
|
return promptkit.NewEngine(promptkit.Config{Sources: promptkit.ConfigurationSources{Main: &configkit.Input{Source: engineConfig}}}, promptkit.WithLLMClient(client))
|
|
|
|
|
return promptkit.NewFromConfig(application, promptkit.RuntimeConfig{}, promptkit.WithLLMClient(client))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func selectedCampaign(configuration appConfiguration, supplied commandkit.Supplied[string]) (string, campaign, error) {
|
|
|
|
|
@@ -231,6 +253,8 @@ func newAppWithEngineLoader(
|
|
|
|
|
|
|
|
|
|
appScope := ckconfig.FromConfigKit("app", "Application settings.", loadApplicationConfig)
|
|
|
|
|
appScope.Features.Overrides = true
|
|
|
|
|
storageScope := ckconfig.FromConfigKitSubtree("storage", "Storage settings.", configkit.Keys("storage"), loadApplicationConfig)
|
|
|
|
|
storageScope.Features.Overrides = true
|
|
|
|
|
engineScope := ckprompt.ConfigScope(engineLoader)
|
|
|
|
|
configCommand := ckconfig.Command(ckconfig.Suite[*inspectionInput, *runCache]{
|
|
|
|
|
NewInput: inputFactory,
|
|
|
|
|
@@ -242,10 +266,10 @@ func newAppWithEngineLoader(
|
|
|
|
|
return nil
|
|
|
|
|
},
|
|
|
|
|
Selectors: []ckconfig.Selector[*inspectionInput]{
|
|
|
|
|
{Binding: campaignSelector(), AgainstName: "against-campaign", Scopes: []string{"app", "promptkit"}},
|
|
|
|
|
{Binding: campaignSelector(), AgainstName: "against-campaign", Scopes: []string{"app", "storage", "promptkit"}},
|
|
|
|
|
{Binding: limitFlag, AgainstName: "against-limit", Scopes: []string{"app"}},
|
|
|
|
|
},
|
|
|
|
|
Scopes: []ckconfig.Scope[*inspectionInput, *runCache]{appScope, engineScope},
|
|
|
|
|
Scopes: []ckconfig.Scope[*inspectionInput, *runCache]{appScope, storageScope, engineScope},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
definitions := ckprompt.FromEngine(engineLoader)
|
|
|
|
|
|