From 56795bb49a82dc9cced69eb47ae4ce682f74d372 Mon Sep 17 00:00:00 2001 From: Eric Rakestraw Date: Sat, 21 Nov 2026 14:43:14 +0000 Subject: [PATCH] Update offline examples for shared configuration --- docs/roadmap/implementation.md | 2 ++ examples/go-library/observe/main.go | 13 ++++++++----- .../go-library/observe/prompts/assessment.yaml | 1 + .../go-library/observe/prompts/proposal.yaml | 1 + .../prepare/collections/support/collection.yaml | 1 - examples/go-library/prepare/main.go | 16 +++++++++++++--- examples/go-library/run/main.go | 6 +++--- 7 files changed, 28 insertions(+), 12 deletions(-) diff --git a/docs/roadmap/implementation.md b/docs/roadmap/implementation.md index 87c1235..dee718f 100644 --- a/docs/roadmap/implementation.md +++ b/docs/roadmap/implementation.md @@ -618,6 +618,8 @@ or independent comparison implementation. ## Stage 15 — Update The Three Maintained Offline Examples +Status: complete. All three maintained offline example test packages passed. + Focus: `examples/go-library/{prepare,run,observe}` and their tests/assets. 1. Update preparation to demonstrate an application-owned typed root, explicit diff --git a/examples/go-library/observe/main.go b/examples/go-library/observe/main.go index 2c7f50b..4963d31 100644 --- a/examples/go-library/observe/main.go +++ b/examples/go-library/observe/main.go @@ -90,19 +90,22 @@ func run() (summary, error) { if err != nil { return summary{}, err } + for i := range inputs { + inputs[i].Destination = configkit.Keys("promptkit") + } backendID, proposalModel, assessmentModel := "offline-backend", "proposal-model", "assessment-model" filesystem := configkit.NewFilesystem("example schemas", assets) backend := promptkit.LocalBackend("https://example.invalid/v1", 1) backend.ID = backendID inputs = append(inputs, - configkit.Input{Source: promptkit.SchemaRootSource("example schemas", "schemas"), Filesystem: &configkit.FilesystemContext{FS: &filesystem, Root: ".", BaseDir: "."}}, - configkit.Input{Source: promptkit.BackendSource("example backend", []promptkit.BackendConfig{ + configkit.Input{Source: promptkit.SchemaRootSource("example schemas", "schemas"), Destination: configkit.Keys("promptkit"), Filesystem: &configkit.FilesystemContext{FS: &filesystem, Root: ".", BaseDir: "."}}, + promptkit.SettingsInput(promptkit.BackendSource("example backend", []promptkit.BackendConfig{ backend, - })}, - configkit.Input{Source: promptkit.ProfileSource("example profiles", []promptkit.ProfileConfig{ + })), + promptkit.SettingsInput(promptkit.ProfileSource("example profiles", []promptkit.ProfileConfig{ {ID: "proposal-profile", Backend: &backendID, Model: &proposalModel}, {ID: "assessment-profile", Backend: &backendID, Model: &assessmentModel}, - })}, + })), ) engine, err := promptkit.NewEngine(promptkit.Config{ Sources: promptkit.ConfigurationSources{Underlays: []configkit.Underlay{{Inputs: inputs}}}, diff --git a/examples/go-library/observe/prompts/assessment.yaml b/examples/go-library/observe/prompts/assessment.yaml index 9ba40e5..7f1d82d 100644 --- a/examples/go-library/observe/prompts/assessment.yaml +++ b/examples/go-library/observe/prompts/assessment.yaml @@ -14,6 +14,7 @@ prompts: output: format: json validation_mode: json_schema + repair_attempts: 0 schema: $schema: https://json-schema.org/draft/2020-12/schema type: object diff --git a/examples/go-library/observe/prompts/proposal.yaml b/examples/go-library/observe/prompts/proposal.yaml index 2c686bf..96563e9 100644 --- a/examples/go-library/observe/prompts/proposal.yaml +++ b/examples/go-library/observe/prompts/proposal.yaml @@ -14,4 +14,5 @@ prompts: output: format: json validation_mode: json_schema + repair_attempts: 0 schema_path: proposal.schema.json diff --git a/examples/go-library/prepare/collections/support/collection.yaml b/examples/go-library/prepare/collections/support/collection.yaml index 34b6b2c..8be1325 100644 --- a/examples/go-library/prepare/collections/support/collection.yaml +++ b/examples/go-library/prepare/collections/support/collection.yaml @@ -1,4 +1,3 @@ -version: "2" config: imports: - path: fragments/resources.yaml diff --git a/examples/go-library/prepare/main.go b/examples/go-library/prepare/main.go index 0e84afa..3cbf7cf 100644 --- a/examples/go-library/prepare/main.go +++ b/examples/go-library/prepare/main.go @@ -30,6 +30,10 @@ type collectionSummary struct { ReleaseVersion *string `json:"release_version"` } +type applicationSettings struct { + PromptKit promptkit.Settings `yaml:"promptkit"` +} + func main() { if err := run(context.Background(), "examples/go-library/prepare", os.Stdout); err != nil { fmt.Fprintln(os.Stderr, err) @@ -59,12 +63,18 @@ func run(ctx context.Context, exampleDir string, out io.Writer) error { if err != nil { return err } - engine, err := promptkit.NewEngine(promptkit.Config{Sources: promptkit.ConfigurationSources{ + definition := promptkit.Configure(configkit.Definition[applicationSettings]{}, func(value *applicationSettings) *promptkit.Settings { return &value.PromptKit }) + result, err := configkit.LoadLayered(configkit.Input{Source: configkit.NoSource()}, configkit.LayeredOptions[applicationSettings]{ + Definition: definition, Underlays: []configkit.Underlay{ {Inputs: []configkit.Input{support, review}}, {Inputs: []configkit.Input{override}}, }, - }}, promptkit.WithBundledOpenRouter(false)) // Keep this example's inventory caller-owned. + }) + if err != nil { + return err + } + engine, err := promptkit.NewFromConfig(result, promptkit.RuntimeConfig{}) if err != nil { return err } @@ -78,7 +88,7 @@ func run(ctx context.Context, exampleDir string, out io.Writer) error { if err != nil { return err } - if _, found := view.Explain(configkit.Keys("collections", "support", "profiles").Index(1).Key("timeout_seconds")); !found { + if _, found := view.Explain(configkit.Keys("promptkit", "collections", "support", "profiles").Index(1).Key("timeout_seconds")); !found { return fmt.Errorf("collection profile override was not found") } requirements, err := scoped.InspectRequirements(ctx, promptkit.RequirementInspectionRequest{ diff --git a/examples/go-library/run/main.go b/examples/go-library/run/main.go index c8dfaf9..0220208 100644 --- a/examples/go-library/run/main.go +++ b/examples/go-library/run/main.go @@ -50,10 +50,10 @@ func main() { func run(ctx context.Context, exampleDir string, out io.Writer) error { endpoint, model := "https://example.invalid/v1", "offline-model" engine, err := promptkit.NewEngine(promptkit.Config{Sources: promptkit.ConfigurationSources{ - Underlays: []configkit.Underlay{{Inputs: []configkit.Input{{Source: promptkit.ProfileSource("example profile", []promptkit.ProfileConfig{ + Underlays: []configkit.Underlay{{Inputs: []configkit.Input{promptkit.SettingsInput(promptkit.ProfileSource("example profile", []promptkit.ProfileConfig{ {ID: "offline-example", Endpoint: &endpoint, Model: &model}, - })}}}}, - Main: &configkit.Input{Source: configkit.File(filepath.Join(exampleDir, "prompt.yaml"))}, + }))}}}, + Main: &configkit.Input{Source: configkit.File(filepath.Join(exampleDir, "prompt.yaml")), Destination: configkit.Keys("promptkit")}, }}, promptkit.WithBundledOpenRouter(false), promptkit.WithLLMClient(deterministicClient{})) // Use only this example's offline configuration. if err != nil { return err