Demonstrate PromptKit catalogs and smoke tests
This commit is contained in:
@@ -40,6 +40,18 @@ type applicationCacheKey struct {
|
||||
// chooses to pass it to its loaders.
|
||||
type runCache struct {
|
||||
applications map[applicationCacheKey]*configkit.Result[appConfiguration]
|
||||
llmClient promptkit.LLMClient
|
||||
}
|
||||
|
||||
type exampleLLMClient struct {
|
||||
calls *int
|
||||
}
|
||||
|
||||
func (client *exampleLLMClient) Generate(context.Context, promptkit.GenerateRequest) (*promptkit.GenerateResponse, error) {
|
||||
if client.calls != nil {
|
||||
(*client.calls)++
|
||||
}
|
||||
return &promptkit.GenerateResponse{Content: "Example response."}, nil
|
||||
}
|
||||
|
||||
type restoreInput struct {
|
||||
@@ -110,6 +122,20 @@ func loadPromptEngine(ctx context.Context, selection ckconfig.Selection, input *
|
||||
return nil, err
|
||||
}
|
||||
engineConfig := configkit.Mapping("campaign "+name, map[string]any{
|
||||
"collections": map[string]any{
|
||||
"field-notes": map[string]any{
|
||||
"release_version": "1",
|
||||
"backends": map[string]any{"demo": map[string]any{"endpoint": "https://example.invalid/v1"}},
|
||||
"profiles": map[string]any{"assistant": map[string]any{"backend": "field-notes/demo", "model": "example-model"}},
|
||||
"prompts": map[string]any{"briefing": map[string]any{
|
||||
"version": "1",
|
||||
"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"},
|
||||
}},
|
||||
},
|
||||
},
|
||||
"profiles": map[string]any{chosen.ProfileID: map[string]any{
|
||||
"endpoint": "https://example.invalid/v1",
|
||||
"model": chosen.Model,
|
||||
@@ -125,7 +151,11 @@ func loadPromptEngine(ctx context.Context, selection ckconfig.Selection, input *
|
||||
"output": map[string]any{"format": "text", "validation_mode": "none"},
|
||||
}},
|
||||
})
|
||||
return promptkit.NewEngine(promptkit.Config{Sources: promptkit.ConfigurationSources{Main: &configkit.Input{Source: engineConfig}}})
|
||||
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))
|
||||
}
|
||||
|
||||
func selectedCampaign(configuration appConfiguration, supplied commandkit.Supplied[string]) (string, campaign, error) {
|
||||
@@ -166,11 +196,18 @@ func buildValidationRequest(ctx context.Context, seed ckprompt.ValidationRequest
|
||||
}
|
||||
|
||||
func newApp() (*commandkit.App, error) {
|
||||
return newAppWithLLMClient(&exampleLLMClient{})
|
||||
}
|
||||
|
||||
func newAppWithLLMClient(client promptkit.LLMClient) (*commandkit.App, error) {
|
||||
if client == nil {
|
||||
client = &exampleLLMClient{}
|
||||
}
|
||||
limitDefault := 0
|
||||
limitFlag := commandkit.ValueFlag(commandkit.FlagMeta{Name: "limit", Usage: "Override the application item limit."}, &limitDefault, strconv.Atoi,
|
||||
func(input **inspectionInput, value commandkit.Supplied[int]) { (*input).Limit = value })
|
||||
inputFactory := func() *inspectionInput { return &inspectionInput{} }
|
||||
stateFactory := func() *runCache { return &runCache{} }
|
||||
stateFactory := func() *runCache { return &runCache{llmClient: client} }
|
||||
|
||||
appScope := ckconfig.FromConfigKit("app", "Application settings.", loadApplicationConfig)
|
||||
engineScope := ckprompt.ConfigScope(loadPromptEngine)
|
||||
@@ -195,6 +232,7 @@ func newApp() (*commandkit.App, error) {
|
||||
definitions.NewState = stateFactory
|
||||
definitions.Selectors = []commandkit.Flag[*inspectionInput]{campaignSelector()}
|
||||
definitions = ckprompt.WithRequestValidation(definitions, loadPromptEngine, buildValidationRequest)
|
||||
definitions = ckprompt.WithSmokeTesting(definitions, loadPromptEngine, nil)
|
||||
definitionCommand := ckprompt.Command(definitions)
|
||||
|
||||
store := map[string]session{
|
||||
|
||||
Reference in New Issue
Block a user