Update offline examples for shared configuration
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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}}},
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -14,4 +14,5 @@ prompts:
|
||||
output:
|
||||
format: json
|
||||
validation_mode: json_schema
|
||||
repair_attempts: 0
|
||||
schema_path: proposal.schema.json
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
version: "2"
|
||||
config:
|
||||
imports:
|
||||
- path: fragments/resources.yaml
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user