Demonstrate automatic usage in composed pipeline
This commit is contained in:
@@ -60,7 +60,8 @@ func (client *exampleLLMClient) Generate(context.Context, promptkit.GenerateRequ
|
||||
if client.calls != nil {
|
||||
(*client.calls)++
|
||||
}
|
||||
return &promptkit.GenerateResponse{Content: "Example response."}, nil
|
||||
cost := 0.00125
|
||||
return &promptkit.GenerateResponse{Content: "Example response.", Usage: promptkit.TokenUsage{PromptTokens: 10, CompletionTokens: 4, TotalTokens: 14, ReasoningTokens: 1, CachedTokens: 2, CacheWriteTokens: 0}, UsagePresence: &promptkit.TokenUsagePresence{PromptTokens: true, CompletionTokens: true, TotalTokens: true, ReasoningTokens: true, CachedTokens: true, CacheWriteTokens: true}, CostUSD: &cost}, nil
|
||||
}
|
||||
|
||||
type restoreInput struct {
|
||||
@@ -338,8 +339,25 @@ func newAppWithEngineLoader(
|
||||
return commandkit.Success()
|
||||
},
|
||||
})
|
||||
pipeline := commandkit.NewCommand(commandkit.CommandSpec[struct{}]{Name: "run", Summary: "Run a two-prompt planning pipeline.", Run: func(inv commandkit.Invocation, _ struct{}) commandkit.Outcome {
|
||||
engine, err := engineLoader(inv.Context, ckconfig.Selection{}, &inspectionInput{}, &runCache{llmClient: client})
|
||||
if err != nil {
|
||||
return commandkit.Failure("Could not load PromptKit engine.").WithCause(err)
|
||||
}
|
||||
results := make([]string, 0, 2)
|
||||
for _, topic := range []string{"planning", "review"} {
|
||||
result, err := engine.Run(inv.Context, promptkit.RunRequest{PromptID: "briefing", Inputs: map[string]promptkit.ArtifactRef{"topic": promptkit.Inline(topic)}, Vars: map[string]string{"mode": "", "topic": topic}})
|
||||
if err != nil {
|
||||
return commandkit.Failure("Pipeline prompt failed: " + err.Error()).WithCause(err)
|
||||
}
|
||||
results = append(results, result.RawOutput)
|
||||
}
|
||||
_ = inv.Reporter().Report(commandkit.Report{Value: results})
|
||||
return commandkit.Success()
|
||||
}})
|
||||
declarations := []commandkit.Declaration{
|
||||
configCommand,
|
||||
commandkit.Group("pipeline", "Run an application pipeline.", pipeline),
|
||||
commandkit.Completion("composed-example"),
|
||||
commandkit.Group("session", "Manage saved sessions.", restore),
|
||||
commandkit.Group("request", "Inspect application-owned request inputs.", requestInspect),
|
||||
|
||||
Reference in New Issue
Block a user