Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: AI action draft mode #1722

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions api/v1/playbook_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,9 @@ type AIAction struct {
AIActionClient `json:",inline" yaml:",inline"`
AIActionContext `json:",inline" yaml:",inline" template:"true"`

// When enabled, the prompt is simply saved without passing it on to the LLM.
DryRun bool `json:"dryRun,omitempty"`

// Use an AI agent that can autonomously drive the diagnosis using tools that interface directly with the database.
// NOTE: Not exposed for now
UseAgent bool `json:"-"`
Expand Down
4 changes: 4 additions & 0 deletions config/crds/mission-control.flanksource.com_playbooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ spec:
connection:
description: Connection to setup the llm backend connection
type: string
dryRun:
description: When enabled, the prompt is simply saved without
passing it on to the LLM.
type: boolean
formats:
description: |-
Output format of the prompt.
Expand Down
3 changes: 3 additions & 0 deletions config/schemas/playbook-spec.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
},
"type": "array"
},
"dryRun": {
"type": "boolean"
},
"systemPrompt": {
"type": "string"
},
Expand Down
3 changes: 3 additions & 0 deletions config/schemas/playbook.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
},
"type": "array"
},
"dryRun": {
"type": "boolean"
},
"systemPrompt": {
"type": "string"
},
Expand Down
7 changes: 6 additions & 1 deletion playbook/actions/ai.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package actions
import (
"encoding/json"
"fmt"
"strings"
"time"

"github.com/flanksource/commons/duration"
Expand Down Expand Up @@ -39,6 +40,10 @@ func (t *AIAction) Run(ctx context.Context, spec v1.AIAction) (*AIActionResult,
return nil, fmt.Errorf("faield to populate llm client connection: %w", err)
}

if spec.DryRun {
return &AIActionResult{Markdown: strings.Join(prompt, "\n")}, nil
}

llmConf := llm.Config{AIActionClient: spec.AIActionClient, UseAgent: spec.UseAgent}
response, err := llm.Prompt(ctx, llmConf, spec.SystemPrompt, prompt...)
if err != nil {
Expand All @@ -54,7 +59,7 @@ func buildPrompt(ctx context.Context, prompt string, spec v1.AIActionContext) ([
return nil, fmt.Errorf("failed to get prompt context: %w", err)
}

knowledgeJSON, err := json.Marshal(knowledge)
knowledgeJSON, err := json.MarshalIndent(knowledge, "", "\t")
if err != nil {
return nil, fmt.Errorf("failed to get prompt context: %w", err)
}
Expand Down
Loading